Labels as markdown

AI-generated summary

The discussion revolves around creating a markdown extension for labels in Discourse. trudat suggests adding a markdown syntax, [label style=default]My cool label[/label], to insert labels into posts. pfaffman believes it’s feasible to create a plugin for this feature, citing the pirate speak plugin as a potential basis.

trudat identifies the function to edit and proposes rewriting the regex to recognize the [label] tags and add the corresponding CSS class. However, pfaffman is uncertain about the implementation details.

cpradio recommends examining the formatting toolbar plugin, which demonstrates how to add a toolbar item and whitelist tags/classes, providing a more suitable starting point for the label markdown extension.

Labels are a great general purpose UI element, also pure css:

If there was a markdown extension for labels, they could be inserted into posts via the tool bar or markup:

[label style=default]My cool label[/label]

Any takers?

Should be relatively easy to create a plugin to do that.

If good old pirate speak still works, it’d be a good basis. I’m pretty sure that the plugin tutorial is out of date, but pirate-talk was updated relatively recently, so it might work.

3개의 좋아요

Sweet.

Looks like the function below is the one to edit. So if I rewrite the regex to recognize the tags [label] and [/label], replace those by <span class='cool_label'> and </span>; then add the css class in the customization tab; that should do it right? Anything else I need to do to ensure html tags get rendered?

function piratize (text) {
  return text.replace(/\b(am|are|is)\b/ig, "be")
             .replace(/ing\b/ig, "in'")
             .replace(/v/ig, "'");
}

Beats me. I think it should work, though.

I did go so far as to install the plugin and make sure it works. Real Soon Now, I’ll fix my DOI resolver plugin.

1개의 좋아요

Actually, it would be better to look at the formatting toolbar plugin, as it will show you how to add a toolbar item and how to whitelist tags/classes.

5개의 좋아요