Return a `mailto` link Element given an auto-mail link (` `).
| 1319 | |
| 1320 | |
| 1321 | class AutomailInlineProcessor(InlineProcessor): |
| 1322 | """ |
| 1323 | Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`). |
| 1324 | """ |
| 1325 | def handleMatch(self, m: re.Match[str], data: str) -> tuple[etree.Element, int, int]: |
| 1326 | """ Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`. """ |
| 1327 | el = etree.Element('a') |
| 1328 | email = self.unescape(m.group(1)) |
| 1329 | if email.startswith("mailto:"): |
| 1330 | email = email[len("mailto:"):] |
| 1331 | |
| 1332 | def codepoint2name(code: int) -> str: |
| 1333 | """Return entity definition by code, or the code if not defined.""" |
| 1334 | entity = entities.codepoint2name.get(code) |
| 1335 | if entity: |
| 1336 | return "{}{};".format(util.AMP_SUBSTITUTE, entity) |
| 1337 | else: |
| 1338 | return "%s#%d;" % (util.AMP_SUBSTITUTE, code) |
| 1339 | |
| 1340 | letters = [codepoint2name(ord(letter)) for letter in email] |
| 1341 | el.text = util.AtomicString(''.join(letters)) |
| 1342 | |
| 1343 | mailto = "mailto:" + email |
| 1344 | mailto = "".join([util.AMP_SUBSTITUTE + '#%d;' % |
| 1345 | ord(letter) for letter in mailto]) |
| 1346 | el.set('href', mailto) |
| 1347 | return el, m.start(0), m.end(0) |
no outgoing calls
no test coverage detected