deno.land / std@0.224.0 / front_matter / any.ts
1234567891011121314151617181920212223242526272829303132333435363738// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { createExtractor, type Extractor, type Parser,} from "./create_extractor.ts";import { parse as parseYAML } from "../yaml/parse.ts";import { parse as parseTOML } from "../toml/parse.ts";
/** * Extracts and parses {@link https://yaml.org | YAML}, {@link https://toml.io | * TOML}, or {@link https://www.json.org/ | JSON} from the metadata of front * matter content, depending on the format. * * @example * ```ts * import { extract } from "https://deno.land/std@$STD_VERSION/front_matter/any.ts"; * * const output = `---json * { * "title": "Three dashes marks the spot" * } * --- * Hello, world!`; * const result = extract(output); * * result.frontMatter; // '{\n "title": "Three dashes marks the spot"\n}' * result.body; // "Hello, world!" * result.attrs; // { title: "Three dashes marks the spot" } * ``` */export const extract: Extractor = createExtractor({ yaml: parseYAML as Parser, toml: parseTOML as Parser, json: JSON.parse as Parser,});
Version Info