Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/project/types/website/website-navigation-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ const sidebarContentsHandler = (context: NavigationPipelineContext) => {
);
for (let i = 0; i < sidebarSectionEls.length; i++) {
const sectionEl = sidebarSectionEls[i] as Element;
const target = sectionEl.getAttribute("data-bs-target");
// The toggle has data-bs-target whether or not the section has an href
const target = sectionEl.parentElement
?.querySelector(".sidebar-item-toggle")
?.getAttribute("data-bs-target");

if (target) {
const id = target.slice(1);
Expand Down
3 changes: 3 additions & 0 deletions tests/docs/websites/website-sidebar-section-href/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.quarto/

**/*.quarto_ipynb
12 changes: 12 additions & 0 deletions tests/docs/websites/website-sidebar-section-href/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project:
type: website

website:
title: "Sidebar section href test"
sidebar:
contents:
- index.qmd
- section: "**More info**"
href: more-info.qmd
contents:
- child.qmd
5 changes: 5 additions & 0 deletions tests/docs/websites/website-sidebar-section-href/child.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Child page"
---

Child page.
5 changes: 5 additions & 0 deletions tests/docs/websites/website-sidebar-section-href/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "Home"
---

Home page.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "More info"
---

More info page.
36 changes: 36 additions & 0 deletions tests/smoke/website/website-sidebar-section-href.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* website-sidebar-section-href.test.ts
*
* Tests that markdown in sidebar section titles is rendered correctly when
* the section has an href. Without the fix, the .sidebar-item-text element
* is a plain link without data-bs-target, so the markdown substitution in
* sidebarContentsHandler() fails to recover the sectionId and leaves raw
* markdown (e.g. **More info**) in the DOM instead of rendering it.
*
* Copyright (C) 2026 Posit Software, PBC
*/

import { docs } from "../../utils.ts";
import { join } from "../../../src/deno_ral/path.ts";
import { safeRemoveSync } from "../../../src/deno_ral/fs.ts";
import { testQuartoCmd } from "../../test.ts";
import { ensureHtmlElements, noErrorsOrWarnings } from "../../verify.ts";

const renderDir = docs("websites/website-sidebar-section-href");
const outDir = join(renderDir, "_site");

testQuartoCmd(
"render",
[renderDir],
[
noErrorsOrWarnings,
// Markdown in section title must be rendered: **More info** → <strong>
ensureHtmlElements(
join(outDir, "index.html"),
[".sidebar-item-text strong"],
),
],
{
teardown: async () => safeRemoveSync(outDir, { recursive: true }),
},
);
Loading