Skip to content

Commit c1d6bb3

Browse files
cscheidjjallaire
authored andcommitted
escape mermaid input to support html tags
1 parent 387034c commit c1d6bb3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/core/handlers/mermaid.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { LocalizedError } from "../lib/error.ts";
4242
import { warning } from "log/mod.ts";
4343
import { FormatDependency } from "../../config/types.ts";
4444
import { mappedDiff } from "../mapped-text.ts";
45+
import { escape } from "../../core/lodash.ts";
4546

4647
const mermaidHandler: LanguageHandler = {
4748
...baseHandler,
@@ -81,13 +82,14 @@ object:
8182
options: Record<string, unknown>,
8283
) {
8384
const cellContent = handlerContext.cellContent(cell);
85+
// TODO escaping removes MappedString information.
8486
// create puppeteer target page
8587
const content = `<html>
8688
<head>
8789
<script src="./mermaid.min.js"></script>
8890
</head>
8991
<body>
90-
<pre class="mermaid">\n${cellContent.value}\n</pre>
92+
<pre class="mermaid">\n${escape(cellContent.value)}\n</pre>
9193
<script>
9294
mermaid.initialize();
9395
</script>
@@ -323,7 +325,7 @@ mermaid.initialize();
323325
classes: ["mermaid"],
324326
attrs: [`tooltip-selector="#${tooltipName}"`],
325327
});
326-
preEl.push(pandocRawStr(cell.source));
328+
preEl.push(pandocRawStr(escape(cell.source.value))); // TODO escaping removes MappedString information.
327329

328330
const attrs: Record<string, unknown> = {};
329331
if (isRevealjsOutput(handlerContext.options.context.format.pandoc)) {
@@ -349,7 +351,11 @@ mermaid.initialize();
349351
} else if (
350352
isMarkdownOutput(handlerContext.options.format.pandoc, ["gfm"])
351353
) {
352-
return mappedConcat(["\n``` mermaid\n", cellContent, "\n```\n"]);
354+
return mappedConcat([
355+
"\n``` mermaid\n",
356+
escape(cellContent.value), // TODO escaping removes MappedString information.
357+
"\n```\n",
358+
]);
353359
} else {
354360
return await makePng();
355361
}

0 commit comments

Comments
 (0)