Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/markdown_it/rules_inline/escape.py: 100%
33 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"""
2Process escaped chars and hardbreaks
3"""
4from ..common.utils import isSpace
5from .state_inline import StateInline
7ESCAPED = [0 for _ in range(256)]
8for ch in "\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-":
9 ESCAPED[ord(ch)] = 1
12def escape(state: StateInline, silent: bool):
13 pos = state.pos
14 maximum = state.posMax
16 # /* \ */
17 if state.srcCharCode[pos] != 0x5C:
18 return False
20 pos += 1
22 if pos < maximum:
23 ch = state.srcCharCode[pos]
25 if ch < 256 and ESCAPED[ch] != 0:
26 if not silent:
27 state.pending += state.src[pos]
28 state.pos += 2
29 return True
31 if ch == 0x0A:
32 if not silent:
33 state.push("hardbreak", "br", 0)
35 pos += 1
36 # skip leading whitespaces from next line
37 while pos < maximum:
38 ch = state.srcCharCode[pos]
39 if not isSpace(ch):
40 break
41 pos += 1
43 state.pos = pos
44 return True
46 if not silent:
47 state.pending += "\\"
48 state.pos += 1
49 return True