Skip to content

Commit

Permalink
markdown html cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
skorotkiewicz committed Jul 3, 2020
1 parent fd0e2f8 commit c3b9ed3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions helpers/slimdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ class Slimdown {
}
return `<pre><code class="hljs">${highlightedCode}</code></pre>`;
}

cleanHtml(text) {
var map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}

// Render some Markdown into HTML.
render(text) {
Expand All @@ -72,6 +83,8 @@ class Slimdown {
text = text.replace(match[0], 'KUCOSMULTILINECODEID');
}

text = this.cleanHtml(text);

// Match remaining text and replace with rules
for (let i = 0; i < this.rules.length; i++) {
const rule = this.rules[i];
Expand Down

0 comments on commit c3b9ed3

Please sign in to comment.