feat: support disableAutolinkProtocols to opt out of GFM autolinks per protocol - #611
Open
sleitor wants to merge 1 commit into
Open
feat: support disableAutolinkProtocols to opt out of GFM autolinks per protocol#611sleitor wants to merge 1 commit into
sleitor wants to merge 1 commit into
Conversation
…r protocol Adds an optional disableAutolinkProtocols prop to <Streamdown> that lets consumers turn off GFM autolink-literal linking for specific URL protocols (e.g. mailto). Implemented as a remark plugin that runs after remark-gfm, identifying autolink-literal link nodes structurally (single text child reconstructing the URL) and unwrapping them to plain text when their protocol is disabled. Explicit markdown links ([text](url)) are left alone. Protocol names are case-insensitive and accept an optional trailing colon. The pipeline is unchanged when the prop is omitted. Closes vercel#607
Contributor
|
@sleitor is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Merged
4 tasks
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.
Closes #607.
What
Adds an optional
disableAutolinkProtocolsprop to<Streamdown>that disables GFM autolink-literal linking for specific URL protocols (e.g.mailto), as requested in #607.Before:
After (with
disableAutolinkProtocols={["mailto"]}):"mailto"and"mailto:"are equivalent).remark-gfm's autolink-literal extension are affected (bare emails, barehttp(s)/wwwURLs). Explicit markdown links ([text](mailto:...)) are left as links, since they're an intentional link, not an autolink.How
mdast-util-gfm-autolink-literaldoesn't tag the link nodes it creates, so a small remark plugin (packages/streamdown/lib/remark/disable-autolink-protocols.ts) identifies them structurally: a link with exactly onetextchild whose value reconstructs the node'surl(accounting for themailto:prefix GFM adds to bare emails). Matching nodes are unwrapped back to their text children. The plugin runs immediately afterremark-gfmin the pipeline (before the CJK/math plugin slots), matching the existing "before/after gfm" plugin ordering convention.It's exposed via the standard unified
[plugin, options]tuple form rather than a plugin-factory closure — Streamdown's internalMarkdownprocessor cache keys processors by plugin name +JSON.stringify(options), and a factory returning a fresh anonymous closure per call would always serialize to the same cache key, causing differentdisableAutolinkProtocolsconfigurations to silently reuse a stale cached processor (caught this via a failing test while developing).Testing
Added
packages/streamdown/__tests__/disable-autolink-protocols.test.tsxcovering:mailtois disabled[text](mailto:...)links stay linkedmailtois disabled"mailto:"formhttpsleavesmailtoautolinks untouched<Streamdown disableAutolinkProtocols>prop itselfpnpm -F streamdown exec vitest runpasses except for 5 pre-existing failures onmainunrelated to this change (image-placeholder / incomplete-image-sanitize tests, verified failing identically on a cleanupstream/maincheckout before my changes).Also updated
apps/website/content/docs/configuration.mdxwith the new prop, and added a changeset.