markdown-it-metadata-block
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

markdown-it-metadata-block

Metadata block plugin for markdown-it markdown parser.

Syntax

Syntax based on Pandoc yaml_metadata_block but metadata format is configurable:

A metadata block must either start on the first line or be preceded by a blank line. Metadata blocks are by a line starting with exactly three dashes (---) possibly followed by whitespace. They are closed by three dashes or three dots (...).

The content must parse to a valid object otherwise it will not be interpreted as a metadata block. Metadata blocks are interpreted and merged in sequence.

Options

interface MetadataOptions {
  meta?: object
  parseMetadata: (block: string) => any
}

The parseMetadata option is required. Recommended value: require('yaml').parse. If the function does not return an object or throws an error, the potential metadata block will be interpreted as if the plugins was disabled.

Use

the env object of a parser run will be populated with an object meta which can be used by other plugins. If you want to expose the metadata you have to pass the meta option to the plugin:

import md from 'markdown-it'
import metadata_block from 'markdown-it-metadata-block'
import yaml from 'yaml'

const meta = {} // may be pre-populated with defaults

const markdown = md().use(metadata_block,{
  parseMetadata: yaml.parse,
  meta
})

markdown.render(`
---
a: 1
...

the markdown content

---
b:
- 1
- 2
- 3
...
`)

console.log(meta.a) // 5
console.log(meta.b) // [1,2,3]

Package Sidebar

Install

npm i markdown-it-metadata-block

Weekly Downloads

25

Version

1.0.6

License

MIT

Unpacked Size

9.11 kB

Total Files

9

Last publish

Collaborators

  • martinring