Class: MarkdownIt::RulesBlock::Lheading

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

Class Method Summary collapse

Class Method Details

.lheading(state, startLine, endLine, silent = true) ⇒ 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
42
43
44
45
46
47
48
49
50
# File 'lib/motion-markdown-it/rules_block/lheading.rb', line 8

def self.lheading(state, startLine, endLine, silent = true)
  nextLine = startLine + 1

  return false if (nextLine >= endLine)
  return false if (state.tShift[nextLine] < state.blkIndent)

  # Scan next line

  return false if (state.tShift[nextLine] - state.blkIndent > 3)

  pos = state.bMarks[nextLine] + state.tShift[nextLine]
  max = state.eMarks[nextLine]

  return false if (pos >= max)

  marker = state.src.charCodeAt(pos)

  return false if (marker != 0x2D && marker != 0x3D) # != '-' && != '='

  pos = state.skipChars(pos, marker)
  pos = state.skipSpaces(pos)

  return false if (pos < max)

  pos = state.bMarks[startLine] + state.tShift[startLine]

  state.line = nextLine + 1
  level = (marker == 0x3D ? 1 : 2) # =

  token          = state.push('heading_open', "h#{level.to_s}", 1)
  token.markup   = marker.chr
  token.map      = [ startLine, state.line ]

  token          = state.push('inline', '', 0)
  token.content  = state.src.slice(pos...state.eMarks[startLine]).strip
  token.map      = [ startLine, state.line - 1 ]
  token.children = []

  token          = state.push('heading_close', "h#{level.to_s}", -1)
  token.markup   = marker.chr

  return true
end