diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-03-29 20:45:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-03-29 20:45:53 +0000 |
| commit | 1413e67cdde7dc349c098c670d8590cc8e04b004 (patch) | |
| tree | 044e85c273a49dd8c53ac0f06dd686f22b234165 /lib | |
| parent | e3891290bd3034d0ce8034387ffab1e5a9793a70 (diff) | |
HTML escape text
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/documents.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/documents.js b/lib/documents.js index 5d2d0b7..b91c3b1 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -47,7 +47,7 @@ function DocumentConverter(options) { return element.children.map(elementToHtml).join(""); }, "text": function(element) { - return element.value; + return escapeHtml(element.value); } }; return { @@ -83,3 +83,11 @@ function Text(value) { value: value }; } + +function escapeHtml(value) { + return value + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/</g, '<') + .replace(/>/g, '>'); +} |
