Reputation: 185
I have been fiddling for ages with custom handlebars helpers such as:
Handlebars.registerHelper('markdowner', function (input) {
var converter = new Showdown.converter({ extensions: 'tables' });
return converter.makeHtml(input);
});
yet i get thrown:
Uncaught TypeError: Cannot call method 'replace' of undefined
from showdown.js when trying to call the helper.
I have also tried redefining the converter when Meteor loads, but it is ignored - any ideas on how to get showdown convertors/extensions running would be greatly appreciated.
Upvotes: 0
Views: 575
Reputation: 9193
You need to provide the extensions as an array and also you need to refer to that extension as 'table' rather than 'tables' (based on the table.js file within the Showdown gitgub repository as below).
var converter = new Showdown.converter({ extensions: ['table'] });
I've just implemented this myself after having the same error you had.
When the extension is loaded you should be able to run this from the console and have it return something.
$ window.Showdown.extensions.table
To test it's working from the console try this:
new Showdown.converter({extensions:['table']}).makeHtml("| A | B | C | \n |-|-|").htmlSafe()
should output
SafeString {string: "<table>↵<thead>↵<tr>↵<th id="a" style="text-align:…C </th>↵</tr>↵</thead>↵↵<tbody>↵</tbody>↵</table>", toString: function}
References
Upvotes: 2