Skip to content

Commit fb98c5d

Browse files
authored
Merge pull request #11097 from quarto-dev/bugfix/8932
markdown pipeline: escape render-ids
2 parents 66ea8c4 + 531d1c3 commit fb98c5d

File tree

7 files changed

+50
-1
lines changed

7 files changed

+50
-1
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ All changes included in 1.6:
7171

7272
### Websites
7373

74+
- ([#8932](https://github.com/quarto-dev/quarto-cli/issues/8932)): Escape render ids in markdown pipeline to allow special characters in sidebars/navbars, etc.
7475
- ([#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.
7576

7677
### Quarto Blog

src/core/markdown-pipeline.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*
44
* Copyright (C) 2020-2022 Posit Software, PBC
55
*/
6+
import { base } from "acorn/walk";
7+
import { decodeBase64, encodeBase64 } from "encoding/base64";
68
import { Document, Element, Node } from "./deno-dom.ts";
9+
import { decode } from "https://deno.land/[email protected]/encoding/base64.ts";
710

811
export interface PipelineMarkdown {
912
blocks?: Record<string, string>;
@@ -98,10 +101,12 @@ export function processMarkdownRenderEnvelope(
98101
const markdownEnvelopeWriter = (envelopeId: string) => {
99102
const renderList: string[] = [];
100103
const hiddenSpan = (id: string, contents: string) => {
104+
id = encodeBase64(id);
101105
return `[${contents}]{.hidden .quarto-markdown-envelope-contents render-id="${id}"}`;
102106
};
103107

104108
const hiddenDiv = (id: string, contents: string) => {
109+
id = encodeBase64(id);
105110
return `\n:::{.hidden .quarto-markdown-envelope-contents render-id="${id}"}\n${contents}\n:::\n`;
106111
};
107112

@@ -126,7 +131,8 @@ const readEnvelope = (doc: Document, envelopeId: string) => {
126131
const el = node as Element;
127132
const id = el.getAttribute("data-render-id");
128133
if (id) {
129-
contents[id] = el;
134+
// convert the array to a string
135+
contents[new TextDecoder().decode(decodeBase64(id))] = el;
130136
}
131137
};
132138

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "issue-8932"
6+
navbar:
7+
left:
8+
- href: index.qmd
9+
text: Home
10+
- about.qmd
11+
page-footer:
12+
center:
13+
- text: 'Project "created"'
14+
15+
format:
16+
html:
17+
theme: cosmo
18+
css: styles.css
19+
toc: true
20+
21+
22+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "About"
3+
---
4+
5+
About this site
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function Str(str)
2+
if string.find(str.text, ":::") then
3+
crash()
4+
end
5+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "issue-8932"
3+
filters:
4+
- check_stray_div.lua
5+
---
6+
7+
This is a Quarto website.
8+
9+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* css styles */

0 commit comments

Comments
 (0)