All Projects → remarkjs → remark-frontmatter

remarkjs / remark-frontmatter

Licence: MIT license
remark plugin to support frontmatter (YAML, TOML, and more)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to remark-frontmatter

Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+982.63%)
Mutual labels:  yaml, toml
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+34.73%)
Mutual labels:  yaml, toml
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-14.97%)
Mutual labels:  yaml, toml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-44.31%)
Mutual labels:  yaml, toml
remark-bookmarks
plugin to manage links
Stars: ✭ 15 (-91.02%)
Mutual labels:  remark, remark-plugin
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (-32.34%)
Mutual labels:  yaml, toml
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+22.16%)
Mutual labels:  yaml, toml
Ansible Config encoder filters
Ansible role used to deliver the Config Encoder Filters.
Stars: ✭ 48 (-71.26%)
Mutual labels:  yaml, toml
remark-directive
remark plugin to support directives
Stars: ✭ 137 (-17.96%)
Mutual labels:  remark, remark-plugin
Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+10076.65%)
Mutual labels:  yaml, toml
Config Lite
A super simple & flexible & useful config module.
Stars: ✭ 78 (-53.29%)
Mutual labels:  yaml, toml
remark-autolink-headings
Legacy remark plugin to automatically add links to headings — please use `rehype-autolink-headings` instead
Stars: ✭ 63 (-62.28%)
Mutual labels:  remark, remark-plugin
Re Txt
converts text-formats from one to another, it is very useful if you want to re-format a json file to yaml, toml to yaml, csv to yaml, ... etc
Stars: ✭ 59 (-64.67%)
Mutual labels:  yaml, toml
Gray Matter
Contributing Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Stars: ✭ 2,105 (+1160.48%)
Mutual labels:  yaml, frontmatter
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-71.26%)
Mutual labels:  yaml, toml
Simple Settings
A simple way to manage your project settings.
Stars: ✭ 165 (-1.2%)
Mutual labels:  yaml, toml
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-83.23%)
Mutual labels:  yaml, toml
Configr
Implements the JSON, INI, YAML and TOML parser, for R setting and writing of configuration file.
Stars: ✭ 38 (-77.25%)
Mutual labels:  yaml, toml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+34.73%)
Mutual labels:  yaml, toml
wildq
Command-line TOML/JSON/INI/YAML/XML/HCL processor using jq c bindings
Stars: ✭ 22 (-86.83%)
Mutual labels:  yaml, toml

remark-frontmatter

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to support frontmatter (YAML, TOML, and more).

Contents

What is this?

This package is a unified (remark) plugin to add support for YAML, TOML, and other frontmatter. You can use this to add support for parsing and serializing this syntax extension.

unified is a project that transforms content with abstract syntax trees (ASTs). remark adds support for markdown to unified. mdast is the markdown AST that remark uses. micromark is the markdown parser we use. This is a remark plugin that adds support for the frontmatter syntax and AST to remark.

When should I use this?

Frontmatter is a metadata format in front of content. It’s typically written in YAML and is often used with markdown. This mechanism works well when you want authors, that have some markup experience, to configure where or how the content is displayed or supply metadata about content. Frontmatter does not work everywhere so it makes markdown less portable. A good example use case is markdown being rendered by (static) site generators.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install remark-frontmatter

In Deno with esm.sh:

import remarkFrontmatter from 'https://esm.sh/remark-frontmatter@4'

In browsers with esm.sh:

<script type="module">
  import remarkFrontmatter from 'https://esm.sh/remark-frontmatter@4?bundle'
</script>

Use

Say we have the following file, example.md:

+++
title = "New Website"
+++

# Other markdown

And our module, example.js, looks as follows:

import {read} from 'to-vfile'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkFrontmatter from 'remark-frontmatter'
import remarkStringify from 'remark-stringify'

main()

async function main() {
  const file = await unified()
    .use(remarkParse)
    .use(remarkStringify)
    .use(remarkFrontmatter, ['yaml', 'toml'])
    .use(() => (tree) => {
      console.dir(tree)
    })
    .process(await read('example.md'))

  console.log(String(file))
}

Now, running node example yields:

{
  type: 'root',
  children: [
    {type: 'toml', value: 'title = "New Website"', position: [Object]},
    {type: 'heading', depth: 1, children: [Array], position: [Object]}
  ],
  position: {
    start: {line: 1, column: 1, offset: 0},
    end: {line: 6, column: 1, offset: 48}
  }
}
+++
title = "New Website"
+++

# Other markdown

API

This package exports no identifiers. The default export is remarkFrontmatter.

unified().use(remarkFrontmatter[, options])

Configures remark so that it can parse and serialize frontmatter (YAML, TOML, and more). Doesn’t parse the data inside them: create your own plugin to do that.

options

One preset or Matter, or an array of them, defining all the supported frontmatters (default: 'yaml').

preset

Either 'yaml' or 'toml':

  • 'yaml'Matter defined as {type: 'yaml', marker: '-'}
  • 'toml'Matter defined as {type: 'toml', marker: '+'}
Matter

An object with a type and either a marker or a fence:

  • type (string) — Type to tokenize as
  • marker (string or {open: string, close: string}) — Character used to construct fences. By providing an object with open and close different characters can be used for opening and closing fences. For example the character '-' will result in '---' being used as the fence
  • fence (string or {open: string, close: string}) — String used as the complete fence. By providing an object with open and close different values can be used for opening and closing fences. This can be used too if fences contain different characters or lengths other than 3
  • anywhere (boolean, default: false) – if true, matter can be found anywhere in the document. If false (default), only matter at the start of the document is recognized

Examples

Example: custom marker

A custom frontmatter with different open and close markers, repeated 3 times, that looks like this:

<<<
data
>>>

# hi

…can be supported with:

// …
.use(remarkFrontmatter, {type: 'custom', marker: {open: '<', close: '>'}})
// …

Example: custom fence

A custom frontmatter with custom fences that are not repeated like this:

{
  "key": "value"
}

# hi

…can be supported with:

// …
.use(remarkFrontmatter, {type: 'json', fence: {open: '{', close: '}'}})
// …

Syntax

This plugin applies a micromark extensions to parse the syntax. See its readme for how it works:

The syntax supported depends on the given configuration.

Syntax tree

This plugin applies one mdast utility to build and serialize the AST. See its readme for how it works:

The node types supported in the tree depend on the given configuration.

Types

This package is fully typed with TypeScript. The YAML node type is supported in @types/mdast by default. To add other node types, register them by adding them to FrontmatterContentMap:

import type {Literal} from 'mdast'

interface TOML extends Literal {
  type: 'toml'
}

declare module 'mdast' {
  interface FrontmatterContentMap {
    // Allow using toml nodes defined by `remark-frontmatter`.
    toml: TOML
  }
}

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

This plugin works with unified version 6+ and remark version 13+.

Security

Use of remark-frontmatter does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.

Related

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].