Repository navigation
fix: don't linkify inside inline HTML markup tokens (link-patterns extra) - #771
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
The link-patterns extra checked only markdown link syntax and <http://> auto-links before replacing a match. A match inside any other inline HTML markup token that markdown2's own tokenizer recognizes - a tag (<span title="word">), a comment, a processing instruction, or a <word@example.com> style auto-link - was replaced anyway, inserting an anchor into an attribute value (invalid HTML) and destroying the email auto-link before _do_auto_links could see it. Exclude matches that fall inside _sorta_html_tokenize_re tokens, so prose is still linkified while markup and auto-links are left intact and _do_auto_links can produce the mailto link afterwards. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the
link-patternsextra enabled, a pattern matching inside an inline HTML markup token got replaced there — inserting an anchor into an attribute value and destroying<word@example.com>auto-links:LinkPatterns.runexcluded matches inside markdown link syntax and<http://…>auto-links (issues #385/#446 covered those), but not the other inline tokens markdown2's own tokenizer (_sorta_html_tokenize_re) classifies as markup: tags, comments, processing instructions, and<word@example.com>style auto-links — which_do_auto_linksprocesses after the extra runs, so the match split the token before the auto-linker ever saw it.This excludes matches that fall inside a
_sorta_html_tokenize_retoken. Prose still linkifies; matches inside an element's content still linkify; markup and auto-links are left intact for the later stages:Fixes #752.
Verification (system Python 3.13):
test/tm-cases/link_patterns_in_html_tags_issue752.{text,html,opts}covering all three symptoms plus prose/element-content controls: fails onmaster@6d0a518with the exact attribute-corruption diff, passes with this change.test/test.py: exit 0, no failures (pygments present, wavedrom/latex2mathml/emoji cases skipped as unavailable).