Fix cross referencing when spliting by sections #849
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This will fixes #787
To understand what does not work currently, here is a
index.Rmdto reproduceWhen using
split_by: sections, a h2 following a h1 with no content in between will broke the section reference, and will create an incorrect number in figure reference.You'll get a
This is because bookdown processing will add a closing
divtag, to support special bookdown feature, whensplit_byissectionorsection+numberbookdown/R/html.R
Line 282 in 70f9c07
When the second header follows directly the first header (i.e
x[i]would be thish1header), it will add this closing\n</div>to the end of the h1 header. This will breakparse_section_labels()that won't find the id because the regex does not take into account this addition.bookdown/R/html.R
Lines 700 to 707 in 70f9c07
This PR fixes this by detecting the extra div added when split by sections.
Also, I added some tests to check that it will continue to work in the future.