Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a Markdown-it plugin without Node or require.js

I am trying to use the markdown-it-footnote extension for the markdown-it JS parser.

The readme gives an example of how to install it when using node.js:

var md = require('markdown-it')()
            .use(require('markdown-it-footnote'));

md.render(/*...*/) // See examples above

However I am not using node.js (and have never done so far). How can I embed the extension directly into the HTML-document?

I use the markdown-it-parser as follows:

<script type="text/javascript" src="https://cdn.jsdelivr.net/markdown-it/8.2.2/markdown-it.min.js"></script>
<script type="text/javascript">
var md = window.markdownit();
md.render(...);
</script>

The markdown-it-footnote-readme also states:

If you load script directly into the page, without package system, module will add itself globally as window.markdownitFootnote.

I tried to use it in many ways but was not successful:

var md = window.markdownit();
md = window.markdownitFootnote();

or

var md = window.markdownit().markdownitFootnote;

or

var md = window.markdownit(window.markdownitFootnote);

...

like image 870
Phil Avatar asked Jan 06 '17 08:01

Phil


1 Answers

I just found the solution. Use:

<script type="text/javascript">
var md = window.markdownit().use(markdownitFootnote);
</script>
like image 191
Phil Avatar answered Oct 13 '22 02:10

Phil