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

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

27 statements  

1""" 

2Parse link label 

3 

4this function assumes that first character ("[") already matches 

5returns the end of the label 

6 

7""" 

8 

9from markdown_it.rules_inline import StateInline 

10 

11 

12def parseLinkLabel(state: StateInline, start: int, disableNested: bool = False) -> int: 

13 labelEnd = -1 

14 oldPos = state.pos 

15 found = False 

16 

17 state.pos = start + 1 

18 level = 1 

19 

20 while state.pos < state.posMax: 

21 marker = state.src[state.pos] 

22 if marker == "]": 

23 level -= 1 

24 if level == 0: 

25 found = True 

26 break 

27 

28 prevPos = state.pos 

29 state.md.inline.skipToken(state) 

30 if marker == "[": 

31 if prevPos == state.pos - 1: 

32 # increase level if we find text `[`, 

33 # which is not a part of any token 

34 level += 1 

35 elif disableNested: 

36 state.pos = oldPos 

37 return -1 

38 if found: 

39 labelEnd = state.pos 

40 

41 # restore old state 

42 state.pos = oldPos 

43 

44 return labelEnd