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

Method handleMatch

markdown/inlinepatterns.py:1046–1065  ·  view source on GitHub ↗

Return an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`.

(self, m: re.Match[str], data: str)

Source from the content-addressed store, hash-verified

1044 RE_TITLE_CLEAN = re.compile(r'\s')
1045
1046 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element | None, int | None, int | None]:
1047 """ Return an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. """
1048 text, index, handled = self.getText(data, m.end(0))
1049
1050 if not handled:
1051 return None, None, None
1052
1053 href, title, index, handled = self.getLink(data, index)
1054 if not handled:
1055 return None, None, None
1056
1057 el = etree.Element("a")
1058 el.text = text
1059
1060 el.set("href", href)
1061
1062 if title is not None:
1063 el.set("title", title)
1064
1065 return el, m.start(0), index
1066
1067 def getLink(self, data: str, index: int) -> tuple[str, str | None, int, bool]:
1068 """Parse data between `()` of `[Text]()` allowing recursive `()`. """

Callers

nothing calls this directly

Calls 3

getTextMethod · 0.95
getLinkMethod · 0.95
setMethod · 0.80

Tested by

no test coverage detected