Repository navigation
fix(markdown): end a bare URL where the sentence ends, not at the next space - #815
Merged
Merged
Conversation
…t space GFM links a bare URL up to the next whitespace. Chinese prose has no space before its punctuation, so `见 https://x.com/a。下一句` swallowed the rest of the sentence into the link target; worse, `**https://x.com/a**(PRIVATE)` also swallowed the closing `**`, which broke the target and left the emphasis unclosed — the asterisks rendered literally and the whole sentence was painted as a link. Two changes in the shared parser (desktop, mobile and every preview): - GFM's autolink *tokenizer* is turned off. It runs before inline syntax is resolved, so whatever followed the URL — emphasis markers, code spans, punctuation — became part of the link and never came back. The node-scoped pass remark-gfm keeps runs after emphasis and link resolution, links the same URLs inside one text node, and cannot reach outside it. - That pass sees text nodes, so the plugin cuts them at both ends of the URL: after it at whitespace or full-width punctuation, and before it where GFM is stricter than the tokenizer it replaces (`网页https://…` is how Chinese is written, no space). Known limit, no occurrence in ~3000 recorded messages: a bare URL containing inline syntax (a literal backtick, `__`) is no longer linked — the tokenizer used to shield those characters and the pass cannot see them. Verified against the recorded corpus: every changed parse cleans a target, no URL stops being a link, and the visible text changes only where literal `**` became real emphasis.
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.
Fixes the mobile/desktop rendering of a reply like:
which rendered as one link-coloured blob whose target was
https://…articles**(PRIVATE,huichen`` (tapping it 404s), with the**and thebackticks printed literally.
Root cause
GFM links a bare URL up to the next whitespace and only trims trailing ASCII
punctuation — a rule for Latin prose. In Chinese/Japanese the punctuation comes
straight after the word, so:
见 https://x.com/a。下一句put。下一句inside the target (18 of the 187recorded messages with URLs change);
**https://x.com/a**(PRIVATE)also ate the closing**. The emphasis couldthen never close, so the asterisks showed up as literal text and everything up
to the next space was painted as a link.
The swallowing happens in GFM's autolink tokenizer, which runs before inline
syntax is resolved — emphasis markers, code spans and punctuation that follow the
URL become part of the link and never come back.
Change (
packages/markdown, shared by desktop, mobile and previews)protocolAutolink/wwwAutolink/emailAutolink) is turned off.remark-gfm's node-scoped pass stays: it runs after emphasis and link
resolution, links the same URLs inside one text node, and therefore cannot
reach outside it.
**url**(…)now parses as bold + link + text + code.the URL: after it at whitespace or full-width punctuation, and before it where
GFM is stricter than the tokenizer it replaces (
网页https://…has no spacein Chinese). Registration order matters and is documented — it has to precede
remark-gfm.Verification
agent.db),old vs new parse: 18 link targets cleaned, no URL stops being linked, and
the visible text changes only where literal
**became real emphasis(
text.replace(/\*\*/g,"")equality)..use(remarkAutolinkBoundary)removed, 6 of the newtests fail.
mobile: 1906 tests / 125 suites,tsc --noEmit,eslint— green.desktop: 275 markdown tests (incl. a new streaming fixture that pins thesecond processor chain),
tsc --noEmit,eslint,stylelint— green.packages/markdown:tsc --noEmit; streaming prefix-equality fixtures extendedwith the reported line, so the streaming projector and the canonical parser
stay identical at every prefix.
Known limits (no occurrence in ~3000 recorded messages)
__,<) is nolonger linked: the old tokenizer shielded those characters, the node-scoped
pass cannot see them. Markdown links (
[x](url)) are unaffected.…/herita-project在做的…)keeps its glued tail — Han characters are legal URL characters
(
zh.wikipedia.org/wiki/中文), so the tail is not cut at a character boundary.This is unchanged from before.