Module: MarkdownIt::Helpers::ParseLinkTitle

Included in:
HelperWrapper
Defined in:
lib/motion-markdown-it/helpers/parse_link_title.rb

Instance Method Summary collapse

Instance Method Details

#parseLinkTitle(str, pos, max) ⇒ 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
# File 'lib/motion-markdown-it/helpers/parse_link_title.rb', line 8

def parseLinkTitle(str, pos, max)
  lines = 0
  start = pos
  result = {ok: false, pos: 0, lines: 0, str: ''}

  return result if (pos >= max)

  marker = charCodeAt(str, pos)

  return result if (marker != 0x22 && marker != 0x27 && marker != 0x28) # " ' (

  pos += 1

  # if opening marker is "(", switch it to closing marker ")"
  marker = 0x29 if (marker == 0x28)

  while (pos < max)
    code = charCodeAt(str, pos)
    if (code == marker)
      result[:pos]   = pos + 1
      result[:lines] = lines
      result[:str]   = unescapeAll(str.slice((start + 1)...pos))
      result[:ok]    = true
      return result
    elsif (code == 0x0A)
      lines += 1
    elsif (code == 0x5C && pos + 1 < max) # \
      pos += 1
      if (charCodeAt(str, pos) == 0x0A)
        lines += 1
      end
    end

    pos += 1
  end

  return result
end