@gerhobbelt/markdown-it-front-matter

v0.2.3-4
Plugin to process front matter container for markdown-it markdown parser (based on Craig McKenna's original)
markdown-it-plugin markdown-it markdown front-matter front matter frontmatter meta meta data meta-data and 2 more...

markdown-it-front-matter

npm master-ci

Build Status NPM version Coverage Status

Plugin for processing front matter for markdown-it markdown parser.

Install

$ npm install markdown-it-front-matter --save

Valid Front Matter

Essentially, valid front matter is a fenced block:

  • Indicated by three or more dashes: ---
  • Opening and closing fences must be the same number of dash characters
  • Opening fence must begin on the first line of the markdown string/file
  • Opening fence must not be indented
---
valid-front-matter: true
---

The example above uses YAML but YAML is not required

(bring your own front matter parser, e.g. front-matter)

Example

  • Front Matter is not rendered.
  • Any markup inside the block is passed to the required callback function as the first parameter.
  • The markdown_it 'front_matter' token is passed to the callback in the second argument.
  • The markdown_it state object is passed in the third argument.
  • The callback's this references the active markdown-it-front-matter options object (which is a Object.assign()-ed copy of the options object you passed earlier into the use() API call).
const md = require('@gerhobbelt/markdown-it')()
  .use(require('@gerhobbelt/markdown-it-front-matter'), {
    callback: function(fm, token, state) {
      console.log(fm);
    }
  });

let result = md.render('---\ntitle: This is the Title\n---\n# Heading\n----\nsome text');

// > title: This is the Title

References / Thanks

Code heavily borrowed from markdown-it-container

License

markdown-it-front-matter is distributed under the MIT License - see the LICENSE file for details.

npm i @gerhobbelt/markdown-it-front-matter

Metadata

  • MIT
  • >=12.20.0
  • Craig McKenna
  • released 6/25/2021

Downloads

Maintainers