Skip to content

cross references should work with distill_article as base format #1077

Open
@cderv

Description

@cderv

This should be working IMO

---
title: "Untitled"
date: "`r Sys.Date()`"
output:
  bookdown::html_document2:
    base_format: distill::distill_article
    pandoc_args: ["--number-sections"]
---

# heading 1 {#myheading1}

See section \@ref(myheading1)

Reported in rstudio/distill#287

Currently it is not because distill will generate this HTML

"<h1 data-number=\"1\" id=\"myheading1\"><span class=\"header-section-number\">1</span> heading 1</h1>"

which bookdown regex does not currently support. This should be solve when we'll change how to solve reference (without regex) but for now I guess just modifying the regex will work.

bookdown/R/html.R

Lines 706 to 719 in 0098721

parse_section_labels = function(content) {
arry = character()
sec_ids = '^<div id="([^"]+)" class="section .+$'
for (i in grep(sec_num, content)) {
if (!grepl(sec_ids, content[i - 1])) next # no section id
# extract section number and id, store in the array
arry = c(arry, setNames(
sub(sec_num, '\\1', content[i]),
sub(sec_ids, '\\1', content[i - 1])
))
}
write_ref_keys(names(arry))
arry
}

sec_num = '^<h[1-6]><span class="header-section-number">([.A-Z0-9]+)</span>.+</h[1-6]>(\n</div>)?$'

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behaviornextto consider for next release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions