How to create a showdown.js markdown extension

后端 未结 2 1925
孤城傲影
孤城傲影 2021-01-14 17:35

Using the following code, I get working output:


  
    

        
相关标签:
2条回答
  • 2021-01-14 17:51

    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.

    0 讨论(0)
  • 2021-01-14 18:11

    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;
          }
        }
      ]
    });
    
    0 讨论(0)
提交回复
热议问题