Class: MarkdownIt::RulesInline::Backticks

Inherits:
Object
  • Object
show all
Extended by:
Common::Utils
Defined in:
lib/motion-markdown-it/rules_inline/backticks.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, charCodeAt, escapeHtml, escapeRE, fromCharCode, fromCodePoint, isMdAsciiPunct, isPunctChar, isSpace, isValidEntityCode, isWhiteSpace, normalizeReference, replaceEntityPattern, unescapeAll, unescapeMd

Class Method Details

.backtick(state, 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
47
48
# File 'lib/motion-markdown-it/rules_inline/backticks.rb', line 9

def self.backtick(state, silent)
  pos = state.pos
  ch = charCodeAt(state.src, pos)

  return false if (ch != 0x60)  #  `

  start = pos
  pos  += 1
  max  = state.posMax

  while (pos < max && charCodeAt(state.src, pos) == 0x60)  # `
    pos += 1
  end

  marker = state.src.slice(start...pos)

  matchStart = matchEnd = pos

  while ((matchStart = state.src.index('`', matchEnd)) != nil)
    matchEnd = matchStart + 1

    while (matchEnd < max && charCodeAt(state.src, matchEnd) == 0x60) # `
      matchEnd += 1
    end

    if (matchEnd - matchStart == marker.length)
      if (!silent)
        token         = state.push('code_inline', 'code', 0)
        token.markup  = marker
        token.content = state.src.slice(pos...matchStart).gsub(/[ \n]+/, ' ').strip
      end
      state.pos = matchEnd
      return true
    end
  end

  state.pending += marker if (!silent)
  state.pos     += marker.length
  return true
end