Skip to content

Commit

Permalink
Merge pull request #11097 from quarto-dev/bugfix/8932
Browse files Browse the repository at this point in the history
markdown pipeline: escape render-ids
  • Loading branch information
cscheid authored Oct 17, 2024
2 parents 66ea8c4 + 531d1c3 commit fb98c5d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/changelog-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/core/markdown-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/encoding/base64.ts";

export interface PipelineMarkdown {
blocks?: Record<string, string>;
Expand Down Expand Up @@ -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`;
};

Expand All @@ -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;
}
};

Expand Down
22 changes: 22 additions & 0 deletions tests/docs/smoke-all/2024/10/17/issue-8932/_quarto.yml
Original file line number Diff line number Diff line change
@@ -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



5 changes: 5 additions & 0 deletions tests/docs/smoke-all/2024/10/17/issue-8932/about.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "About"
---

About this site
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function Str(str)
if string.find(str.text, ":::") then
crash()
end
end
9 changes: 9 additions & 0 deletions tests/docs/smoke-all/2024/10/17/issue-8932/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "issue-8932"
filters:
- check_stray_div.lua
---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
1 change: 1 addition & 0 deletions tests/docs/smoke-all/2024/10/17/issue-8932/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* css styles */

0 comments on commit fb98c5d

Please sign in to comment.