Skip to content

Commit 503e200

Browse files
committed
fix
1 parent a8da4f7 commit 503e200

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/pages/markdownPreview/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ function createMarkdownPreview(file) {
370370
const codeElement = pre.querySelector("code");
371371
if (!codeElement || codeElement.closest(".mermaid-error")) return;
372372

373-
const language = codeElement.className.match(/language-(\w+)/)?.[1];
373+
const language =
374+
codeElement.dataset.language ||
375+
codeElement.className.match(/language-(\S+)/)?.[1];
374376
if (!language) return;
375377

376378
const originalCode = codeElement.textContent || "";
@@ -456,6 +458,7 @@ function createMarkdownPreview(file) {
456458
const sanitizedSvg = DOMPurify.sanitize(svg, {
457459
USE_PROFILES: { svg: true, svgFilters: true },
458460
ADD_TAGS: ["style"],
461+
ADD_ATTR: ["data-et", "data-id", "data-node", "data-zoom", "class"],
459462
});
460463
block.innerHTML = sanitizedSvg;
461464
bindFunctions?.(block);

src/pages/markdownPreview/renderer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const EXTERNAL_LINK_PATTERN = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1010
const IMAGE_PLACEHOLDER =
1111
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
1212
const BLOCK_MATH_PATTERN = /(^|[^\\])\$\$[\s\S]+?\$\$/m;
13-
const INLINE_MATH_PATTERN = /(^|[^\\])\$(?!\s)(?:\\.|[^$\\\n])+\$(?!\w)/m;
13+
const INLINE_MATH_PATTERN =
14+
/(^|[^\\])\$(?!\s)(?:\\.|[^$\\\n])*(?:\\[{^_(]|[{^_])(?:\\.|[^$\\\n])*\$(?!\w)/m;
1415
const BEGIN_END_MATH_PATTERN =
1516
/\\begin\{(?:equation|align|gather|multline|eqnarray)\*?\}[\s\S]*?\\end\{(?:equation|align|gather|multline|eqnarray)\*?\}/m;
1617

0 commit comments

Comments
 (0)