MCPcopy Create free account
hub / github.com/Python-Markdown/markdown / __applyPattern

Method __applyPattern

markdown/treeprocessors.py:253–331  ·  view source on GitHub ↗

Check if the line fits the pattern, create the necessary elements, add it to `stashed_nodes`. Arguments: data: The text to be processed. pattern: The pattern to be checked. patternIndex: Index of current pattern. startIndex: S

(
        self,
        pattern: inlinepatterns.Pattern,
        data: str,
        patternIndex: int,
        startIndex: int = 0
    )

Source from the content-addressed store, hash-verified

251 return result
252
253 def __applyPattern(
254 self,
255 pattern: inlinepatterns.Pattern,
256 data: str,
257 patternIndex: int,
258 startIndex: int = 0
259 ) -> tuple[str, bool, int]:
260 """
261 Check if the line fits the pattern, create the necessary
262 elements, add it to `stashed_nodes`.
263
264 Arguments:
265 data: The text to be processed.
266 pattern: The pattern to be checked.
267 patternIndex: Index of current pattern.
268 startIndex: String index, from which we start searching.
269
270 Returns:
271 String with placeholders instead of `ElementTree` elements.
272
273 """
274 new_style = isinstance(pattern, inlinepatterns.InlineProcessor)
275
276 for exclude in pattern.ANCESTOR_EXCLUDES:
277 if exclude.lower() in self.ancestors:
278 return data, False, 0
279
280 if new_style:
281 match = None
282 # Since `handleMatch` may reject our first match,
283 # we iterate over the buffer looking for matches
284 # until we can't find any more.
285 for match in pattern.getCompiledRegExp().finditer(data, startIndex):
286 node, start, end = pattern.handleMatch(match, data)
287 if start is None or end is None:
288 startIndex += match.end(0)
289 match = None
290 continue
291 break
292 else: # pragma: no cover
293 match = pattern.getCompiledRegExp().match(data[startIndex:])
294 leftData = data[:startIndex]
295
296 if not match:
297 return data, False, 0
298
299 if not new_style: # pragma: no cover
300 node = pattern.handleMatch(match)
301 start = match.start(0)
302 end = match.end(0)
303
304 if node is None:
305 return data, True, end
306
307 if not isinstance(node, str):
308 if not isinstance(node.text, util.AtomicString):
309 # We need to process current node too
310 for child in [node] + list(node):

Callers 1

__handleInlineMethod · 0.95

Calls 6

__handleInlineMethod · 0.95
__stashNodeMethod · 0.95
isStringFunction · 0.85
getCompiledRegExpMethod · 0.80
typeMethod · 0.80
handleMatchMethod · 0.45

Tested by

no test coverage detected