Citation Link Up tool 🔧 to turn citations into links for a block of text

Inspired by this post, and in my ongoing efforts to learn coding, I created this tool to take a block of text and turn the citations into links:

If you want to past it into a post in the discussion forum here, select Markdown. If it is for a post on, select PHPbb.

There are some limitations at this point. You need to use the same abbreviations that are used on SuttaCentral. And of course if the citations are bad, then the links will be bad. It also doesn’t accommodate ranges.

So, if you look at the post that inspired me to make it, the Udana citations won’t work because it says “Udana” instead of “Ud”. And the Iti links won’t work because they are in the form of chapter and sutta rather than suttas 1–112.

Any feedback would be most welcome. It’s mostly a learning project for me, so I’d be interested in feature requests.


This is awesome.
This is awesome. So if I want to link to SN 2.12, and compare this with Snp 2.12, they’ll both work.

We should add this to Discourse! Can you turn your widget into a Discourse plugin?

Just to note, canonically URLs on SC are all lowercase. Uppercase works, but in the past it didn’t, so if you can convert to all-lowercase it’d be more robust.

1 Like

Thanks for the appreciation.

At the moment it is not really anything more than a regex search and replace. Accommodating the other two number formats for Iti and Ud will make it slightly more complex.


OK, I have the issue with the Iti and the Ud sorted. No matter what format those citations are in, it should give you a working link (assuming it is a valid citation)

4 posts were split to a new topic: Automatically linking up citations to suttas on D&D

A post was merged into an existing topic: Automatically linking up citations to suttas on D&D

I just added a preview for the html result so users can make sure all the links work. (I’m assuming that the other formats would produce the same preview)

Bhante @Sujato, I think this is stable enough that it’s ready to be added to the “SC Awesome” page if you think it will be helpful.

(small side note… it’s a bit more user friendly to link directly to the readme anchor on github pages for non github users, i.e.

Bhante, you can try these for size. The regex rules below will produce only valid SC links!

Use $2 for substitution and map each regex below to corresponding SC id:

  • \b(DN...)\b[DN $2]($2/en/sujato)
  • \b(Ud...)\b[Ud $2]($2/en/sujato)










This should be complete and accurate list of rules now (some tweaks were made and some missing chapters in Thag and Thig were added).

Also, there is an added option to use : as a separator for SN (for legacy purposes).

1 Like

Sorcery, I say! :man_mage:t2:

I’ll give it a try. Couple of things:

I’d recommend not including Sn as a possible citation for Saṁyutta Nikāya since it is a standard (if not outdated in a digital world) abbreviation for Sutta Nipāta. You would rarely see it for SN. In fact, I wouldn’t bother with Dn, Mn, or An either.

Is there a tool you used to create that? It’s amazing.


Here are a couple test cases, just to see what happens:

  • a long link with DN 1 inside
  • DN 1: The very first sutta
  • SN 1: a chapter
  • AN 1.10 is a sutta in a range
  • AN 1.1-10 is the range
  • References sometimes use colons like this: AN 10:5
  • References could occur inside code blocks MN 5 like this
  • lowercase AN is an actual word, though it shouldn’t be followed by numbers “in the wild”, though I might make an 3xample just to try!
  • What about italic: Thag 1.1 and bold: Ud 1.2?
  • And what about deleted Thig 1.1 text?
1 Like

Yes, if at all possible colons as well as periods should be acceptable as separators.

I think the very nature of code blocks is that nothing should touch them, eh? I believe that the default behaviour of the code being used ignores things inside of code blocks.

By work, you mean…?

Personally, I think it would be find to require a standard capitalization (e.g. DN, AN, Snp, Dhp). That might even give people the option of not having citations linked up automatically if they desired.

My idea here is simply to think of edge cases. What the behavior “should” be in these cases is up to y’all! But, fwiw, I agree that code block refs should probably be left unlinkafied

Ah, I got confused as to which thread we were in. :man_facepalming:t2: Yes, with the tool I wrote, things inside code blocks will get linked. That’s not good.

1 Like

For what its worth, those test cases should also apply to @musiko 's changes here on SuttaCentral Dungeons and Dragons Discuss and Discover :slight_smile:

Yes, several of these do break the linkup tool. I didn’t really consider people pasting in html text. I should probably just say that it’s unsupported/use at your own risk for linking up code. I think there might be too many edge cases to deal with.

Ranges are already unsupported. The link will be created for the first part of the range.

But the an 3example is bad and I will fix.


1 Like

Simply edit Sn out from (SN|Sn|sn)

It might not seem so at first glance but these are really simple regex rules (basically just matching numerical sequences 1…n).

The hard part was to find the ranges for each collection (I used sc-data/sc_bilara_data/html/pli/ms/sutta at master · suttacentral/sc-data · GitHub to extract the ranges) and then construct ranges by hand ([1-9] matches range 1…9, [1-9][0-9] matches 10…99 etc.) for the easier part.

1 Like

Right. I made that comment when I thought we were discussing the feature on the forum.


1 Like

Implementation on the forum is simplified due to the current constraints with using |, so the rule here (for the time being) is to simply match all case insensitive strings (which will also match dN 1).

1 Like

@Snowbird please replace all the rules in your tool. This should be the final version of the rules :grin:

Added support for legacy : notation for SN, AN, Ud and Snp.

Rules using : as a separator are not exact (i.e. they will map some non-existent notations to invalid links). Use $3.$4 for substitution and map each regex below to corresponding SC id:

  • \b(SN...)\b[SN $3.$4]($3.$4/en/sujato)
  • \b(AN...)\b[AN $3.$4]($3.$4/en/sujato)
  • \b(Ud...)\b[Ud $3.$4]($3.$4/en/sujato)
  • \b(Snp...)\b[Snp $3.$4]($3.$4/en/sujato)




1 Like

Thanks! I’ll give it a spin.

1 Like