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

fix: tweak TOC detection for VFM v2 change #1132

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

MurakamiShinyu
Copy link
Member

@MurakamiShinyu MurakamiShinyu commented Feb 27, 2023

This resolves the problem on VFM v2 change:

With the following Markdown,

 # Table of Contents {.toc}

- [One](one.html)
- [Two](two.html)

VFM v1 generates the following HTML:

    <section class="level1 toc" id="table-of-contents">
      <h1 class="toc">Table of Contents</h1>
      <ul>
        <li><a href="one.html">One</a></li>
        <li><a href="two.html">Two</a></li>
      </ul>
    </section>

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:

    <section class="level1" aria-labelledby="table-of-contents">
      <h1 class="toc" id="table-of-contents">Table of Contents</h1>
      <ul>
        <li><a href="one.html">One</a></li>
        <li><a href="two.html">Two</a></li>
      </ul>
    </section>

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.

This resolves the problem on VFM v2 change:

- vivliostyle/vfm#157

With the following Markdown,

```md
 # Table of Contents {.toc}

- [One](one.html)
- [Two](two.html)
```

VFM v1 generates the following HTML:

```html
    <section class="level1 toc" id="table-of-contents">
      <h1 class="toc">Table of Contents</h1>
      <ul>
        <li><a href="one.html">One</a></li>
        <li><a href="two.html">Two</a></li>
      </ul>
    </section>
```

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:

```html
    <section class="level1" aria-labelledby="table-of-contents">
      <h1 class="toc" id="table-of-contents">Table of Contents</h1>
      <ul>
        <li><a href="one.html">One</a></li>
        <li><a href="two.html">Two</a></li>
      </ul>
    </section>
```

The "toc" class is not found in 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.
@vercel
Copy link

vercel bot commented Feb 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
vivliostyle ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 27, 2023 at 4:58AM (UTC)

@MurakamiShinyu MurakamiShinyu merged commit ab6c649 into master Feb 27, 2023
@MurakamiShinyu MurakamiShinyu deleted the fix/tweak-toc-detection branch February 27, 2023 07:43
@MurakamiShinyu MurakamiShinyu added this to the v2.23 milestone Feb 27, 2023
MurakamiShinyu added a commit that referenced this pull request Feb 27, 2023
forgot to remove comment marks added for testing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant