Skip to content

Commit

Permalink
fix: html characters not escaped in code blocks (fixes #378)
Browse files Browse the repository at this point in the history
if lang is not specified
  • Loading branch information
RomanHotsiy committed Nov 15, 2017
1 parent a5e4e2a commit fef9ec4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/utils/md-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import * as slugify from 'slugify';
import * as Remarkable from 'remarkable';
import { StringMap } from './';

function HTMLescape(html: string): string {
return document.createElement('div')
.appendChild(document.createTextNode(html))
.parentElement
.innerHTML;
}

declare var Prism: any;
const md = new Remarkable({
html: true,
Expand All @@ -15,7 +22,7 @@ const md = new Remarkable({
if (lang === 'json') lang = 'js';
let grammar = Prism.languages[lang];
// fallback to click
if (!grammar) return str;
if (!grammar) return HTMLescape(str);
return Prism.highlight(str, grammar);
}
});
Expand Down

0 comments on commit fef9ec4

Please sign in to comment.