Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_inline/backticks.py: 100%
43 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:15 +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
12 if state.src[pos] != "`":
13 return False
15 start = pos
16 pos += 1
17 maximum = state.posMax
19 # scan marker length
20 while pos < maximum and (state.src[pos] == "`"):
21 pos += 1
23 marker = state.src[start:pos]
24 openerLength = len(marker)
26 if state.backticksScanned and state.backticks.get(openerLength, 0) <= start:
27 if not silent:
28 state.pending += marker
29 state.pos += openerLength
30 return True
32 matchStart = matchEnd = pos
34 # Nothing found in the cache, scan until the end of the line (or until marker is found)
35 while True:
36 try:
37 matchStart = state.src.index("`", matchEnd)
38 except ValueError:
39 break
40 matchEnd = matchStart + 1
42 # scan marker length
43 while matchEnd < maximum and (state.src[matchEnd] == "`"):
44 matchEnd += 1
46 closerLength = matchEnd - matchStart
48 if closerLength == openerLength:
49 # Found matching closer length.
50 if not silent:
51 token = state.push("code_inline", "code", 0)
52 token.markup = marker
53 token.content = state.src[pos:matchStart].replace("\n", " ")
54 if (
55 token.content.startswith(" ")
56 and token.content.endswith(" ")
57 and len(token.content.strip()) > 0
58 ):
59 token.content = token.content[1:-1]
60 state.pos = matchEnd
61 return True
63 # Some different length found, put it in cache as upper limit of where closer can be found
64 state.backticks[closerLength] = matchStart
66 # Scanned through the end, didn't find anything
67 state.backticksScanned = True
69 if not silent:
70 state.pending += marker
71 state.pos += openerLength
72 return True