# Labels as markdown

**URL:** https://meta.discourse.org/t/labels-as-markdown/60287
**Category:** Feature
**Created:** [2017 年 4 月 1 日午後 4:29 UTC](https://meta.discourse.org/t/labels-as-markdown/60287 "2017-04-01T16:29:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![trudat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trudat/32/104354_2.png) [@trudat](https://meta.discourse.org/u/trudat)
#### Post date: [2017 年 4 月 1 日午後 4:29 UTC](https://meta.discourse.org/t/labels-as-markdown/60287/1 "2017-04-01T16:29:11Z")

</div>

Labels are a great general purpose UI element, also pure css:  
 ![](https://global.discourse-cdn.com/meta/original/3X/7/7/77563281129323dbab46cf6126d0299bae937ed3.PNG)

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?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017 年 4 月 1 日午後 5:03 UTC](https://meta.discourse.org/t/labels-as-markdown/60287/2 "2017-04-01T17:03:48Z")

</div>

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

If good old [pirate speak](https://github.com/discourse/discourse-pirate-speak) still works, it’d be a good basis. I’m pretty sure that the [plugin tutorial](https://meta.discourse.org/t/plugin-tutorial-1-how-to-manipulate-the-text-in-the-composer/10925) is out of date, but pirate-talk was updated relatively recently, so it might work.

---

<div class="post-metadata">

### Author: ![trudat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trudat/32/104354_2.png) [@trudat](https://meta.discourse.org/u/trudat)
#### Post date: [2017 年 4 月 1 日午後 5:18 UTC](https://meta.discourse.org/t/labels-as-markdown/60287/3 "2017-04-01T17:18:17Z")

</div>

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, "'");
}

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2017 年 4 月 1 日午後 6:11 UTC](https://meta.discourse.org/t/labels-as-markdown/60287/4 "2017-04-01T18:11:31Z")

</div>

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](https://meta.discourse.org/t/new-plugin-doi-resolver/38920).

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2017 年 4 月 1 日午後 6:28 UTC](https://meta.discourse.org/t/labels-as-markdown/60287/5 "2017-04-01T18:28:36Z")

</div>

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.

> [@Formatting toolbar](https://meta.discourse.org/t/formatting-toolbar/40649):
>
> Add some formatting options to your discourse posts : center a text or an image, align to the right, justify, colors, underline, etc. It’s easy to use and it will provide some options to embellish your posts.
