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

Function tokenize

markdown_it/rules_inline/strikethrough.py:7–82  ·  view source on GitHub ↗

Insert each marker as a separate text token, and add it to delimiter list. When the ``strikethrough_single_tilde`` option is enabled on the ``MarkdownIt`` instance, single ``~`` delimiters are also accepted and runs of three or more tildes are rejected (matching GitHub's rendering behav

(state: StateInline, silent: bool)

Source from the content-addressed store, hash-verified

5
6
7def tokenize(state: StateInline, silent: bool) -> bool:
8 """Insert each marker as a separate text token, and add it to delimiter list.
9
10 When the ``strikethrough_single_tilde`` option is enabled on the
11 ``MarkdownIt`` instance, single ``~`` delimiters are also accepted and
12 runs of three or more tildes are rejected (matching GitHub's rendering behaviour).
13 """
14 start = state.pos
15 ch = state.src[start]
16
17 if silent:
18 return False
19
20 if ch != "~":
21 return False
22
23 scanned = state.scanDelims(state.pos, True)
24 length = scanned.length
25
26 single_tilde = state.md.options.get("strikethrough_single_tilde", False)
27
28 if single_tilde:
29 # GitHub mode: only accept exactly 1 or 2 tildes.
30 if length < 1:
31 return False
32 if length > 2:
33 # Consume 3+ tildes as plain text so the parser doesn't
34 # re-enter and match a subset of them. This intentionally
35 # matches GitHub's rendering, where ≥3 tildes are literal text.
36 token = state.push("text", "", 0)
37 token.content = ch * length
38 state.pos += scanned.length
39 return True
40
41 token = state.push("text", "", 0)
42 token.content = ch * length
43 state.delimiters.append(
44 Delimiter(
45 marker=ord(ch),
46 length=0, # disable "rule of 3" length checks
47 token=len(state.tokens) - 1,
48 end=-1,
49 open=scanned.can_open,
50 close=scanned.can_close,
51 )
52 )
53 else:
54 # Original markdown-it behaviour: minimum 2, split odd runs.
55 if length < 2:
56 return False
57
58 if length % 2:
59 token = state.push("text", "", 0)
60 token.content = ch
61 length -= 1
62
63 i = 0
64 while i < length:

Callers

nothing calls this directly

Calls 3

DelimiterClass · 0.85
scanDelimsMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…