Automatic package links

In the Julia Zulip server, we have something called “linkifiers” which basically just use a regex to detect specific patterns in text, and turn them into links automatically. The main thing we use this for is to turn strings like “DifferentialEquations.jl” into an automatic link pointing to the JuliaHub page for DifferentialEquations: https://juliahub.com/ui/Packages/General/DifferentialEquations, which should work for any package on the general registry. (previously, we did a Github search, but we switched to JuliaHub around a month ago and it’s been mostly good!)

I find this feature quite nice and convenient, and learned recently that it’s actually also available on recent versions of Discourse as an built-in feature: Watched Words Reference Guide - admins - Discourse Meta and also for as an extension: Linkify Words - theme-component - Discourse Meta

Is this something people would be interested in having on Discourse? I quite like it in Zulip, so maybe if there’s enough interest, the admins here on Discourse could enable it?

Here’s a little poll if people want to weigh in that way:

  • I’d like this feature as described
  • I don’t want this specific implementation, but want something similar
  • I don’t want this feature at all
  • I don’t care
0 voters
6 Likes

I think this is a great idea! As a hosted instance, we don’t have regexes enabled on our watched words, but the theme component seems to work.

I see the Zulip has the following regexes, which I think we could just replicate here:

3 Likes

people voting for “I don’t want this specific implementation, but want something similar”, it’d be helpful to comment on what that similar thing you want is. Sorry, I should have mentioned in the original post.

1 Like

Thanks everyone for your input! Looks like we have a solid majority in favor, let’s try it out. Here’s what I’ve implemented (note that you may need to refresh to get the links):

This is a Julia issue: julia#265
These are Julia commits: julia@7327a8f, julia@72cd63ce28c50c8c72e009df03dfec608802450e
This is a package issue: JuliaStats/Distributions.jl#123
This is a registered package info page on JuliaHub: Distributions.jl
This is a GitHub package link: JuliaStats/Distributions.jl

If you see anything awry or have other suggestions, please make your voice known!

@Mason, just FYI, I added \bs to the beginning of these regexes, which isn’t how it’s configured on Zulip. It may help reduce some false positives, like someone writing path/to/src/SubModule/SubModule.jl without ``s.

I wonder if and/or how we could display these rules. Unlike Zulip, by default Discourse doesn’t display these to users (I don’t think). Anyhow, these are the rules as of right now (the component doesn’t support named groups):

/\b[jJ]ulia\#([0-9]+)/, https://github.com/JuliaLang/julia/issues/$1
/\bjulia@([0-9a-f]{4,40})/, https://github.com/JuliaLang/julia/commit/$1
/\b([a-zA-Z0-9_-]+)/([a-zA-Z0-9._-]+)#([0-9]+)/, https://github.com/$1/$2/issues/$3
/\b([A-Z][a-zA-Z0-9_-]+)(.jl)/, https://juliahub.com/ui/Packages/$1
/\b([a-zA-Z0-9_-]+)/([a-zA-Z0-9._-]+.jl)/, https://github.com/$1/$2
7 Likes

Just saw this today on DifferentialEquations.jl, such a great feature, thanks for adding!

6 Likes

The . in .jl in the regexes should be escaped to not match any character. I noticed this while trying to opt out of this feature in some places (e.g. it looks a bit silly in Markdown headers IMO) but replacing . with e.g. ( U+2024 but looks like it is normalized to . on here) or some other dot looking character didn’t work. Is there another way to opt out?

You could use `…` to escape: PackageName.jl

Sure, but doesn’t look as nice and it isn’t code after all.

Hah, sure enough, whoops. Asdfjl used to be a package link!

In addition to Backticks.jl you can also Bold.jl or Italics.jl.

2 Likes

Both of those are links though. Edit: Ok, not after a force reload of the page…

Reload your browser. :slight_smile: I just added them.

I can also add any other HTML tags to opt out.

1 Like

Given the problems reported in other threads (e.g. Automatic package link pages have poor layout) with the juliahub generated READMEs / docs, i wonder if it’d be possible to make the linkifier send people directly to the source link rather than the juliahub-generated README, since there’s a better chance of the content being correctly displayed on the original hosting platform

4 Likes

That’s what I implemented here via GitHub pages Automatic package link pages have poor layout - #7 by jules

We could add that to the General Registry CI in principle

1 Like

oh very nice. I think if we just used this technique and then set up a github action to update it with new links from the general registry a couple times a day, that’d be pretty close to a perfect solution

I can make a PR

1 Like

This work is now done, we could linkify here on discourse using this format:

5 Likes

We’re now using these linkifiers on Zulip and it’s really nice. Thank you again for putting in the work to make these redirect pages @jules.

@mbauman what do you think? Can we switch the Discourse linkifiers to use these redirect pages from the General Registry? I think this solution is a much better fit than the JuliaHub pages because

  • it’s significantly faster to load
  • Authors intend for people to visit their repos, and they have control over those repos, unlike the JuliaHub pages (i.e. if a problem comes up with their presentation, they know and they can change it), so it feels like a disservice to send people somewhere that they have no control over.
  • it gives more immediate access to things like issues / pull requests / giving stars
  • Most authors don’t check the JuliaHub pages and don’t know if auto-generated pages screwed up their docs or their README (this has happened to me before and was quite aggravating, especially because after I discovered it, there was no way to fix it other than switch from using Org to Markdown for my README.)
  • The General Registry 404 fallback page is significantly more helpful for finding non-registered packages, or dealing with misspelt package names
11 Likes