Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/helpers/parse_link_title.py: 98%
42 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +0000
1"""Parse link title
2"""
3from ..common.utils import charCodeAt, unescapeAll
6class _Result:
7 __slots__ = ("ok", "pos", "lines", "str")
9 def __init__(self) -> None:
10 self.ok = False
11 self.pos = 0
12 self.lines = 0
13 self.str = ""
15 def __str__(self) -> str:
16 return self.str
19def parseLinkTitle(string: str, pos: int, maximum: int) -> _Result:
20 lines = 0
21 start = pos
22 result = _Result()
24 if pos >= maximum:
25 return result
27 marker = charCodeAt(string, pos)
29 # /* " */ /* ' */ /* ( */
30 if marker != 0x22 and marker != 0x27 and marker != 0x28:
31 return result
33 pos += 1
35 # if opening marker is "(", switch it to closing marker ")"
36 if marker == 0x28:
37 marker = 0x29
39 while pos < maximum:
40 code = charCodeAt(string, pos)
41 if code == marker:
42 title = string[start + 1 : pos]
43 title = unescapeAll(title)
44 result.pos = pos + 1
45 result.lines = lines
46 result.str = title
47 result.ok = True
48 return result
49 elif code == 0x28 and marker == 0x29: # /* ( */ /* ) */
50 return result
51 elif code == 0x0A:
52 lines += 1
53 elif code == 0x5C and pos + 1 < maximum: # /* \ */
54 pos += 1
55 if charCodeAt(string, pos) == 0x0A:
56 lines += 1
58 pos += 1
60 return result