Something like shortcodes for Discourse?

I recently discovered MDX, which allows you embed dynamic components in markdown using JSX.

I’m wondering how difficult it would be to do something similar in Discourse posts.

I want users to be able to start games in the forum by embedding shortcode-like snippets in posts:

Here's today's game. Let's see who can get the best score.

[game type="whatever" prop2="something" expires="midnight"]

The tag would be replaced with a dynamic JavaScript game. Scores would be saved in the database (or sent into Firebase from the backend).

Does anyone know if something like this exists or if there is an open-source plugin that might provide some ideas on how to implement it?

3 Likes

There is a bbcode plugin and there is the Topic Template Placeholder Text theme component that offer a start, but you’ll need to understand a fair amount about Beginner’s Guide to Creating Discourse Plugins Part 1: Creating a basic plugin

3 Likes

Thanks, I found a calendar plugin that looks like it might have some examples of what I’m looking for (custom markdown tag and some backend controllers). I also found a markdown extensions guide, but haven’t read it closely yet.

If I can load an iframe in a modal, and communicate scores using postMessage, that might allow the games to be embedded in MDX pages on the site too. I’m going to experiment with it.

2 Likes