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

Method handleMatch

markdown/inlinepatterns.py:1437–1459  ·  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

1435 Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`).
1436 """
1437 def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element, int, int]:
1438 """ Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`. """
1439 el = etree.Element('a')
1440 email = self.unescape(m.group(1))
1441 if email.startswith("mailto:"):
1442 email = email[len("mailto:"):]
1443
1444 def codepoint2name(code: int) -> str:
1445 """Return entity definition by code, or the code if not defined."""
1446 entity = entities.codepoint2name.get(code)
1447 if entity:
1448 return "{}{};".format(util.AMP_SUBSTITUTE, entity)
1449 else:
1450 return "%s#%d;" % (util.AMP_SUBSTITUTE, code)
1451
1452 letters = [codepoint2name(ord(letter)) for letter in email]
1453 el.text = util.AtomicString(''.join(letters))
1454
1455 mailto = "mailto:" + email
1456 mailto = "".join([util.AMP_SUBSTITUTE + '#%d;' %
1457 ord(letter) for letter in mailto])
1458 el.set('href', mailto)
1459 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