import * as mod from "https://deno.land/std@0.224.0/front_matter/mod.ts";
Extracts front matter from strings. Adapted from jxson/front-matter.
Supported formats
JSON
import { test } from "https://deno.land/std@0.224.0/front_matter/test.ts";
import { extract } from "https://deno.land/std@0.224.0/front_matter/json.ts";
const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";
const result = extract(str);
test(str); // true
result.frontMatter; // "{\"and\": \"this\"}"
result.body; // "deno is awesome"
result.attrs; // { and: "this" }
extractJson
| extract and test
support the following delimiters.
---json
{
"and": "this"
}
---
{
"is": "JSON"
}
TOML
import { test } from "https://deno.land/std@0.224.0/front_matter/test.ts";
import { extract } from "https://deno.land/std@0.224.0/front_matter/toml.ts";
const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";
const result = extract(str);
test(str); // true
result.frontMatter; // "module = 'front_matter'"
result.body; // "deno is awesome"
result.attrs; // { module: "front_matter" }
extractToml
| extract and test
support the following delimiters.
---toml
this = 'is'
---
= toml =
parsed = 'as'
toml = 'data'
= toml =
+++
is = 'that'
not = 'cool?'
+++
YAML
import { test } from "https://deno.land/std@0.224.0/front_matter/test.ts";
import { extract } from "https://deno.land/std@0.224.0/front_matter/yaml.ts";
const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";
const result = extract(str);
test(str); // true
result.frontMatter; // "module: front_matter"
result.body; // "deno is awesome"
result.attrs; // { module: "front_matter" }
extractYaml
| extract and test
support the following delimiters.
---
these: are
---
---yaml
all: recognized
---
= yaml =
as: yaml
= yaml =
Functions
Factory that creates a function that extracts front matter from a string with the given parsers. Supports YAML, TOML and JSON. | |
f test | Tests if a string has valid front matter. Supports YAML, TOML and JSON. |
Type Aliases
Return type for | |
Function return type for | |
Parser function type used alongside |