Skip to content

Commit 281d126

Browse files
committed
Merge remote-tracking branch 'origin/fix/issue-1254' into fix/issue-1254
2 parents e813f48 + 71eb732 commit 281d126

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

‎dor-tools-builtin/test/markdown-format.test.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ for (const source of [
5252
'<span title="<literal>">safe</span>\n',
5353
'Use \\<your relay> and &lt;https://example.com&gt;.\n',
5454
'\\<script>alert(1)\\</script>\n',
55+
'Write \\&#x3C; and \\&#x3E; literally, but \\\\&lt;.\n',
5556
'A \\[label] **bold** and \\[label]\\(url).\n',
5657
]) {
5758
test(`retains semantics: ${JSON.stringify(source)}`, () => {

‎dor-tools-builtin/viewer/markdown-format.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function markdownFormat(markdown: string): Options {
3232
},
3333
text(node, _parent, state, info) {
3434
const safe = state.safe(node.value, { ...info, encode: ['<', '>'] })
35-
.replace(/&#x3C;/gi, '&lt;').replace(/&#x3E;/gi, '&gt;');
35+
.replace(/\\[^]|&#x3([CE]);/g, (match, hex: string | undefined) => hex ? (hex === 'C' ? '&lt;' : '&gt;') : match);
3636
// Restore only simple, complete labels. Keep escapes inside link labels,
3737
// list items (task syntax), and documents with reference definitions.
3838
if (references || state.stack.some(kind => ['label', 'reference', 'listItem'].includes(kind))) return safe;

0 commit comments

Comments
 (0)