Extracts front matter from strings. Adapted from jxson/front-matter.
import { test, extractJson } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractJson(str), { frontMatter: "{\"and\": \"this\"}", body: "deno is awesome", attrs: { and: "this" }}); Copy
import { test, extractJson } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractJson(str), { frontMatter: "{\"and\": \"this\"}", body: "deno is awesome", attrs: { and: "this" }});
extract and test support the following delimiters.
extract
test
---json{ "and": "this"}--- Copy
---json{ "and": "this"}---
{ "is": "JSON"} Copy
{ "is": "JSON"}
import { test, extractToml } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractToml(str), { frontMatter: "module = 'front_matter'", body: "deno is awesome", attrs: { module: "front_matter" }}); Copy
import { test, extractToml } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractToml(str), { frontMatter: "module = 'front_matter'", body: "deno is awesome", attrs: { module: "front_matter" }});
---tomlthis = 'is'--- Copy
---tomlthis = 'is'---
= toml =parsed = 'as'toml = 'data'= toml = Copy
= toml =parsed = 'as'toml = 'data'= toml =
+++is = 'that'not = 'cool?'+++ Copy
+++is = 'that'not = 'cool?'+++
import { test, extractYaml } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractYaml(str), { frontMatter: "module: front_matter", body: "deno is awesome", attrs: { module: "front_matter" }}); Copy
import { test, extractYaml } from "@std/front-matter";import { assertEquals } from "@std/assert";const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";assertEquals(test(str), true);assertEquals(extractYaml(str), { frontMatter: "module: front_matter", body: "deno is awesome", attrs: { module: "front_matter" }});
--- these: are --- Copy
--- these: are ---
---yamlall: recognized--- Copy
---yamlall: recognized---
= yaml =as: yaml= yaml = Copy
= yaml =as: yaml= yaml =
Extracts front matter from strings. Adapted from jxson/front-matter.
Supported formats
JSON
extractandtestsupport the following delimiters.TOML
extractandtestsupport the following delimiters.YAML
extractandtestsupport the following delimiters.