Skip to content

Commit fef9ec4

Browse files
committed
fix: html characters not escaped in code blocks (fixes #378)
if lang is not specified
1 parent a5e4e2a commit fef9ec4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/utils/md-renderer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import * as slugify from 'slugify';
55
import * as Remarkable from 'remarkable';
66
import { StringMap } from './';
77

8+
function HTMLescape(html: string): string {
9+
return document.createElement('div')
10+
.appendChild(document.createTextNode(html))
11+
.parentElement
12+
.innerHTML;
13+
}
14+
815
declare var Prism: any;
916
const md = new Remarkable({
1017
html: true,
@@ -15,7 +22,7 @@ const md = new Remarkable({
1522
if (lang === 'json') lang = 'js';
1623
let grammar = Prism.languages[lang];
1724
// fallback to click
18-
if (!grammar) return str;
25+
if (!grammar) return HTMLescape(str);
1926
return Prism.highlight(str, grammar);
2027
}
2128
});

0 commit comments

Comments
 (0)