Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/markdown_it/helpers/parse_link_destination.py: 95%

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

58 statements  

1""" 

2Parse link destination 

3""" 

4 

5from ..common.utils import charCodeAt, unescapeAll 

6 

7 

8class _Result: 

9 __slots__ = ("ok", "pos", "str") 

10 

11 def __init__(self) -> None: 

12 self.ok = False 

13 self.pos = 0 

14 self.str = "" 

15 

16 

17def parseLinkDestination(string: str, pos: int, maximum: int) -> _Result: 

18 start = pos 

19 result = _Result() 

20 

21 if charCodeAt(string, pos) == 0x3C: # /* < */ 

22 pos += 1 

23 while pos < maximum: 

24 code = charCodeAt(string, pos) 

25 if code == 0x0A: # /* \n */) 

26 return result 

27 if code == 0x3C: # / * < * / 

28 return result 

29 if code == 0x3E: # /* > */) { 

30 result.pos = pos + 1 

31 result.str = unescapeAll(string[start + 1 : pos]) 

32 result.ok = True 

33 return result 

34 

35 if code == 0x5C and pos + 1 < maximum: # \ 

36 pos += 2 

37 continue 

38 

39 pos += 1 

40 

41 # no closing '>' 

42 return result 

43 

44 # this should be ... } else { ... branch 

45 

46 level = 0 

47 while pos < maximum: 

48 code = charCodeAt(string, pos) 

49 

50 if code is None or code == 0x20: 

51 break 

52 

53 # ascii control characters 

54 if code < 0x20 or code == 0x7F: 

55 break 

56 

57 if code == 0x5C and pos + 1 < maximum: 

58 if charCodeAt(string, pos + 1) == 0x20: 

59 break 

60 pos += 2 

61 continue 

62 

63 if code == 0x28: # /* ( */) 

64 level += 1 

65 if level > 32: 

66 return result 

67 

68 if code == 0x29: # /* ) */) 

69 if level == 0: 

70 break 

71 level -= 1 

72 

73 pos += 1 

74 

75 if start == pos: 

76 return result 

77 if level != 0: 

78 return result 

79 

80 result.str = unescapeAll(string[start:pos]) 

81 result.pos = pos 

82 result.ok = True 

83 return result