showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.26k stars 1.56k forks source link

Error: sub-extension 0: property "type" must be a string, but undefined given #777

Open BlackGoku36 opened 4 years ago

BlackGoku36 commented 4 years ago

Trying to run from command line:

showdown makehtml -e ~/path/to/ext.js -i lala.md -o export.html

Getting error:

Enabling option ghCodeBlocks
Enabling option encodeEmails
Loading extensions
Could not load extension  /path/to/ext.js. Reason:
ERROR: Error in /path/to/ext.js extension-> sub-extension 0: property "type" must be a string, but undefined given
Run 'showdown <command> -h' for help

Code:

showdown = require('showdown');

showdown.extension('ext', function () {
    var matches = [];
    return [{
        type: "lang",
        regex: /!>([^]+?)<!/gi,
        replace: function (s, match) {
            matches.push(match);
            var n = matches.length - 1;
            return '%PLACEHOLDER' + n + '%';
        }
    },
    {
        type: 'output',
        filter: function (text) {
            for (var i = 0; i < matches.length; ++i) {
                var pat = '<p>%PLACEHOLDER' + i + '% *<\/p>';
                text = text.replace(new RegExp(pat, 'gi'), '<p class="ds">' + matches[i] + '</p>');
            }
            //reset array
            matches = [];
            return text;
        }
    }
    ]
});