Class: MarkdownIt::RulesBlock::Hr

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

Constant Summary

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

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




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
# File 'lib/motion-markdown-it/rules_block/hr.rb', line 9

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

  # if it's indented more than 3 spaces, it should be a code block
  return false if (state.sCount[startLine] - state.blkIndent >= 4)

  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 of them

  cnt = 1
  while (pos < max)
    ch   = state.src.charCodeAt(pos)
    pos += 1
    return false if ch != marker && !isSpace(ch)
    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