fix: tweak TOC detection for VFM v2 change #1132
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 resolves the problem on VFM v2 change:
With the following Markdown,
VFM v1 generates the following HTML:
Vivliostyle.js recognizes the section as TOC because "toc" class is found in the section element.
This is changed in VFM v2. It generates the following HTML:
The "toc" class (or id) is not found on the
<section>
element, so the TOC detection has to be tweaked using the selector,section:has(>:first-child:is(h1,h2,h3,h4,h5,h6):is(.toc,#toc))
.Note: the stylesheet for TOC that was a part of UserAgentBaseCSS is now a separate stylesheet UserAgentTocCSS. This change is necessary because uaStylesheetBaseFetcher cannot handle the
:has()
selector.