Class: MarkdownIt::RulesInline::Escape
- Inherits:
-
Object
- Object
- MarkdownIt::RulesInline::Escape
- Extended by:
- Common::Utils
- Defined in:
- lib/motion-markdown-it/rules_inline/escape.rb
Constant Summary collapse
- ESCAPED =
[]
Constants included from Common::Utils
Common::Utils::DIGITAL_ENTITY_TEST_RE, Common::Utils::ENTITY_RE, Common::Utils::HTML_ESCAPE_REPLACE_RE, Common::Utils::HTML_ESCAPE_TEST_RE, Common::Utils::HTML_REPLACEMENTS, Common::Utils::REGEXP_ESCAPE_RE, Common::Utils::UNESCAPE_ALL_RE, Common::Utils::UNESCAPE_MD_RE, Common::Utils::UNICODE_PUNCT_RE
Class Method Summary collapse
-
.escape(state, silent) ⇒ Object
——————————————————————————.
Methods included from Common::Utils
arrayReplaceAt, assign, charCodeAt, escapeHtml, escapeRE, fromCharCode, fromCodePoint, isMdAsciiPunct, isPunctChar, isSpace, isValidEntityCode, isWhiteSpace, normalizeReference, replaceEntityPattern, unescapeAll, unescapeMd
Class Method Details
.escape(state, silent) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/motion-markdown-it/rules_inline/escape.rb', line 15 def self.escape(state, silent) pos = state.pos max = state.posMax return false if charCodeAt(state.src, pos) != 0x5C # pos += 1 # '\' at the end of the inline block return false if pos >= max ch1 = charCodeAt(state.src, pos) if ch1 == 0x0A if !silent state.push('hardbreak', 'br', 0) end pos += 1 # skip leading whitespaces from next line while pos < max ch1 = charCodeAt(state.src, pos) break if !isSpace(ch1) pos += 1 end state.pos = pos return true end escapedStr = state.src[pos] if (ch1 >= 0xD800 && ch1 <= 0xDBFF && pos + 1 < max) ch2 = charCodeAt(state.src, pos + 1) if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) escapedStr += state.src[pos + 1] pos += 1 end end origStr = '\\' + escapedStr if (!silent) token = state.push('text_special', '', 0) if ch1 < 256 && ESCAPED[ch1] != 0 token.content = escapedStr else token.content = origStr end token.markup = origStr token.info = 'escape' end state.pos = pos + 1 return true end |