Custom BBCode Help/Advice


#1

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 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.


(Kane York) #2

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


#3
    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.