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
11 changes: 10 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,16 @@ 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");
// When a section has an href, the .sidebar-item-text element is a
// plain link without data-bs-target. Fall back to the sibling
// .sidebar-item-toggle, which always carries data-bs-target.
let target = sectionEl.getAttribute("data-bs-target");
if (!target) {
const toggleEl = sectionEl.parentElement?.querySelector(
".sidebar-item-toggle",
);
target = toggleEl?.getAttribute("data-bs-target") ?? null;
}

if (target) {
const id = target.slice(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.quarto/
16 changes: 16 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,16 @@
project:
type: website

website:
title: "Sidebar section href test"
sidebar:
contents:
- index.qmd
- section: "**More info**"
href: more-info.qmd
contents:
- child.qmd

format:
html:
theme: default
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.
50 changes: 50 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,50 @@
/*
* 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) 2020-2025 Posit Software, PBC
*/

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

const renderDir = docs("websites/website-sidebar-section-href");
const outDir = join(Deno.cwd(), 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"],
),
// Raw markdown asterisks must not appear in the sidebar HTML
ensureFileRegexMatches(
join(outDir, "index.html"),
[],
[/sidebar-item-text[^<]*\*\*/],
),
],
{
teardown: async () => {
if (existsSync(outDir)) {
await Deno.remove(outDir, { recursive: true });
}
},
},
);
Loading