Class: MarkdownIt::RulesBlock::HtmlBlock

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

Constant Summary collapse

HTML_OPEN_CLOSE_TAG_RE =
MarkdownIt::Common::HtmlRe::HTML_OPEN_CLOSE_TAG_RE
HTML_SEQUENCES =

An array of opening and corresponding closing sequences for html tags, last argument defines whether it can terminate a paragraph or not

[
  [ /^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true ],
  [ /^<!--/,        /-->/,   true ],
  [ /^<\?/,         /\?>/,   true ],
  [ /^<![A-Z]/,     />/,     true ],
  [ /^<!\[CDATA\[/, /\]\]>/, true ],
  [ Regexp.new('^</?(' + MarkdownIt::HTML_BLOCKS.join('|') + ')(?=(\\s|/?>|$))', 'i'), /^$/, true ],
  [ Regexp.new(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'),  /^$/, false ]
]

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, charCodeAt, escapeHtml, escapeRE, fromCharCode, fromCodePoint, isMdAsciiPunct, isPunctChar, isSpace, isValidEntityCode, isWhiteSpace, normalizeReference, replaceEntityPattern, unescapeAll, unescapeMd

Class Method Details

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




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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/motion-markdown-it/rules_block/html_block.rb', line 24

def self.html_block(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

  return false if !state.md.options[:html]
  return false if charCodeAt(state.src, pos) != 0x3C    # <

  lineText = state.src.slice(pos...max)

  i = 0
  while i < HTML_SEQUENCES.length
    break if HTML_SEQUENCES[i][0].match(lineText)
    i += 1
  end

  return false if i == HTML_SEQUENCES.length

  if silent
    # true if this sequence can be a terminator, false otherwise
    return HTML_SEQUENCES[i][2]
  end

  nextLine = startLine + 1

  # If we are here - we detected HTML block.
  # Let's roll down till block end.
  if !HTML_SEQUENCES[i][1].match(lineText)
    while nextLine < endLine
      break if state.sCount[nextLine] < state.blkIndent

      pos = state.bMarks[nextLine] + state.tShift[nextLine]
      max = state.eMarks[nextLine]
      lineText = state.src.slice(pos...max)

      if HTML_SEQUENCES[i][1].match(lineText)
        nextLine += 1 if lineText.length != 0
        break
      end
      nextLine += 1
    end
  end

  state.line = nextLine

  token         = state.push('html_block', '', 0)
  token.map     = [ startLine, nextLine ]
  token.content = state.getLines(startLine, nextLine, state.blkIndent, true)

  return true
end