-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown: turn plain URLs into links #2884
Conversation
Current dependencies on/for this PR:
This stack of pull requests is managed by Graphite. |
bf6380d
to
165afaa
Compare
165afaa
to
ffed23d
Compare
@@ -0,0 +1,23 @@ | |||
import findAndReplace from "mdast-util-find-and-replace" | |||
|
|||
export const urlRegex = /https?:\/\/([\w-]+\.)+[\w-]+(\/[\w\- .\+/?:%&=~#]*)?/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, now that I think of it, including .?:
can be annoying in cases like Learn more at https://ourworldindata.com/poverty.
.
I know that some other sites do something like "match .?:
unless they are at the very end of the URL", which seems sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I took this opportunity to also make sure we match urls with unicode word characters in the path.
AFAIK to properly match this with a regex you need to use negative lookbehind assertions and they are not supported in Safari before 16.4 which came out in Spring this year so I instead handle trailing punctuation characters in the replacement function.
01111b6
to
3e3744f
Compare
c4ea834
to
d8387dc
Compare
Merge activity
|
531cc39
to
3863877
Compare
d8387dc
to
944d5b2
Compare
By default, plain link like https://domain.com are not shown as links in markdown (see commonmark spec) and instead have to be written in the
[text](https://domain.com)
style.This PR adds autolinking to plain links. This is done in two different way
In theory it should be possible to use the remark plugin in both cases, but navigating the set of interdependent libraries at the state two years ago is a pain and so I went for the two bespoke versions. When we upgrade our setup to be ESM everywhere we can upgrade to the latest versions of the unified, react-remark et al libraries and try again to use the same code in both cases.