MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / escape

Function escape

markdown_it/rules_inline/escape.py:9–57  ·  view source on GitHub ↗

Process escaped chars and hardbreaks.

(state: StateInline, silent: bool)

Source from the content-addressed store, hash-verified

7
8
9def escape(state: StateInline, silent: bool) -> bool:
10 """Process escaped chars and hardbreaks."""
11 pos = state.pos
12 maximum = state.posMax
13
14 if state.src[pos] != "\\":
15 return False
16
17 pos += 1
18
19 # '\' at the end of the inline block
20 if pos >= maximum:
21 return False
22
23 ch1 = state.src[pos]
24 ch1_ord = ord(ch1)
25 if ch1 == "\n":
26 if not silent:
27 state.push("hardbreak", "br", 0)
28 pos += 1
29 # skip leading whitespaces from next line
30 while pos < maximum:
31 ch = state.src[pos]
32 if not isStrSpace(ch):
33 break
34 pos += 1
35
36 state.pos = pos
37 return True
38
39 escapedStr = state.src[pos]
40
41 if ch1_ord >= 0xD800 and ch1_ord <= 0xDBFF and pos + 1 < maximum:
42 ch2 = state.src[pos + 1]
43 ch2_ord = ord(ch2)
44 if ch2_ord >= 0xDC00 and ch2_ord <= 0xDFFF:
45 escapedStr += ch2
46 pos += 1
47
48 origStr = "\\" + escapedStr
49
50 if not silent:
51 token = state.push("text_special", "", 0)
52 token.content = escapedStr if ch1 in _ESCAPED else origStr
53 token.markup = origStr
54 token.info = "escape"
55
56 state.pos = pos + 1
57 return True
58
59
60_ESCAPED = {

Callers

nothing calls this directly

Calls 2

isStrSpaceFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…