Plugin or theme component for post editor modification?

Honestly, I have no idea where to post this so feel free to move it if this isn’t the right category.

Recently I’ve been interested in improving the user experience in Discourse for adding ruby tags for text in the post editor. For those that don’t know, this tag can be used when writing Japanese text to convey the “reading” along with the text, such as changing 日本語 to ほん. However, many people even in our Japanese learning community don’t know this exists or don’t bother using it because it can be tedious writing it out for long phrases or sentences. (That one word example was generated from <ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby>.)

For that reason, I want to add an option in the post editor menu to act very similarly to the hyperlink option. It would still have two inputs, but they would be used to separate the main text and the reading instead of the link name and URL. It wouldn’t interact with the server at all since it would just insert vanilla (Discourse-supported) HTML into the editor. It’s likely that I’d want to do a little bit of text parsing to allow users to write long strings of text and add the ruby tags all at once instead of having to do it one character at a time.

So to the question, would this best be done as a theme component, a plugin, or something else entirely? Also, would there be a way to do this where I wouldn’t have to worry about the component/plugin/whatever breaking when core Discourse changes something about the editor? I’m pretty sure the Discourse install I’d want to get this added to is hosted by Discourse, so it would have to be compatible with that type of installation. I still have to check with the admins of that site, but I don’t think I’ll have any issue getting them to install it once it’s ready (and obviously I’ll check with them first after I get advice from here).

Any help and advice would be appreciated!

5 Likes

Theme component is the way to go here! No need to change core and we already have the hooks to add this.

Have a look at Composer Help Button (which is currently a plugin but could easily be converted to a theme component)

2 Likes

Thanks, I’ll take a look. Just to make sure, theme components can be added even by a hosted site? I just want to make sure the admins of the site I use could actually install this before I spend time on it.

Yes, theme components can be installed by administrators on a hosted site. Generic theme documentation can be found here.

Here’s an example of one theme component which adds a toolbar button to the composer:

https://github.com/discourse/DiscoTOC/blob/master/common/header.html#L373-L393

4 Likes