Custom formatting for OSM tags in Discourse?

I was wondering, is there a possibility to add custom formatting to this Discourse instance?

What I wish for is ability to use two wiki-alike constructs:

  • {{Tag|artwork_type|sculpture}}
  • {{Key|artwork_type}}

which would in Discourse messages expand to:

respectively. I understand that diverting as little as possible from upstream is very desirable, but on the other hand, much of the discussion on Discourse is related to tagging, and it is very cumbersome and very error-prone to try to manually create links like that (even when using copy/paste generously). There are also almost impossible to re-read by the author and find right place in editing window while editing the message.

And I’ve noticed that by just doing low-effort artwork_type=sculpture is not only less readable, but leads to many misunderstandings and needless explaining, as not many users (read: almost nobody) will bother to open and search for those tags, fighting with sub-ideal wiki search functionality.
But when they’re made as links, and they’re just one click away, they’ll click them a lot more often and thus get information easily.

So adding such support would help enormously both people writing the messages mentioning wiki tags, and people reading (and replying) to those messages.


I’ve no idea how hard this would be to implement, but it’d be great! It could even support all (or a specific list of) wiki templates, and could probably render them via an API call to action=parse, reducing the amount of work done on the Discourse side and ensuring the formatting here and on the wiki stays the same.

@Firefishy I suspect this enters de plugin territory right?

Yes, likely requires a plugin. Not easy. Not something I’m going to work on, but happy if someone else wants to look further.

1 Like

Unfortunately, Discourse won’t display a “onebox” if you put the URL of a wiki or taginfo page about the tag on its own line, because neither site specifies the required meta tags. For the wiki, this would entail enabling the PageImages extension that comes with MediaWiki.

I’ve noticed that too @Minh_Nguyen, but don’t see how it is related to this thread? (which is about adding support for inline rendering of {{Tag|artwork_type|sculpture}} as artwork_type=sculpture)

(perhaps you intended to create separate thread for that request?)

I’ve done some digging, and it does not look very complicated (if one already has test instance of Discourse running, of course, which seems like vast majority of the work).

The closest and simplest I could find is this abbreviation plugin (~100 lines of code and CSS combined) which seems to find certain acronyms from (setting it implements), and adds HTML <abbr> tags around them for explanation.

Which seems even more complex than we would need here (we don’t even need that settings preference)

This main part of code seems to be just several lines of code culminating in simple RegEx:

much of the rest of the code seems like common-to-reuse boilerplate for this case.

And the RegEx itself should be simple too, e.g. this for JS:

text = text.replace(new RegExp('{{key\\|([^}]+)}}','gi'), '<A HREF="$1">$1</A>');
text = text.replace(new RegExp('{{tag\\|([^|]+)\\|([^}]+)}}','gi'), '<A HREF="$1">$1</A>=<A HREF="$1=$2">$2</A>');
other possible options

If one were to need more complex functionality, there is still relatively simple version of bbcode [which supports only bbcode color changes] at GitHub - discourse/discourse-bbcode-color: A Discourse Plugin to support BBCode color tags.

Or, if one were to want to start writing more complex plugin from scratch, there is GitHub - discourse/discourse-plugin-skeleton: Template for Discourse plugins

Actually it wasn’t quite a request – I started out suggesting a onebox as a temporary workaround for the lack of this formatting, but I had to edit the post because the oneboxen don’t even appear. Sorry for the confusion. I do think the PageImages extension (which enables Discourse’s onebox feature by coincidence) would be very nice to have, but that discussion belongs on the wiki for now.

@Firefishy As noted above, I did some research and it seems relatively easy to do - there is a plugin which does very similar thing. If one were to invest time to write such plugin, would it be included?

Hmmm, I am nervous about custom extensions. We have been bitten in the past with mediawiki.

Saying that, custom formatting for OSM tags would be nice. Maybe automatically linking tags to taginfo?

Depending on the complexity of the plugin and the likelihood of it potentially breaking things in future upgrades.

1 Like