Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/helpers/parse_link_title.py: 98%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

42 statements  

1"""Parse link title 

2""" 

3from ..common.utils import charCodeAt, unescapeAll 

4 

5 

6class _Result: 

7 __slots__ = ("ok", "pos", "lines", "str") 

8 

9 def __init__(self) -> None: 

10 self.ok = False 

11 self.pos = 0 

12 self.lines = 0 

13 self.str = "" 

14 

15 def __str__(self) -> str: 

16 return self.str 

17 

18 

19def parseLinkTitle(string: str, pos: int, maximum: int) -> _Result: 

20 lines = 0 

21 start = pos 

22 result = _Result() 

23 

24 if pos >= maximum: 

25 return result 

26 

27 marker = charCodeAt(string, pos) 

28 

29 # /* " */ /* ' */ /* ( */ 

30 if marker != 0x22 and marker != 0x27 and marker != 0x28: 

31 return result 

32 

33 pos += 1 

34 

35 # if opening marker is "(", switch it to closing marker ")" 

36 if marker == 0x28: 

37 marker = 0x29 

38 

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 

57 

58 pos += 1 

59 

60 return result