Class: MarkdownIt::RulesInline::Escape

Inherits:
Object
  • Object
show all
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

Methods included from Common::Utils

arrayReplaceAt, assign, escapeHtml, escapeRE, fromCharCode, fromCodePoint, isMdAsciiPunct, isPunctChar, isSpace, isValidEntityCode, isWhiteSpace, normalizeReference, replaceEntityPattern, unescapeAll, unescapeMd

Class Method Details

.escape(state, silent) ⇒ Object




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
# File 'lib/motion-markdown-it/rules_inline/escape.rb', line 16

def self.escape(state, silent)
  pos = state.pos
  max = state.posMax

  return false if state.src.charCodeAt(pos) != 0x5C    # \

  pos += 1

  if pos < max
    ch = state.src.charCodeAt(pos)

    if ch < 256 && ESCAPED[ch] != 0
      state.pending += state.src[pos] if !silent
      state.pos     += 2
      return true
    end

    if ch == 0x0A
      if !silent
        state.push('hardbreak', 'br', 0)
      end

      pos += 1
      # skip leading whitespaces from next line
      while pos < max
        ch = state.src.charCodeAt(pos)
        break if !isSpace(ch)
        pos += 1
      end

      state.pos = pos
      return true
    end
  end

  state.pending += '\\' if !silent
  state.pos += 1
  return true
end