mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
d102a10235
* refactor: import from `@std/assert` * update
35 lines
865 B
TypeScript
35 lines
865 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import {
|
|
createExtractor,
|
|
type Extractor,
|
|
type Parser,
|
|
} from "./create_extractor.ts";
|
|
import { parse } from "@std/yaml/parse";
|
|
|
|
/**
|
|
* Extracts and parses {@link https://yaml.org | YAML} from the metadata of
|
|
* front matter content.
|
|
*
|
|
* @example Extract YAML front matter
|
|
* ```ts
|
|
* 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" },
|
|
* });
|
|
* ```
|
|
*/
|
|
export const extract: Extractor = createExtractor({
|
|
["yaml"]: parse as Parser,
|
|
});
|