diff options
author | Minteck <contact@minteck.org> | 2022-01-20 13:43:34 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-01-20 13:43:34 +0100 |
commit | c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1 (patch) | |
tree | 226598e8d17d20e3721358f7c60b1cc6b851163a /node_modules/markdown-it/lib/rules_inline/escape.js | |
download | cobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.tar.gz cobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.tar.bz2 cobalt-c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1.zip |
Initial commit
Diffstat (limited to 'node_modules/markdown-it/lib/rules_inline/escape.js')
-rw-r--r-- | node_modules/markdown-it/lib/rules_inline/escape.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/node_modules/markdown-it/lib/rules_inline/escape.js b/node_modules/markdown-it/lib/rules_inline/escape.js new file mode 100644 index 0000000..229ead0 --- /dev/null +++ b/node_modules/markdown-it/lib/rules_inline/escape.js @@ -0,0 +1,52 @@ +// Process escaped chars and hardbreaks + +'use strict'; + +var isSpace = require('../common/utils').isSpace; + +var ESCAPED = []; + +for (var i = 0; i < 256; i++) { ESCAPED.push(0); } + +'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' + .split('').forEach(function (ch) { ESCAPED[ch.charCodeAt(0)] = 1; }); + + +module.exports = function escape(state, silent) { + var ch, pos = state.pos, max = state.posMax; + + if (state.src.charCodeAt(pos) !== 0x5C/* \ */) { return false; } + + pos++; + + if (pos < max) { + ch = state.src.charCodeAt(pos); + + if (ch < 256 && ESCAPED[ch] !== 0) { + if (!silent) { state.pending += state.src[pos]; } + state.pos += 2; + return true; + } + + if (ch === 0x0A) { + if (!silent) { + state.push('hardbreak', 'br', 0); + } + + pos++; + // skip leading whitespaces from next line + while (pos < max) { + ch = state.src.charCodeAt(pos); + if (!isSpace(ch)) { break; } + pos++; + } + + state.pos = pos; + return true; + } + } + + if (!silent) { state.pending += '\\'; } + state.pos++; + return true; +}; |