Custom css class based on regex

I am adding special links to a Rails app that uses EasyMDE.

The special links are in format


which means that they are included in [[ ]] tags.

Unfortunately the html code becomes like

<pre class=" CodeMirror-line "role="presentation">
  <span role="presentation" style="padding-right: 0.1px;">
      this is 
          <span class="cm-formatting cm-formatting-link cm-link">[</span>
          <span class="cm-link">[[Darth Vader](http://localhost:3000/post/0fd5387c1e37)</span>
          <span class="cm-formatting cm-formatting-link cm-link">]</span>] </span>

The last ] does not have formatting and the cm-link class.
This seems simple but I have no idea how to solve.
Any help will be appreciated !

Is this using the Markdown mode? Or a custom mode?

I don’t know tbh. It’s used by easyMDE GitHub - Ionaru/easy-markdown-editor: EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking..
I guess that’s markdown mode, that’s what the plugin is about.