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 valuetrue
is treated astrue
false
: literal valuefalse
is treated asfalse
- 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 string | parsed |
---|---|
foo | { foo: true } |
foo=true | { foo: true } |
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] } |
yarn add rehype-meta-string (or npm/pnpm)
- metaString?: string
Specify the field name which holds the raw meta string. By default, it is
metaString
.