Skip to content

Commit a9e4dd9

Browse files
committed
ensure replaceAll() is called with function parameter when string is not known to be free of $ (#12853)
1 parent 3cea512 commit a9e4dd9

File tree

6 files changed

+31
-21
lines changed

6 files changed

+31
-21
lines changed

package/src/common/update-html-dependencies.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,63 +820,63 @@ async function updateBootstrapFromBslib(
820820
for (let line of varContents) {
821821
line = line.replaceAll(
822822
"var(--#{$prefix}font-sans-serif)",
823-
"$font-family-sans-serif"
823+
"$$font-family-sans-serif"
824824
);
825825
line = line.replaceAll(
826826
"var(--#{$prefix}font-monospace)",
827-
"$font-family-monospace"
827+
"$$font-family-monospace"
828828
);
829829
line = line.replaceAll(
830830
"var(--#{$prefix}success-rgb)",
831-
"$success"
831+
"$$success"
832832
);
833833
line = line.replaceAll(
834834
"var(--#{$prefix}danger-rgb)",
835-
"$danger"
835+
"$$danger"
836836
);
837837
line = line.replaceAll(
838838
"var(--#{$prefix}body-color-rgb)",
839-
"$body-color"
839+
"$$body-color"
840840
);
841841
line = line.replaceAll(
842842
"var(--#{$prefix}body-bg-rgb)",
843-
"$body-bg"
843+
"$$body-bg"
844844
);
845845
line = line.replaceAll(
846846
"var(--#{$prefix}emphasis-color-rgb)",
847-
"$body-emphasis-color"
847+
"$$body-emphasis-color"
848848
);
849849
line = line.replaceAll(
850850
/RGBA?\(var\(--#\{\$prefix\}emphasis-color-rgb,(.*?)\).*?\)/gm,
851-
"$body-emphasis-color"
851+
"$$body-emphasis-color"
852852
);
853853
line = line.replaceAll(
854854
"var(--#{$prefix}secondary-color)",
855-
"$body-secondary-color"
855+
"$$body-secondary-color"
856856
);
857857
line = line.replaceAll(
858858
"var(--#{$prefix}secondary-bg)",
859-
"$body-secondary-bg"
859+
"$$body-secondary-bg"
860860
);
861861
line = line.replaceAll(
862862
"var(--#{$prefix}tertiary-bg)",
863-
"$body-tertiary-bg"
863+
"$$body-tertiary-bg"
864864
);
865865
line = line.replaceAll(
866866
"var(--#{$prefix}tertiary-color)",
867867
"$body-tertiary-color"
868868
);
869869
line = line.replaceAll(
870870
"var(--#{$prefix}emphasis-bg)",
871-
"$body-emphasis-bg"
871+
"$$body-emphasis-bg"
872872
);
873873
line = line.replaceAll(
874874
"var(--#{$prefix}emphasis-color)",
875-
"$body-emphasis-color"
875+
"$$body-emphasis-color"
876876
);
877877
line = line.replaceAll(
878878
"$emphasis-color-rgb",
879-
"$body-emphasis-color"
879+
"$$body-emphasis-color"
880880
);
881881

882882
line = line.replaceAll(/var\(--#\{\$prefix\}(.*?)\)/gm, "$$$1");

src/core/handlers/mermaid.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
258258
const oldId = svg.getAttribute("id") as string;
259259
svg.setAttribute("id", newMermaidId);
260260
const style = svg.querySelector("style")!;
261-
style.innerHTML = style.innerHTML.replaceAll(oldId, newMermaidId);
261+
style.innerHTML = style.innerHTML.replaceAll(oldId, () => newMermaidId);
262262

263263
for (const defNode of svg.querySelectorAll("defs")) {
264264
const defEl = defNode as Element;
@@ -296,11 +296,11 @@ mermaid.initialize(${JSON.stringify(mermaidOpts)});
296296
// this string substitution is fraught, but I don't know how else to fix the problem.
297297
oldSvgSrc = oldSvgSrc.replaceAll(
298298
`"${idToPatch}"`,
299-
`"${to}"`,
299+
() => `"${to}"`,
300300
);
301301
oldSvgSrc = oldSvgSrc.replaceAll(
302302
`#${idToPatch}`,
303-
`#${to}`,
303+
() => `#${to}`,
304304
);
305305
}
306306
svg = mappedDiff(svg, oldSvgSrc);

src/core/jupyter/jupyter-embed.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,14 @@ export async function replaceNotebookPlaceholders(
339339
}
340340

341341
// Replace the placeholders with the rendered markdown
342-
markdown = markdown.replaceAll(match[0], nbMarkdown || "");
342+
markdown = markdown.replaceAll(
343+
match[0],
344+
// https://github.com/quarto-dev/quarto-cli/issues/12853
345+
// we use a function here to avoid
346+
// escaping issues with $ in the markdown
347+
// (e.g. $x$ in math mode)
348+
() => nbMarkdown ?? "",
349+
);
343350
}
344351
match = regex.exec(markdown);
345352
}

src/core/jupyter/jupyter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ export function mdFromContentCell(
10391039
for (let i = 0; i < source.length; i++) {
10401040
source[i] = source[i].replaceAll(
10411041
`attachment:${file}`,
1042-
imageFile,
1042+
() => imageFile,
10431043
);
10441044
}
10451045
// only process one supported mime type

src/execute/rmd.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ export const knitrEngine: ExecutionEngine = {
135135
options.quiet,
136136
// fixup .rmarkdown file references
137137
(output) => {
138-
output = output.replaceAll(`${inputStem}.rmarkdown`, inputBasename);
138+
output = output.replaceAll(
139+
`${inputStem}.rmarkdown`,
140+
() => inputBasename,
141+
);
139142

140143
const m = output.match(/^Quitting from lines (\d+)-(\d+)/m);
141144
if (m) {

src/format/jats/format-jats-postprocess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const renderSubarticlePostProcessor = (
8888
// Replace the placeholder with the rendered subarticle
8989
outputContents = outputContents.replaceAll(
9090
placeholder,
91-
subArtLines.join("\n"),
91+
() => subArtLines.join("\n"),
9292
);
9393

9494
// Move supporting and resource files into place

0 commit comments

Comments
 (0)