Skip to content

Fix Markdown rendering for sidebar sections with href - #14521

Open
cliffckerr wants to merge 1 commit into
quarto-dev:mainfrom
sciris:fix/issue14520-section-sidebar-formatting
Open

cliffckerr wants to merge 1 commit into
quarto-dev:mainfrom
sciris:fix/issue14520-section-sidebar-formatting

Conversation

@cliffckerr

@cliffckerr cliffckerr commented May 17, 2026 •

Copy link
Copy Markdown

Summary

Markdown in sidebar section titles (e.g. **More info**) render correctly when the section has no href, but is left as raw Markdown when the section has an href. HTML in the same title (e.g. <b>More info</b>) renders bold in both cases. This PR fixes the Markdown case.

Closes #14520.

Cause

Sidebar item text is emitted by sidebaritem.ejs via lodash <%= item.text %>, which is unescaped interpolation, so any raw HTML in the title passes through to the browser as-is. Markdown requires a separate post-render pass to be converted to HTML: sidebarContentsHandler in src/project/types/website/website-navigation-md.ts:

  1. getUnrendered() collects each section's text and hands it to pandoc, keyed by sectionId.
  2. processRendered() walks the rendered DOM, identifies each section by reading data-bs-target off .sidebar-item-text, and swaps the pandoc-rendered HTML back in.

The two branches of sidebaritem.ejs produce different markup for the .sidebar-item-text element:

  • No href: <a ... data-bs-toggle="collapse" data-bs-target="#<sectionId>"> — has data-bs-target.
  • With href: <a href="..." class="sidebar-item-text sidebar-link"> — no data-bs-target.

So when a section has an href, processRendered can't recover the sectionId, falls through silently, and the raw markdown (**More info**) is left in the DOM.

Fix

The sibling .sidebar-item-toggle element (the chevron button) always carries data-bs-target="#<sectionId>", regardless of whether the section has an href. When .sidebar-item-text lacks the attribute, fall back to the sibling toggle.

(NB: PR written with the help of Claude, but reviewed and validated by me.)

@posit-snyk-bot

posit-snyk-bot commented May 17, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cliffckerr cliffckerr changed the title Fix markdown rendering in sidebar section titles with href Fix Markdown rendering for sidebar sections with href May 17, 2026
@mcanouil

Copy link
Copy Markdown
Collaborator

Thanks.
Some tests to ensure the behaviour and avoid future regression is needed.

@cliffckerr

cliffckerr commented May 24, 2026 •

Copy link
Copy Markdown
Author

@mcanouil Added, let me know if it looks ok! (Edit: I see a test is failing, but it seems to have something to do with Windows/Julia and isn't related to this commit.)

@cliffckerr
cliffckerr force-pushed the fix/issue14520-section-sidebar-formatting branch from f12f7d9 to 1a88396 Compare October 28, 2026 23:57
@cliffckerr

Copy link
Copy Markdown
Author

Hi @mcanouil -- I've made some updates so hopefully the PR is a little cleaner now. Happy to make more changes if you want!

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.

Adding href to a sidebar section breaks Markdown formatting

3 participants