summaryrefslogtreecommitdiff
path: root/js/lib/common.js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-24 11:07:01 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-24 11:07:01 -0800
commitd6c615f2680e79bbb76cc85a056aadfe3524513f (patch)
tree1df0b3fe4a85a6ffcbaf06809318fc40ed062708 /js/lib/common.js
parent31530d93448bdf93c0797540a73c6b67586ad5e1 (diff)
Removed JS implementation, which is moving to its own repo:
<https://github.com/jgm/commonmark.js>
Diffstat (limited to 'js/lib/common.js')
-rw-r--r--js/lib/common.js75
1 files changed, 0 insertions, 75 deletions
diff --git a/js/lib/common.js b/js/lib/common.js
deleted file mode 100644
index c365e53..0000000
--- a/js/lib/common.js
+++ /dev/null
@@ -1,75 +0,0 @@
-"use strict";
-
-var entityToChar = require('./html5-entities.js').entityToChar;
-
-var ENTITY = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});";
-
-var reBackslashOrAmp = /[\\&]/;
-
-var ESCAPABLE = '[!"#$%&\'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]';
-
-var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi');
-
-var XMLSPECIAL = '[&<>"]';
-
-var reXmlSpecial = new RegExp(XMLSPECIAL, 'g');
-
-var reXmlSpecialOrEntity = new RegExp(ENTITY + '|' + XMLSPECIAL, 'gi');
-
-var unescapeChar = function(s) {
- if (s[0] === '\\') {
- return s[1];
- } else {
- return entityToChar(s);
- }
-};
-
-// Replace entities and backslash escapes with literal characters.
-var unescapeString = function(s) {
- if (reBackslashOrAmp.test(s)) {
- return s.replace(reEntityOrEscapedChar, unescapeChar);
- } else {
- return s;
- }
-};
-
-var normalizeURI = function(uri) {
- try {
- return encodeURI(decodeURI(uri));
- }
- catch(err) {
- return uri;
- }
-};
-
-var replaceUnsafeChar = function(s) {
- switch (s) {
- case '&':
- return '&amp;';
- case '<':
- return '&lt;';
- case '>':
- return '&gt;';
- case '"':
- return '&quot;';
- default:
- return s;
- }
-};
-
-var escapeXml = function(s, preserve_entities) {
- if (reXmlSpecial.test(s)) {
- if (preserve_entities) {
- return s.replace(reXmlSpecialOrEntity, replaceUnsafeChar);
- } else {
- return s.replace(reXmlSpecial, replaceUnsafeChar);
- }
- } else {
- return s;
- }
-};
-
-module.exports = { unescapeString: unescapeString,
- normalizeURI: normalizeURI,
- escapeXml: escapeXml
- };