diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 1cc2c74f1d..828da29752 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -71,6 +71,7 @@ All changes included in 1.6: ### Websites +- ([#8932](https://github.com/quarto-dev/quarto-cli/issues/8932)): Escape render ids in markdown pipeline to allow special characters in sidebars/navbars, etc. - ([#10616](https://github.com/quarto-dev/quarto-cli/issues/10268)): Add a `z-index` setting to the 'back to top' button to ensure it is always visible. ### Quarto Blog diff --git a/src/core/markdown-pipeline.ts b/src/core/markdown-pipeline.ts index ba609be5ac..c1705a4a3d 100644 --- a/src/core/markdown-pipeline.ts +++ b/src/core/markdown-pipeline.ts @@ -3,7 +3,10 @@ * * Copyright (C) 2020-2022 Posit Software, PBC */ +import { base } from "acorn/walk"; +import { decodeBase64, encodeBase64 } from "encoding/base64"; import { Document, Element, Node } from "./deno-dom.ts"; +import { decode } from "https://deno.land/std@0.93.0/encoding/base64.ts"; export interface PipelineMarkdown { blocks?: Record; @@ -98,10 +101,12 @@ export function processMarkdownRenderEnvelope( const markdownEnvelopeWriter = (envelopeId: string) => { const renderList: string[] = []; const hiddenSpan = (id: string, contents: string) => { + id = encodeBase64(id); return `[${contents}]{.hidden .quarto-markdown-envelope-contents render-id="${id}"}`; }; const hiddenDiv = (id: string, contents: string) => { + id = encodeBase64(id); return `\n:::{.hidden .quarto-markdown-envelope-contents render-id="${id}"}\n${contents}\n:::\n`; }; @@ -126,7 +131,8 @@ const readEnvelope = (doc: Document, envelopeId: string) => { const el = node as Element; const id = el.getAttribute("data-render-id"); if (id) { - contents[id] = el; + // convert the array to a string + contents[new TextDecoder().decode(decodeBase64(id))] = el; } }; diff --git a/tests/docs/smoke-all/2024/10/17/issue-8932/_quarto.yml b/tests/docs/smoke-all/2024/10/17/issue-8932/_quarto.yml new file mode 100644 index 0000000000..e734d436bc --- /dev/null +++ b/tests/docs/smoke-all/2024/10/17/issue-8932/_quarto.yml @@ -0,0 +1,22 @@ +project: + type: website + +website: + title: "issue-8932" + navbar: + left: + - href: index.qmd + text: Home + - about.qmd + page-footer: + center: + - text: 'Project "created"' + +format: + html: + theme: cosmo + css: styles.css + toc: true + + + diff --git a/tests/docs/smoke-all/2024/10/17/issue-8932/about.qmd b/tests/docs/smoke-all/2024/10/17/issue-8932/about.qmd new file mode 100644 index 0000000000..07c5e7f9d1 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/17/issue-8932/about.qmd @@ -0,0 +1,5 @@ +--- +title: "About" +--- + +About this site diff --git a/tests/docs/smoke-all/2024/10/17/issue-8932/check_stray_div.lua b/tests/docs/smoke-all/2024/10/17/issue-8932/check_stray_div.lua new file mode 100644 index 0000000000..7d483b38b8 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/17/issue-8932/check_stray_div.lua @@ -0,0 +1,5 @@ +function Str(str) + if string.find(str.text, ":::") then + crash() + end +end \ No newline at end of file diff --git a/tests/docs/smoke-all/2024/10/17/issue-8932/index.qmd b/tests/docs/smoke-all/2024/10/17/issue-8932/index.qmd new file mode 100644 index 0000000000..6b33eff6ad --- /dev/null +++ b/tests/docs/smoke-all/2024/10/17/issue-8932/index.qmd @@ -0,0 +1,9 @@ +--- +title: "issue-8932" +filters: + - check_stray_div.lua +--- + +This is a Quarto website. + +To learn more about Quarto websites visit . diff --git a/tests/docs/smoke-all/2024/10/17/issue-8932/styles.css b/tests/docs/smoke-all/2024/10/17/issue-8932/styles.css new file mode 100644 index 0000000000..2ddf50c7b4 --- /dev/null +++ b/tests/docs/smoke-all/2024/10/17/issue-8932/styles.css @@ -0,0 +1 @@ +/* css styles */