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

Method handleMatch

markdown/inlinepatterns.py:974–996  ·  view source on GitHub ↗

Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`.

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

Source from the content-addressed store, hash-verified

972 Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`).
973 """
974 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element, int, int]:
975 """ Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`. """
976 el = etree.Element('a')
977 email = self.unescape(m.group(1))
978 if email.startswith("mailto:"):
979 email = email[len("mailto:"):]
980
981 def codepoint2name(code: int) -> str:
982 """Return entity definition by code, or the code if not defined."""
983 entity = entities.codepoint2name.get(code)
984 if entity:
985 return "{}{};".format(util.AMP_SUBSTITUTE, entity)
986 else:
987 return "%s#%d;" % (util.AMP_SUBSTITUTE, code)
988
989 letters = [codepoint2name(ord(letter)) for letter in email]
990 el.text = util.AtomicString(''.join(letters))
991
992 mailto = "mailto:" + email
993 mailto = "".join([util.AMP_SUBSTITUTE + '#%d;' %
994 ord(letter) for letter in mailto])
995 el.set('href', mailto)
996 return el, m.start(0), m.end(0)

Callers

nothing calls this directly

Calls 2

setMethod · 0.80
unescapeMethod · 0.45

Tested by

no test coverage detected