A marked-backed Markdown->HTML generator. Supports extended attribute and front matter syntaxes, and provides hooks for modifying the generated HTML. Check out the full documentation for marked-it.
npm install marked-it-core
var markedIt = require("marked-it-core");
var result = markedIt.generate("#Welcome to marked-it\n{: #welcomeId .title}\n");
console.log(result.html.text);
/* Output:
<h1 id="welcomeId" class="title">Welcome to marked-it</h1>
*/
{
extensions: {},
markedOptions: {tables: true, gfm: true, headerPrefix: "", xhtml: true, langPrefix: "lang-"},
processAttributes: true,
processFrontMatter: true,
variablesMap: {},
/* the following TOC generation options are subject to change */
tocJSON: false,
tocDepth: Infinity
filePath: ""
}
{
html: {
text: <string>,
errors: <array>
},
properties: {
document: {
title: <string>,
frontMatterMap: <object>
}
},
jsonToc: {
text: <string>,
errors: <array>
},
xmlToc: {
text: <string>,
errors: <array>
}
}
Extensions are functions that can hook into well-defined points in the HTML generation process. A client can provide an array of extensions to the marked-it.generate()
options object.
All extension functions receive two arguments:
If the extension function returns any string, including "", then that string will replace the initially-generated value in the end document. If a non-string value is returned then the initially-generated value is preserved.
For an example of an extension that adds All extensions in this section receive a data object containing: A function that returns the HTML string for a DOM object. See options. A function that returns a DOM representation of an HTML string. options: xmlMode: A function to convert a DOM object to its inner HTML string. It takes the same options as the An object with functions for manipulating DOM objects. The functions are defined in the various files here. A function that can be used to replace all occurrences of html.onHeading (Note that TOC generation is being re-thought and therefore this extension is subject to change) This extension receives a data object containing: The source header string that this TOC entry would point to. A function that returns the HTML string for a DOM object. See options. A function that returns a DOM representation of an HTML string. options: xmlMode: A function to convert a DOM object to its inner HTML string. It takes the same options as the An object with functions for manipulating DOM objects. The functions are defined in the various files found here. elements see ./examples/extension-tableCaptions.js.
HTML Generation extensions
htmlToDom(string, options)
domToHtml(dom, options)
decodeEntities: domToInnerHtml(string, options)
domToHtml
function.domUtils
replaceVariables(string, variableMaps)
{{<variableName>}}
in a string with the corresponding variable values. This function comes pre-seeded with all currently-scoped variable values. Optionally, additional maps containing more variable name->value pairs can be provided.HTML Generation extension points
html.onCode
html.onBlockquote
html.onHorizontalRule
html.onList
html.onListItem
html.onParagraph
html.onPre
html.onTable
html.onTablerow
html.onTablecell
html.onStrong
html.onEmphasis
html.onCodespan
html.onDel
html.onLink
html.onImage TOC Generation extensions
header
htmlToDom(string, options)
domToHtml(dom, options)
decodeEntities: domToInnerHtml(string, options)
domToHtml
function.domUtils
TOC Generation extension points
json.toc.onTopic
xml.toc.onTopic