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
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:07 +0000
1# Parse backticks
2import re
4from .state_inline import StateInline
6regex = re.compile("^ (.+) $")
9def backtick(state: StateInline, silent: bool) -> bool:
10 pos = state.pos
11 ch = state.srcCharCode[pos]
13 # /* ` */
14 if ch != 0x60:
15 return False
17 start = pos
18 pos += 1
19 maximum = state.posMax
21 # scan marker length
22 while pos < maximum and (state.srcCharCode[pos] == 0x60): # /* ` */
23 pos += 1
25 marker = state.src[start:pos]
26 openerLength = len(marker)
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
34 matchStart = matchEnd = pos
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
44 # scan marker length
45 while matchEnd < maximum and (state.srcCharCode[matchEnd] == 0x60): # /* ` */
46 matchEnd += 1
48 closerLength = matchEnd - matchStart
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
65 # Some different length found, put it in cache as upper limit of where closer can be found
66 state.backticks[closerLength] = matchStart
68 # Scanned through the end, didn't find anything
69 state.backticksScanned = True
71 if not silent:
72 state.pending += marker
73 state.pos += openerLength
74 return True