Skip to content

Commit c8a8537

Browse files
committed
escape htmlEntities code pre
1 parent fd14fc0 commit c8a8537

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/TextFormatting.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function textFormatting(str) {
4141
} else if (imgAlt) {
4242
return `<img src='${imgPath}' alt='${imgAlt}'/>`;
4343
} else if (code) {
44-
return `<code>${code}</code>`
44+
return `<code>${htmlEntities(code)}</code>`
4545
} else if (pre) {
46-
return `<pre>${pre}</pre>`
46+
return `<pre>${htmlEntities(pre)}</pre>`
4747
} else if (title) {
4848
return `<h${titleNum.length}>${title}</h1>`
4949
} else {
@@ -52,5 +52,9 @@ function textFormatting(str) {
5252
})
5353
}
5454

55+
function htmlEntities(str) {
56+
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
57+
}
58+
5559
module.exports = textFormatting;
5660

0 commit comments

Comments
 (0)