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

Method skipToken

markdown_it/parser_inline.py:132–172  ·  view source on GitHub ↗

Skip single token by running all rules in validation mode; returns `True` if any rule reported success

(self, state: StateInline)

Source from the content-addressed store, hash-verified

130 )
131
132 def skipToken(self, state: StateInline) -> None:
133 """Skip single token by running all rules in validation mode;
134 returns `True` if any rule reported success
135 """
136 ok = False
137 pos = state.pos
138 rules = self.ruler.getRules("")
139 maxNesting = state.md.options["maxNesting"]
140 cache = state.cache
141
142 if pos in cache:
143 state.pos = cache[pos]
144 return
145
146 if state.level < maxNesting:
147 for rule in rules:
148 # Increment state.level and decrement it later to limit recursion.
149 # It's harmless to do here, because no tokens are created.
150 # But ideally, we'd need a separate private state variable for this purpose.
151 state.level += 1
152 ok = rule(state, True)
153 state.level -= 1
154 if ok:
155 break
156 else:
157 # Too much nesting, just skip until the end of the paragraph.
158 #
159 # NOTE: this will cause links to behave incorrectly in the following case,
160 # when an amount of `[` is exactly equal to `maxNesting + 1`:
161 #
162 # [[[[[[[[[[[[[[[[[[[[[foo]()
163 #
164 # TODO: remove this workaround when CM standard will allow nested links
165 # (we can replace it by preventing links from being parsed in
166 # validation mode)
167 #
168 state.pos = state.posMax
169
170 if not ok:
171 state.pos += 1
172 cache[pos] = state.pos
173
174 def tokenize(self, state: StateInline) -> None:
175 """Generate tokens for input range."""

Callers 1

parseLinkLabelFunction · 0.80

Calls 1

getRulesMethod · 0.80

Tested by

no test coverage detected