-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathmarkdown.js
More file actions
30 lines (27 loc) · 903 Bytes
/
markdown.js
File metadata and controls
30 lines (27 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const pify = require('pify')
const Remark = require('remark')
const RemarkExternalLinks = require('remark-external-links')
const RemarkHtml = require('remark-html')
const RemarkMath = require('remark-math')
const RemarkHtmlKatex = require('remark-html-katex')
const converters = {
markdown: Remark()
.use(RemarkHtml, { sanitize: true })
.use(RemarkExternalLinks, { rel: false }),
math: Remark()
.use(RemarkMath)
.use(RemarkHtmlKatex)
.use(RemarkHtml, { sanitize: require('./markdown-sanitize.json') })
}
Object.keys(converters).forEach((key) => {
const converter = converters[key]
converters[key] = pify(converter.process.bind(converter))
})
const convert = async (md, type) => {
const converter = converters[type]
if (!converter) {
throw new Error('no converter for type ' + type)
}
return converter(md).then((result) => result.contents)
}
export { convert }