aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-03-29 20:45:53 +0000
committerMichael Williamson <mike@zwobble.org>2013-03-29 20:45:53 +0000
commit1413e67cdde7dc349c098c670d8590cc8e04b004 (patch)
tree044e85c273a49dd8c53ac0f06dd686f22b234165 /lib
parente3891290bd3034d0ce8034387ffab1e5a9793a70 (diff)
HTML escape text
Diffstat (limited to 'lib')
-rw-r--r--lib/documents.js10
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, '&amp;')
+ .replace(/"/g, '&quot;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+}