From d607ac12097afb5cb6f398a4e7b5cf4316efedc6 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Sun, 12 May 2024 12:14:02 +0700 Subject: self host --- .../markdown-it-14.1.0/lib/rules_inline/escape.mjs | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 packages/markdown-it-14.1.0/lib/rules_inline/escape.mjs (limited to 'packages/markdown-it-14.1.0/lib/rules_inline/escape.mjs') diff --git a/packages/markdown-it-14.1.0/lib/rules_inline/escape.mjs b/packages/markdown-it-14.1.0/lib/rules_inline/escape.mjs new file mode 100644 index 0000000..aa3728e --- /dev/null +++ b/packages/markdown-it-14.1.0/lib/rules_inline/escape.mjs @@ -0,0 +1,69 @@ +// Process escaped chars and hardbreaks + +import { isSpace } from '../common/utils.mjs' + +const ESCAPED = [] + +for (let i = 0; i < 256; i++) { ESCAPED.push(0) } + +'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' + .split('').forEach(function (ch) { ESCAPED[ch.charCodeAt(0)] = 1 }) + +export default function escape (state, silent) { + let pos = state.pos + const max = state.posMax + + if (state.src.charCodeAt(pos) !== 0x5C/* \ */) return false + pos++ + + // '\' at the end of the inline block + if (pos >= max) return false + + let ch1 = state.src.charCodeAt(pos) + + if (ch1 === 0x0A) { + if (!silent) { + state.push('hardbreak', 'br', 0) + } + + pos++ + // skip leading whitespaces from next line + while (pos < max) { + ch1 = state.src.charCodeAt(pos) + if (!isSpace(ch1)) break + pos++ + } + + state.pos = pos + return true + } + + let escapedStr = state.src[pos] + + if (ch1 >= 0xD800 && ch1 <= 0xDBFF && pos + 1 < max) { + const ch2 = state.src.charCodeAt(pos + 1) + + if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { + escapedStr += state.src[pos + 1] + pos++ + } + } + + const origStr = '\\' + escapedStr + + if (!silent) { + const token = state.push('text_special', '', 0) + + if (ch1 < 256 && ESCAPED[ch1] !== 0) { + token.content = escapedStr + } else { + token.content = origStr + } + + token.markup = origStr + token.info = 'escape' + } + + state.pos = pos + 1 + return true +} -- cgit v1.2.3