Change to how lists of tags are separated

AI-generated summary

Discourse has changed how tag separators are implemented, moving from CSS pseudo-elements to proper HTML for better accessibility and functionality. This change allows for easier customization of tag separators using JavaScript value transformers. For example, to remove commas entirely or replace them with pipes. awesomerobot explains the process and provides code examples. Some users reported issues with duplicate commas, which Arkshine attributed to the Multilingual plugin using the old CSS method. jesus2099 and Olle11 discussed the plugin’s impact on language settings and tag separators. nolo noted that separators are hidden by default for box or bullet tag styles but may still appear on mobile due to specific CSS declarations.

Lists of tags on topics in Discourse are separated by commas by default. This isn’t changing, but how it’s implemented and how you can change it has:

Previously we used a CSS pseudo element to add the commas, which isn’t ideal because the content isn’t technically available as part of the document — screenreaders can’t access it, they’re not selectable, web crawlers can’t see them…

This change merged today moves the tag separators to proper HTML: FEATURE: customizable tag separator with value transformer in proper HTML by awesomerobot · Pull Request #31674 · discourse/discourse · GitHub

For most sites this won’t change anything obvious, but if you previously removed or changed the tag separator you’ll have to use a value transformer instead of CSS.

This is a fairly straightforward process with JS, for example if you want to remove the comma entirely:

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  api.registerValueTransformer("tag-separator", () => "");
});

or if you want to use a pipe separator

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => {
  api.registerValueTransformer("tag-separator", () => "|");
});

coupled with a little CSS:

.discourse-tags__tag-separator {
  margin-inline: 0.25em;
}

Let us know if you encounter any issues with this change!

We are seeing duplicate commas:

Probably one comes from the new HTML code and the other comes from the custom theme CSS (old code).

The former (HTML) is indeed selectable, while the latter (CSS) is not.

Following this change, all custom themes should be fixed, apparently?

From what I see on your forum, it’s related to Multilingual Plugin 🌐 .

It still uses the old way with CSS pseudo elements.
This CSS could be removed.

Wow! Thanks for your quick diagnosis!

Hi Arkshine,

I wanted to try and installed the Multilingual plugin and when I tried it the double commas came up. When I try to deactivate the plugin my language becomes English (and hence the double commas dissapear). When I activate it again it becomes my language again.

Do you think I should remove the plugin if I don’t really need it for now, and if so why is the language now in English? The ‘default locale’ is blank when deactivating the multilingual plugin.

If the plugin does not effect the website in any way maybe I can keep it and try to remove the double commas.

Best regards
Olle

Edit: I fixed it by removing the plugin

It seems that the separator is hidden by default when the tag style is box or bullet:

.discourse-tags .box + .discourse-tags__tag-separator, 
.discourse-tags .bullet + .discourse-tags__tag-separator {
  display: none;

However, this is overwritten on the mobile list by a more specific declaration. So on mobile the separator shows: