0.0.4 • Published 8 months ago

rehype-meta-string v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

rehype-meta-string

Known Vulnerabilities Maintainability publish workflow license GitHub issues NPM bundle size(minified + gzip)

NPM

A rehype plugin for parsing the meta string of markdown code fence.

This plugin parse the meta string into key-value paris and assign them to code tag ast nodes.

The parsing contains rules below:

  • true: empty or literal value true is treated as true
  • false: literal value false is treated as false
  • word: literal string without spaces is treated as word.
  • sentence: double quoted, singled quoted, back-ticked string are treated as string.
  • range: square brackets wrapped string is treated as range numbers. It requires format like {digits}-{digits}.
  • mixed: mix all the markers above.

There is the illustration table:

meta stringparsed
foo{ foo: true }
foo=true{ foo: false }

| | foo=false | { foo: false } | | | foo=bar | { foo: "bar" } | | | foo="false" | { foo: "false" } | | foo='false' | { foo: "false" } | | foo=`false` | { foo: "false" } | | foo="true" | { foo: "true" } | | foo='true' | { foo: "true" } | | foo=`true` | { foo: "true" } | | foo="bar baz" | { foo: "bar baz" } | | foo='bar baz' | { foo: "bar baz" } | | foo=`bar baz` | { foo: "bar baz" } | | | foo=42-71 | { foo: 42, 71 } | | | foo foo1=true foo2=false foo3=bar foo4="true" foo5='false' foo6=`hello world` foo7=42-71 | { foo: true, foo1: true, foo2: false, foo3: "bar", foo4: "true", foo5: "false", foo6="hello world", foo7: 42, 71 }

🧩 Installation

yarn add rehype-meta-string (or npm/pnpm)

💫 Options

  • metaString?: string

Specify the field name which holds the raw meta string. By default, it is metaString.