Automatically linking up citations to suttas on D&D

This is actually the easier part (already done), see regex rules here:

This has been implemented for DN, MN, Dhp and Iti (this will work for all existing and new IDs inside posts and it needs browser refresh). Here are some of the samples for valid an invalid sutta IDs, automatically linkified to SC:

DN MN Dhp Iti
DN0 MN0 DHP0 ITI0
Dn0 Mn0 Dhp0 Iti0
dn0 mn0 dhp0 iti0
DN1 MN1 DHP1 ITI1
Dn1 Mn1 Dhp1 Iti1
dn1 mn1 dhp1 iti1
DN 2 MN 2 DHP 2 ITI 2
Dn 2 Mn 2 Dhp 2 Iti 2
dn 2 mn 2 dhp 2 iti 2
DN 34 MN 152 DHP 423 ITI 112
Dn 34 Mn 152 Dhp 423 Iti 112
dn34 mn152 dhp423 iti112
DN35 MN153 DHP424 ITI113
Dn 35 Mn 153 Dhp 424 Iti 113
dn 35 mn 153 dhp 424 iti 113

But there are also several issues with the Linkify Words - theme-component - Discourse Meta component:

  • regex OR operator (|) is reserved as a separator for multiple rules input tool and this is currently still hardcoded in core, which means all compact regex rules must be expanded into multiple rules (this is doable, but harder to maintain)
  • the component allows for mapping spaces and non-break spaces, but not all whitespaces using \s (but this should cover most cases anyway)
  • the crucial showstopper is that the component delimits words at word boundary, which includes dot (.). This makes it impossible to linkify AN, SN, Snp, Thag, Thig and Ud.

Fixing this shouldn’t be too hard, as this component is pure javascript. Best approach would be to create a fork from GitHub - discourse/discourse-linkify-words: theme to auto linkify urls in discourse and add this functionality:

  • add configurable word boundary list instead of hardcoded ones
  • use a substitute character for | (configurable, with default ¦) for rules input and replace it to | in code

Bhante @snowbird, what do you think?

2 Likes