How to create a showdown.js markdown extension

六月ゝ 毕业季﹏ 提交于 2019-12-01 09:24:54
Daveee

In your last block you have a comma after 'lang', followed immediately with a function. This is not valid json.

EDIT

It appears that the readme was incorrect. I had to to pass an array with the string 'twitter'.

var converter = new Showdown.converter({extensions: ['twitter']});
converter.makeHtml('whatever @meandave2020');
// output "<p>whatever <a href="http://twitter.com/meandave2020">@meandave2020</a></p>"

I submitted a pull request to update this.

The way we write extensions has changed, I found some help with the following filter example : http://codepen.io/tivie/pen/eNqOzP

showdown.extension("example", function() {
  'use strict';
  return [
    {
      type: 'lang',
      filter: function(text, converter, options) {
        var mainRegex = new RegExp("(^[ \t]*:>[ \t]?.+\n(.+\n)*\n*)+", "gm");
        text = text.replace(mainRegex, function(match, content) {
          content = content.replace(/^([ \t]*):>([ \t])?/gm, "");
          var foo = converter.makeHtml(content);
          return '\n<blockquote class="foo">' + foo + '</blockquote>\n';
        });
        return text;
      }
    }
  ]
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!