Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

marked-it-core

IBM1.1kMIT2.4.2

A Marked-backed Markdown->HTML generator. Supports extended attribute and front matter syntaxes, and provides hooks for modifying the generated HTML.

markdown, html, marked, kramdown, attributes, front matter, footnotes, toc

readme

marked-it

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.

Install

npm install marked-it-core

Example Usage

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>
*/

API

marked-it.generate(markdownText [,options])

options (default values shown)

{
    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: ""
}

returns:

{
    html: {
        text: <string>,
        errors: <array>
    },
    properties: {
        document: {
            title: <string>,
            frontMatterMap: <object>
        }
    },
    jsonToc: {
        text: <string>,
        errors: <array>
    },
    xmlToc: {
        text: <string>,
        errors: <array>
    }
}

Extensions

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:

  • value: the default value that has been generated
  • data: additional data and functions that may be helpful for generating a replacement value

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 elements to generated

elements see ./examples/extension-tableCaptions.js.

HTML Generation extensions

All extensions in this section receive a data object containing:

htmlToDom(string, options)

A function that returns the HTML string for a DOM object. See options.

domToHtml(dom, options)

A function that returns a DOM representation of an HTML string.

options:

xmlMode: <boolean>
decodeEntities: <boolean>

domToInnerHtml(string, options)

A function to convert a DOM object to its inner HTML string. It takes the same options as the domToHtml function.

domUtils

An object with functions for manipulating DOM objects. The functions are defined in the various files here.

replaceVariables(string, variableMaps)

A function that can be used to replace all occurrences of {{<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.onHeading
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

(Note that TOC generation is being re-thought and therefore this extension is subject to change)

This extension receives a data object containing:

header

The source header string that this TOC entry would point to.

htmlToDom(string, options)

A function that returns the HTML string for a DOM object. See options.

domToHtml(dom, options)

A function that returns a DOM representation of an HTML string.

options:

xmlMode: <boolean>
decodeEntities: <boolean>

domToInnerHtml(string, options)

A function to convert a DOM object to its inner HTML string. It takes the same options as the domToHtml function.

domUtils

An object with functions for manipulating DOM objects. The functions are defined in the various files found here.

TOC Generation extension points

json.toc.onTopic
xml.toc.onTopic

changelog

Change Log

This project uses semantic versioning.

[2.4.1 and 2.4.2] 2023-11-09

Change markdown-it-attrs dependency reference to @marked-it/markdown-it-attrs.

[2.4.0] 2023-07-12

Add labelFormatted in JSON TOC generation.

[2.3.0] 2023-06-16

Add onPre HTML generation extension point and replaceVariable function in all HTML generation extension invocations.

[2.2.3] 2022-11-30

Add support for subscript and superscript.

[2.2.2] 2022-11-01

Add support for spans using bracket syntax.

[2.2.1] 2022-10-31

Enable task list checkboxes.

[2.2.0] 2022-10-20

Add support for generating task lists, and add warnings to result object for unresolved variables.

[2.1.1] 2022-08-26

Fix support for installing with npm 6.x.

[2.1.0] 2022-07-21

Add support for additional keys that do not start with <site.> in variableMaps.

[2.0.1] 2022-02-17

Fix table generation bug when table cell content begins with formatting like bold or italics.

[2.0.0] 2021-12-07

Version 2.0. Makes markdown-it the default underlying HTML generator.

[0.17.13] 2021-10-05

Fix handling of the string "" within an inline code span in a table cell.

[0.17.12] 2021-09-29

Fix detection of tags in table cells to ignore code sections.

[0.17.11] 2021-09-28

Fix regression in detection of code block bounds.

[0.17.10] 2021-09-23

Another fix for detection of code block bounds.

[0.17.9] 2021-09-22

Fix detection of code block bounds.

[0.17.8] 2021-09-17

Pick up the latest markdown-it-attrs.

[0.17.6 and 0.17.7] 2021-09-15

Fix injection of variables to not touch code blocks.

[0.17.5] 2021-09-07

Improve handling of table cells that start with HTML tags.

[0.17.3 and 0.17.4] 2021-08-27

Fix processing of table cell contents and stop linkifying fuzzy urls.

[0.17.2] 2021-08-17

Improve handling of attributes on tables and pick up the latest markdown-it-attrs.

[0.17.1] 2021-08-11

Update the dependency on markdown-it-attrs.

[0.17.0] 2021-08-11

Add processing of table cell content as markdown (for markdown-it renderer only) and fix attribute placement bug.

[0.16.7] 2021-08-10

Work around markdown-it-attrs bug that can cause a crash in the absence of trailing whitespace.

[0.16.6] 2021-07-23

Add auto-generation of header ids (in the absence of an id attribute) when using markdown-it.

[0.16.5] 2021-07-22

Add automatic support for attributes that follow fenced code blocks when using markdown-it.

[0.16.3] 2021-07-21

Don't pre-process within code fences when using markdown-it.

[0.16.2] 2021-07-19

Improvement to generation of syntax styling.

[0.16.1] 2021-07-16

Fix syntax styling for code blocks when using markdown-it.

[0.16.0] 2021-07-12

Added initial support for use of markdown-it as the core md->html generator.

[0.15.0] 2021-01-18

Add extension "json.toc.onTopic" data attribute frontMatterMap.

[0.14.1] 2020-03-07

Fixed ALD detection regex.

[0.14.0] 2019-10-11

Added support for generating footnotes that follow the syntax described at https://www.markdownguide.org/extended-syntax/#footnotes.

[0.13.1] 2019-03-27

Released updated package-lock.json.

[0.13.0] 2019-03-27

Added escape and unescape functions to the data passed to many types of extensions.

[0.12.0] 2019-03-19

Fixed invocations of extensions for span-level elements.

[0.11.1] 2019-02-14

Bumped up the mocha dependency version.

[0.11.0] 2019-02-13

Bumped up to marked v0.3.9 and introduced option to auto-fix headers with invalid syntax.

[0.10.11] 2019-02-08

Fix to attribute detection to handle non-typical space characters.

[0.10.10] 2019-01-15

Changes to support how 'id' attributes for TOC topics are computed by marked-it-cli.

[0.10.8 and 0.10.9] 2018-11-20

Changes to support the addition of 'id' attributes to TOC topics by marked-it-cli.

[0.10.7] 2018-11-07

Changes to support new generation of TOC links by marked-it-cli.

[0.10.6] 2018-11-01

Fix bug that was failing to substitute attribute values into root-level code blocks.

[0.10.5] 2018-10-16

Changes to support setting a custom path prefix in TOCs generated by marked-it-cli.

[0.10.4] 2018-10-11

Fixed path adjustment bug in JSON TOC adapter.

[0.10.3] 2018-09-26

A generated document's title is now determined by the first H1 or H2 that's encountered.

[0.10.2] 2018-08-13

Bug fixes.

[0.10.1] 2018-08-13

Changes to support JSON-format TOC generation by marked-it-cli.

[0.10.0] 2018-08-02

New features

Support has been added for generating TOCs in JSON format. To use this, specify option tocJSON: true when invoking generate(), and the JSON TOC output will be included in the result's jsonToc field.

[0.9.0] 2017-12-21

Events sent from the following extension points now include a src attribute that contains the original markdown source of the new element:

  • html.onCode
  • html.onHeading
  • html.onHr
  • html.onHtml
  • html.onParagraph
  • html.onTable

[0.8.0] 2017-05-07

Initial release