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
5 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:

2 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.

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
6 Likes

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

5 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