Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross references should work with distill_article as base format #1077

Open
cderv opened this issue Feb 15, 2021 · 1 comment
Open

cross references should work with distill_article as base format #1077

cderv opened this issue Feb 15, 2021 · 1 comment
Assignees
Labels
bug an unexpected problem or unintended behavior next to consider for next release

Comments

@cderv
Copy link
Collaborator

cderv commented Feb 15, 2021

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>)?$'

@cderv cderv added the bug an unexpected problem or unintended behavior label Feb 15, 2021
@cderv cderv self-assigned this Feb 15, 2021
@cderv
Copy link
Collaborator Author

cderv commented Feb 16, 2021

The issue is deeper than I thought.

Maybe changing the regex would work but bookdown expect HTML4 I believe and distill produces HTML5. Hence some content is different.

For example, bookdown expect sections so --sections-div needs to be activated (which is not in distill) but this still does not work

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

# heading 1 {#myheading1}

See section \@ref(myheading1)

because this will produce

<section id="myheading1" class="level1" data-number="1">

and not a div with class section.

Should we try to support this ?

I believe this is another case for making referencing possible from rmarkdown directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior next to consider for next release
Projects
None yet
Development

No branches or pull requests

1 participant