MCPcopy
hub / github.com/Python-Markdown/markdown / BacktickInlineProcessor

Class BacktickInlineProcessor

markdown/inlinepatterns.py:436–458  ·  view source on GitHub ↗

Return a ` ` element containing the escaped matching text.

Source from the content-addressed store, hash-verified

434
435
436class BacktickInlineProcessor(InlineProcessor):
437 """ Return a `<code>` element containing the escaped matching text. """
438 def __init__(self, pattern: str):
439 InlineProcessor.__init__(self, pattern)
440 self.ESCAPED_BSLASH = '{}{}{}'.format(util.STX, ord('\\'), util.ETX)
441 self.tag = 'code'
442 """ The tag of the rendered element. """
443
444 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | str, int, int]:
445 """
446 If the match contains `group(3)` of a pattern, then return a `code`
447 [`Element`][xml.etree.ElementTree.Element] which contains HTML escaped text (with
448 [`code_escape`][markdown.util.code_escape]) as an [`AtomicString`][markdown.util.AtomicString].
449
450 If the match does not contain `group(3)` then return the text of `group(1)` backslash escaped.
451
452 """
453 if m.group(3):
454 el = etree.Element(self.tag)
455 el.text = util.AtomicString(util.code_escape(m.group(3).strip()))
456 return el, m.start(0), m.end(0)
457 else:
458 return m.group(1).replace('\\\\', self.ESCAPED_BSLASH), m.start(0), m.end(0)
459
460
461class DoubleTagPattern(SimpleTagPattern): # pragma: no cover

Callers 1

build_inlinepatternsFunction · 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…