Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_inline/backticks.py: 100%

44 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:07 +0000

1# Parse backticks 

2import re 

3 

4from .state_inline import StateInline 

5 

6regex = re.compile("^ (.+) $") 

7 

8 

9def backtick(state: StateInline, silent: bool) -> bool: 

10 pos = state.pos 

11 ch = state.srcCharCode[pos] 

12 

13 # /* ` */ 

14 if ch != 0x60: 

15 return False 

16 

17 start = pos 

18 pos += 1 

19 maximum = state.posMax 

20 

21 # scan marker length 

22 while pos < maximum and (state.srcCharCode[pos] == 0x60): # /* ` */ 

23 pos += 1 

24 

25 marker = state.src[start:pos] 

26 openerLength = len(marker) 

27 

28 if state.backticksScanned and state.backticks.get(openerLength, 0) <= start: 

29 if not silent: 

30 state.pending += marker 

31 state.pos += openerLength 

32 return True 

33 

34 matchStart = matchEnd = pos 

35 

36 # Nothing found in the cache, scan until the end of the line (or until marker is found) 

37 while True: 

38 try: 

39 matchStart = state.src.index("`", matchEnd) 

40 except ValueError: 

41 break 

42 matchEnd = matchStart + 1 

43 

44 # scan marker length 

45 while matchEnd < maximum and (state.srcCharCode[matchEnd] == 0x60): # /* ` */ 

46 matchEnd += 1 

47 

48 closerLength = matchEnd - matchStart 

49 

50 if closerLength == openerLength: 

51 # Found matching closer length. 

52 if not silent: 

53 token = state.push("code_inline", "code", 0) 

54 token.markup = marker 

55 token.content = state.src[pos:matchStart].replace("\n", " ") 

56 if ( 

57 token.content.startswith(" ") 

58 and token.content.endswith(" ") 

59 and len(token.content.strip()) > 0 

60 ): 

61 token.content = token.content[1:-1] 

62 state.pos = matchEnd 

63 return True 

64 

65 # Some different length found, put it in cache as upper limit of where closer can be found 

66 state.backticks[closerLength] = matchStart 

67 

68 # Scanned through the end, didn't find anything 

69 state.backticksScanned = True 

70 

71 if not silent: 

72 state.pending += marker 

73 state.pos += openerLength 

74 return True