質問

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.

役に立ちましたか?

解決

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

  1. table.js - https://raw.githubusercontent.com/coreyti/showdown/master/src/extensions/table.js
  2. I found the array reference here: http://www.sluse.com/view/20863978
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top