Class: MarkdownIt::RulesInline::Escape

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-markdown-it/rules_inline/escape.rb

Constant Summary collapse

ESCAPED =
[]

Class Method Summary collapse

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
# 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 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 && state.src.charCodeAt(pos) == 0x20)
        pos += 1
      end

      state.pos = pos
      return true
    end
  end

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