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

Class StateInline

markdown_it/rules_inline/state_inline.py:44–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class StateInline(StateBase):
45 def __init__(
46 self, src: str, md: MarkdownIt, env: EnvType, outTokens: list[Token]
47 ) -> None:
48 self.src = src
49 self.env = env
50 self.md = md
51 self.tokens = outTokens
52 self.tokens_meta: list[dict[str, Any] | None] = [None] * len(outTokens)
53
54 self.pos = 0
55 self.posMax = len(self.src)
56 self.level = 0
57 self.pending = ""
58 self.pendingLevel = 0
59
60 # Stores { start: end } pairs. Useful for backtrack
61 # optimization of pairs parse (emphasis, strikes).
62 self.cache: dict[int, int] = {}
63
64 # List of emphasis-like delimiters for current tag
65 self.delimiters: list[Delimiter] = []
66
67 # Stack of delimiter lists for upper level tags
68 self._prev_delimiters: list[list[Delimiter]] = []
69
70 # backticklength => last seen position
71 self.backticks: dict[int, int] = {}
72 self.backticksScanned = False
73
74 # Counter used to disable inline linkify-it execution
75 # inside <a> and markdown links
76 self.linkLevel = 0
77
78 def __repr__(self) -> str:
79 return (
80 f"{self.__class__.__name__}"
81 f"(pos=[{self.pos} of {self.posMax}], token={len(self.tokens)})"
82 )
83
84 def pushPending(self) -> Token:
85 token = Token("text", "", 0)
86 token.content = self.pending
87 token.level = self.pendingLevel
88 self.tokens.append(token)
89 self.pending = ""
90 return token
91
92 def push(self, ttype: str, tag: str, nesting: Literal[-1, 0, 1]) -> Token:
93 """Push new token to "stream".
94 If pending text exists - flush it as text token
95 """
96 if self.pending:
97 self.pushPending()
98
99 token = Token(ttype, tag, nesting)
100 token_meta = None
101

Callers 1

parseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…