electron-markdown is a Node.js module to convert Markdown to HTML. It uses cmark-gfm for HTML generation, and a series of unified plugins to process the resulting HTML.
Supports Node.js v12 or higher.
npm install electron-markdown
electron-markdown exports a single function, which takes a Markdown string as its first argument and an options object as its second argument, and returns a Promise that resolves to the resulting HTML.
resultPromise = electronMarkdown(markdown[, options])
result: Promise<String>
- a Promise resolving to the resulting HTML if parsing and rendering succeedsmarkdown: String
- a string of Markdown to render to HTMLoptions: Object
runBefore
Array of [remark] plugins - Custom plugins to be run before the commonly used plugins.cmark
options to pass to cmark-gfm; will be deeply merged with the default optionshighlight
- Object of rehype-highlight options.
Default options:
{
cmark: {
footnotes: true,
extensions: {
table: true,
strikethrough: true,
autolink: true,
tagfilter: true
}
},
highlight: {
ignoreMissing: true,
aliases: {
plaintext: ['text'],
},
},
}
To disable an option or extension that is enabled by default, provide your own
options with a value of false
(or an extensions
object with the given
extension's value set to false
). Any options you provide will be merged into
the default options, with false
values overriding any default true
value.
const markdownToHtml = require('electron-markdown')
markdownToHtml(someMarkdown).then(
function (html) {
console.log(html)
},
function (err) {
console.error(err)
}
)