diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-11 23:19:03 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-11 23:19:03 -0800 |
commit | f846824b17c83092fcb1e5dd92d3e931c39e76ef (patch) | |
tree | 7390209baa9393657b99efb666b54cc98f269e8a /js/lib/xml.js | |
parent | c6d83e713df9864d704e2d12c3f62ff3be8535fd (diff) |
Moved common xml escaping code from xml.js, html.js to common.js.
Diffstat (limited to 'js/lib/xml.js')
-rw-r--r-- | js/lib/xml.js | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/js/lib/xml.js b/js/lib/xml.js index 056bcc5..79b6957 100644 --- a/js/lib/xml.js +++ b/js/lib/xml.js @@ -1,5 +1,7 @@ "use strict"; +var escapeXml = require('./common').escapeXml; + // Helper function to produce an XML tag. var tag = function(name, attrs, selfclosing) { var result = '<' + name; @@ -158,23 +160,6 @@ var renderNodes = function(block) { return buffer; }; -var replaceUnsafeChar = function(s) { - switch (s) { - case '&': - return '&'; - case '<': - return '<'; - case '>': - return '>'; - case '"': - return '"'; - default: - return s; - } -}; - -var reNeedsEscaping = /[&<>"]/; - // The XmlRenderer object. function XmlRenderer(options){ return { @@ -182,17 +167,7 @@ function XmlRenderer(options){ softbreak: '\n', // by default, soft breaks are rendered as newlines in HTML // set to "<br />" to make them hard breaks // set to " " if you want to ignore line wrapping in source - escape: function(s, preserve_entities) { - if (reNeedsEscaping.test(s)) { - if (preserve_entities) { - return s.replace(/[&](?:[#](x[a-f0-9]{1,8}|[0-9]{1,8});|[a-z][a-z0-9]{1,31};)|[&<>"]/gi, replaceUnsafeChar); - } else { - return s.replace(/[&<>"]/g, replaceUnsafeChar); - } - } else { - return s; - } - }, + escape: escapeXml, options: options || {}, render: renderNodes }; |