# Custom BBCode Help/Advice

**URL:** https://meta.discourse.org/t/custom-bbcode-help-advice/84005
**Category:** Development
**Created:** [March 28, 2018, 12:03am UTC](https://meta.discourse.org/t/custom-bbcode-help-advice/84005 "2018-03-28T00:03:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ellibereth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ellibereth/32/202896_2.png) [@Ellibereth](https://meta.discourse.org/u/Ellibereth)
#### Post date: [March 28, 2018, 12:03am UTC](https://meta.discourse.org/t/custom-bbcode-help-advice/84005/1 "2018-03-28T00:03:12Z")

</div>

UPDATE: Figured it out!

* * *

I’m trying to make make a plugin that makes a custom bbcode that maps

`[vote]name[/vote]`  
to  
` <p><span class="highlight"><b>VOTE:name</b></span></p>`

I’ve been reading the stuff in [this topic](https://meta.discourse.org/t/developers-guide-to-markdown-extensions/66023) along with going through the various bbcode plugin repos that exist, and If I’m understanding the examples correctly the only relevant nontrivial places I have to change would be the stuff after wrap here

```
ruler.push('vote',{
    tag: 'vote',
    wrap: 
  });

```

and the stuff in square brackets here:

`replaceBBCode("vote", contents => [].concat(contents));`

I’ve tried a few things but none of them have worked as intended. I’d appreciate if anyone could help with this/point me towards what documentation/examples I’m missing and should read to make this and future similar things easier. Sorry if this is fairly trivial - I’m new to this.

Thanks.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 2, 2018, 4:07am UTC](https://meta.discourse.org/t/custom-bbcode-help-advice/84005/2 "2018-04-02T04:07:38Z")

</div>

> [@Ellibereth](#):
>
> UPDATE: Figured it out!

Would you care to share the result here? Having a overview of what wasn’t obvious to you would be nice!

---

<div class="post-metadata">

### Author: ![Ellibereth](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ellibereth/32/202896_2.png) [@Ellibereth](https://meta.discourse.org/u/Ellibereth)
#### Post date: [April 4, 2018, 5:04am UTC](https://meta.discourse.org/t/custom-bbcode-help-advice/84005/3 "2018-04-04T05:04:24Z")

</div>

```plaintext
    tag: 'vote',
    replace: (state, tagInfo, content) => {
      let token;
      token = state.push('span_open', 'span', 1);
      token.attrs = [['class', 'vote']];
      token = state.push('text', '', 0);
      token.content = 'VOTE:' + content;
      token = state.push('span_close', 'span', -1);
      return true;
    },
  });

```

Basically did this and defined a new vote class that was the same as highlight’s but also with bold.  
I tried a lot of silly thing without tokens and without defining the new class at first but it became clearer after looking at some of the more complicated wrap examples, though there was still some trial and error for notation.
