Function extractYaml

  • Extracts and parses YAML from the metadata of front matter content.

    Type Parameters

    • T

      The type of the parsed front matter.

    Parameters

    • text: string

      The text to extract YAML front matter from.

    Returns Extract<T>

    The extracted YAML front matter and body content.

    import { extract } from "@std/front-matter/yaml";
    import { assertEquals } from "@std/assert";

    const output = `---yaml
    title: Three dashes marks the spot
    ---
    Hello, world!`;
    const result = extract(output);

    assertEquals(result, {
    frontMatter: "title: Three dashes marks the spot",
    body: "Hello, world!",
    attrs: { title: "Three dashes marks the spot" },
    });

    Note: If you need to pass the options to the yaml parse, use the new version of this API from @std/yaml/unstable-yaml.