Skip to content

fix(html): preserve mailto: and tel: links (#2644) - #2648

Open
İlker Oğulcan SAYIN (iosayin) wants to merge 1 commit into
microsoft:mainfrom
iosayin:fix/preserve-mailto-tel-links
Open

İlker Oğulcan SAYIN (iosayin) wants to merge 1 commit into
microsoft:mainfrom
iosayin:fix/preserve-mailto-tel-links

Conversation

@iosayin

Copy link
Copy Markdown

Resolves #2644

Summary of Changes

  • Added mailto and tel to allowed schemes in _CustomMarkdownify.convert_a.
  • Preserved their original URI strings without path manipulation.
  • Added comprehensive unit test covering both mailto: and tel: link markdown conversions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Community review, so it does not clear the merge gate. I checked out the branch and ran it.

What I ran (packages/markitdown, Python 3.13 venv, upstream main 4cc9fa1 as base):

  • tests/test_html.py and tests/test_docx.py on this branch: 135 passed, 1 skipped.
  • A small probe converting <a href="...">link</a> through MarkItDown().convert_stream(..., ".html") on main and on this branch.

The basic case works: mailto:team@example.com and tel:+1-555-0100 now come out as [link](...) where main drops them to bare text. javascript: and sms: still collapse to text.

The problem is the if scheme in ["mailto", "tel"]: pass branch. It skips the path escaping completely, and the escaping is what keeps the output a valid Markdown link. From the probe:

  • tel:+1 555 0100 becomes [link](tel:+1 555 0100)
  • mailto:a b@example.com becomes [link](mailto:a b@example.com)

I rendered both with markdown-it and they come out as literal text, not links. A phone number written with spaces is a plausible href. For comparison #2645 escapes the path and gives tel:+1%20555%200100, which renders as a link (the PR also adds a test for the Word hyperlink path).

Smaller notes:

  • MAILTO: keeps its case on this branch ([link](MAILTO:team@example.com)), while #2645 normalizes it to mailto:. Harmless.
  • The new test only covers two clean addresses, so it would not catch the space case. A parametrized case with a space in a tel: href would.
  • A raw space in the query (?subject=Weekly report) also stays raw, as it does on #2645 and for http today.

Overlap: #2645 fixes the same thing. Suggest the maintainers pick one. I will leave a note there too.

I did not test other converters that use _CustomMarkdownify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mailto: and tel: links are converted to plain text

2 participants