Skip to content

Commit

Permalink
fix: prevent render markup
Browse files Browse the repository at this point in the history
escapes html for lines
  • Loading branch information
petersolopov committed Jun 13, 2020
1 parent 46b1554 commit b5f079c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./styles.js";

import composePlugins from "./plugins/composePlugins.js";
import escape from "./plugins/escape.js";

class Yace {
constructor(selector, options = {}) {
Expand Down Expand Up @@ -113,7 +114,7 @@ class Yace {
.map((line, number) => {
return `<span class="yace-line" style="position: absolute; opacity: .3; left: 0">${
1 + number
}</span><span style="color: transparent; pointer-events: none">${line}</span>`;
}</span><span style="color: transparent; pointer-events: none">${escape(line)}</span>`;
})
.join("\n");
}
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function escape(unsafe) {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

export default escape;

0 comments on commit b5f079c

Please sign in to comment.