fix(llms): preserve heading section in llms-hidden conditional content#14571
Merged
Conversation
…al content (#14562) A heading that leads a `content-hidden when-format="llms-txt"` block is visible in HTML but lost its <section> wrapper and id. Pandoc's --section-divs fuses the llms-hidden-content marker class onto the <section> it generates for that heading; the HTML finalizer then unwrapped every .llms-hidden-content, stripping that section and its id and breaking the TOC link, anchors, and cross-references. Only the leading-heading shape triggers it, since other shapes keep the wrapper div separate. Keep the section when the marker fused onto it (dropping only the marker class) and unwrap genuine wrapper divs as before.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
3 tasks
The conditional-headings regression test only exercised the content-hidden (html-only) leading-heading shape. Extend coverage to the two remaining cases from the fix's test plan: - content-visible when-format="llms-txt": llms-only content is removed from the HTML body but kept in the .llms.md output. - section-divs: false: the conditional block's leading heading still acquires a <section> wrapper independent of --section-divs, and the finalizer must keep its id intact while excluding the content from .llms.md.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a heading is the first element inside
::: {.content-hidden when-format="llms-txt"}in a website withllms-txt: true, the heading renders in HTML as a bare<h2>with no<section id="...">wrapper. The auto-generated TOC link points at anidthat no longer exists, so clicking it does not scroll, and the heading's anchor and cross-references break too.Root Cause
The llms conditional-content filter marks "visible in HTML, hidden from llms" blocks by wrapping them in
<div class="llms-hidden-content">. When that block leads with a heading, Pandoc's--section-divsdoes not keep the heading nested in the div — it fuses the marker class onto the<section>it generates for the heading:cleanupConditionalContentinsrc/project/types/website/website-llms.tsthen unwraps every.llms-hidden-contentelement. Since the class now rides on the<section>, unwrapping strips the section and itsid, leaving the bare<h2>. Only the leading-heading shape is affected; with text before the heading or multiple headings, Pandoc keeps the wrapper div separate, so the unwrap is harmless.Fix
When the marked element is a
<section>(the marker fused onto it), keep the section and drop only thellms-hidden-contentclass; genuine wrapper divs are still unwrapped. Content stays excluded from the.llms.mdoutput, which is generated before cleanup runs.Test Plan
llms-txtwebsite with a heading insidecontent-hidden when-format="llms-txt"— heading keeps its<section id>and the TOC link scrolls.llms.mdstill excludes the HTML-only contentcontent-visible when-format="llms-txt"(llms-only) content stays absent from HTML, present in.llms.mdsection-divs: falsedocuments still render the heading with itsidFixes #14562