最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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=".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);

...

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/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);

...

Share Improve this question edited Jan 8, 2017 at 22:50 Waylan 42.9k14 gold badges91 silver badges117 bronze badges asked Jan 6, 2017 at 8:27 PhilPhil 1511 silver badge6 bronze badges 1
  • as the message states you should be able to access it like this: window.markdownitFootnote – Joel Harkes Commented Jan 6, 2017 at 8:39
Add a ment  | 

1 Answer 1

Reset to default 8

I just found the solution. Use:

<script type="text/javascript">
var md = window.markdownit().use(markdownitFootnote);
</script>
发布评论

评论列表(0)

  1. 暂无评论