VersionTag Plugin no longer works; implementing MarkdownIt-API Calls seems not to work

Hi folks!

after my plugin stopped working I tried to adapt it to the new API but I didn’t succeed. Here is my code:

'discourse-versiontag/assets/javascripts/lib/discourse-markdown/versiontag.js.es6'
import { registerOption } from 'pretty-text/pretty-text';

registerOption((siteSettings, opts) => {
  opts.features.versiontag = !!siteSettings.versiontag_plugin_enabled;
});

function replaceVersionTag(text) {
  text = text || "";
  while (text !== (text = text.replace(/^\_VERSION\:(\d|\.|x)+/mg, function (match, p1) {
    var ver = match.split(':')[1];
    return "<div id=\"my_version\" title=\"supported Version\"><img src=\"/uploads/default/original/2X/c/cb3ca9fec2e0d595125432e2d5df26dd47f6dcce.png\" alt=\"Version "+ver+"\" />"+ver+"</div>";
  })));
  return text;
}

export function setup(helper) {
  helper.whiteList([ 'div[id=my_version]', 'div[title=*]' ]);

  if (helper.markdownIt) {
    helper.registerPlugin(md => {
      const ruler = md.inline.bbcode.ruler;

      ruler.push('versiontag', {
        tag: 'versiontag',
        wrap: function(startToken, endToken, tagInfo){
          startToken.type = 'div_open';
          startToken.tag = 'div';
          startToken.attrs = [['id', 'my_version'], ['title', 'supported Version']];
          startToken.content = '<img src="/uploads/default/original/2X/c/cb3ca9fec2e0d595125432e2d5df26dd47f6dcce.png" alt="Version ' + tagInfo.attrs._default + '" />' + tagInfo.attrs._default;
          startToken.nesting = 1;

          endToken.type = 'div_close';
          endToken.tag = 'div';
          endToken.nesting = -1;
          endToken.content = '';
        }
      });

    });
  } else {
    helper.addPreProcessor(text => replaceVersionTag(text));
  }
}

Could you point me to the right direction how to get it working again?

What this Plugin does

In an article I just can write:

_VERSION:X.y

and this is printed as CSS-styled Tag with a graphic and the Version.

1 Like