Class: MarkdownIt::RulesInline::HtmlInline

Inherits:
Object
  • Object
show all
Extended by:
Common::Utils
Includes:
Common::HtmlRe
Defined in:
lib/motion-markdown-it/rules_inline/html_inline.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

Constants included from Common::HtmlRe

Common::HtmlRe::ATTRIBUTE, Common::HtmlRe::ATTR_NAME, Common::HtmlRe::ATTR_VALUE, Common::HtmlRe::CDATA, Common::HtmlRe::CLOSE_TAG, Common::HtmlRe::COMMENT, Common::HtmlRe::DECLARATION, Common::HtmlRe::DOUBLE_QUOTED, Common::HtmlRe::HTML_OPEN_CLOSE_TAG_RE, Common::HtmlRe::HTML_TAG_RE, Common::HtmlRe::OPEN_TAG, Common::HtmlRe::PROCESSING, Common::HtmlRe::SINGLE_QUOTED, Common::HtmlRe::UNQUOTED

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_inline(state, 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
# File 'lib/motion-markdown-it/rules_inline/html_inline.rb', line 24

def self.html_inline(state, silent)
  pos = state.pos

  return false if !state.md.options[:html]

  # Check start
  max = state.posMax
  if (charCodeAt(state.src, pos) != 0x3C || pos + 2 >= max)  #  <
    return false
  end

  # Quick fail on second char
  ch = charCodeAt(state.src, pos + 1)
  if (ch != 0x21 &&  # !
      ch != 0x3F &&  # ?
      ch != 0x2F &&  # /
      !isLetter(ch))
    return false
  end

  match = state.src[pos..-1].match(HTML_TAG_RE)
  return false if !match

  if !silent
    token         = state.push('html_inline', '', 0)
    token.content = state.src.slice(pos...(pos + match[0].length))

    state.linkLevel += 1 if (isLinkOpen(token.content))
    state.linkLevel -= 1 if (isLinkClose(token.content))
  end
  state.pos += match[0].length
  return true
end

.isLetter(ch) ⇒ Object




18
19
20
21
# File 'lib/motion-markdown-it/rules_inline/html_inline.rb', line 18

def self.isLetter(ch)
  lc = ch | 0x20    # to lower case
  return (lc >= 0x61) && (lc <= 0x7a)  # >= a && <= z
end

.isLinkClose(str) ⇒ Object



13
14
15
# File 'lib/motion-markdown-it/rules_inline/html_inline.rb', line 13

def self.isLinkClose(str)
  return !(/^<\/a\s*>/i =~ str).nil?
end

.isLinkOpen(str) ⇒ Object




10
11
12
# File 'lib/motion-markdown-it/rules_inline/html_inline.rb', line 10

def self.isLinkOpen(str)
  return !(/^<a[>\s]/i =~ str).nil?
end