bookdown
bookdown copied to clipboard
adding markup to a section title generates an anchor that breaks navigation when number_sections=false
Tested with bookdown 0.24. Take the bookdown-demo repository. If the setting
number_sections: false
then if one were to add any formatting to a section title, for example:
# *Literature*
the link that gets generated gains an anchor:
literature.html#literature
The link still works when clicked but the javascript highlighting the active section in the table of content stops working and breaks the ability to see what page in the TOC is active, and with that breaks the navigation
Thanks for the report.
I believe we don't expect html tags in the header like <em>
to italicize as usually styles are set using CSS for headers. We modify the toc in this function
https://github.com/rstudio/bookdown/blob/261286378c73cf06b42db441d6991c07d4e300bf/R/gitbook.R#L188
and we don't support html tag in headers:
https://github.com/rstudio/bookdown/blob/261286378c73cf06b42db441d6991c07d4e300bf/R/gitbook.R#L206
As the header contains <em>
, it will not be detected, and class = "chapter"
won't be added to the <li>
element, which will prevent the hightlighting of current active section. The following chapter will be selected.
This may not be an easy fix without breaking other stuff - we'll try to fix this next time we go through bookdown.
In the meantime, you can apply CSS to this specific header or all header to get the same styling as using <em>
.
What I want to mention here is that the issue is not as much about globally styling headers a certain way, rather the inability to mix any additional styling into a section header. For example a section title such as:
# Let's talk about the `print` function
would trigger the bug.
I want to also note that the bug manifests itself only when number_sections: false
. If the numbering is allowed to be present the styling and linking all works as expected.
Thanks for the precision. The bug will trigger as soon as the html code of the header contains <
.
I want to also note that the bug manifests itself only when number_sections: false. If the numbering is allowed to be present the styling and linking all works as expected.
This is a regex issue and it is not the same regex used for numbered or unnumbered. I'll look closer following this hint.
Thank you.
Yes, I've run into this problem as well.
I've also hit this problem