Class: MarkdownIt::RulesBlock::Hr

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

Class Method Summary collapse

Class Method Details

.hr(state, startLine, endLine, silent) ⇒ Object




8
9
10
11
12
13
14
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
# File 'lib/motion-markdown-it/rules_block/hr.rb', line 8

def self.hr(state, startLine, endLine, silent)
  pos    = state.bMarks[startLine] + state.tShift[startLine]
  max    = state.eMarks[startLine]
  marker = state.src.charCodeAt(pos)
  pos   += 1

  # Check hr marker
  if (marker != 0x2A &&  # *
      marker != 0x2D &&  # -
      marker != 0x5F)    # _
    return false
  end

  # markers can be mixed with spaces, but there should be at least 3 one

  cnt = 1
  while (pos < max)
    ch   = state.src.charCodeAt(pos)
    pos += 1
    return false if (ch != marker && ch != 0x20) # space
    cnt += 1 if (ch == marker)
  end

  return false if (cnt < 3)
  return true if (silent)

  state.line = startLine + 1

  token        = state.push('hr', 'hr', 0)
  token.map    = [ startLine, state.line ]
  token.markup = marker.chr * (cnt + 1)

  return true
end