You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
const MarkdownIt = require('markdown-it');
|
|
|
|
// For math: $a\times b\eq 10$
|
|
// Specific image size: ![image](image.png =100x100)
|
|
const Imsize = require('markdown-it-imsize');
|
|
/* Footnote support.
|
|
Here is a footnote reference,[^1] and another.[^longnote]
|
|
|
|
[^1]: Here is the footnote.
|
|
|
|
[^longnote]: Here's one with multiple blocks.
|
|
|
|
Subsequent paragraphs are indented to show that they
|
|
belong to the previous footnote.
|
|
*/
|
|
const Footnote = require('markdown-it-footnote');
|
|
// ==Highlight==
|
|
const Mark = require('markdown-it-mark');
|
|
const TOC = require('markdown-it-table-of-contents');
|
|
const Anchor = require('markdown-it-anchor');
|
|
// @[url](videourl)
|
|
// @[youtube](https://youtube.com/watch?v=xxx)
|
|
// @[pdf](https://foo.com/bar.pdf)
|
|
const Media = require('./markdown-it-media');
|
|
const Katex = require('./markdown-it-katex');
|
|
|
|
class Markdown extends MarkdownIt {
|
|
constructor() {
|
|
super({
|
|
linkify: true,
|
|
});
|
|
this.linkify.tlds('.py', false);
|
|
this.use(Media);
|
|
this.use(Imsize);
|
|
this.use(Footnote);
|
|
this.use(Mark);
|
|
this.use(Anchor);
|
|
this.use(TOC);
|
|
this.use(Katex);
|
|
}
|
|
}
|
|
|
|
const md = new Markdown();
|
|
|
|
function plugin(func, ...args) {
|
|
md.use(func, ...args);
|
|
}
|
|
|
|
function render(text, html = false) {
|
|
md.set({ html: !!html });
|
|
return md.render(text);
|
|
}
|
|
|
|
function renderInline(text, html = false) {
|
|
md.set({ html: !!html });
|
|
return md.renderInline(text);
|
|
}
|
|
|
|
// eslint-disable-next-line no-multi-assign
|
|
global.Hydro.lib.markdown = module.exports = {
|
|
md, plugin, render, renderInline,
|
|
};
|