2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-03-14 08:09:10 +00:00
|
|
|
// Copyright (c) Jason Campbell. MIT license
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extracts
|
2024-01-31 22:19:46 +00:00
|
|
|
* {@link https://daily-dev-tips.com/posts/what-exactly-is-frontmatter/ | front matter}
|
2024-03-20 01:38:07 +00:00
|
|
|
* from strings. Adapted from
|
2024-01-31 22:19:46 +00:00
|
|
|
* {@link https://github.com/jxson/front-matter/blob/36f139ef797bd9e5196a9ede03ef481d7fbca18e/index.js | jxson/front-matter}.
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ## Supported formats
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ### JSON
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
|
|
|
* ```ts
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* import { test, extractJson } from "@std/front-matter";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* const str = "---json\n{\"and\": \"this\"}\n---\ndeno is awesome";
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* assertEquals(test(str), true);
|
|
|
|
* assertEquals(extractJson(str), {
|
|
|
|
* frontMatter: "{\"and\": \"this\"}",
|
|
|
|
* body: "deno is awesome",
|
|
|
|
* attrs: { and: "this" }
|
|
|
|
* });
|
2023-03-14 08:09:10 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-05-28 01:14:52 +00:00
|
|
|
* {@linkcode extractJson | extract} and {@linkcode test} support the following
|
|
|
|
* delimiters.
|
2024-03-20 01:38:07 +00:00
|
|
|
*
|
|
|
|
* ```markdown
|
|
|
|
* ---json
|
2023-03-14 08:09:10 +00:00
|
|
|
* {
|
2024-03-20 01:38:07 +00:00
|
|
|
* "and": "this"
|
2023-03-14 08:09:10 +00:00
|
|
|
* }
|
2024-03-20 01:38:07 +00:00
|
|
|
* ---
|
2023-03-14 08:09:10 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ```markdown
|
|
|
|
* {
|
|
|
|
* "is": "JSON"
|
2023-03-14 08:09:10 +00:00
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ### TOML
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ```ts
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* import { test, extractToml } from "@std/front-matter";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* const str = "---toml\nmodule = 'front_matter'\n---\ndeno is awesome";
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* assertEquals(test(str), true);
|
|
|
|
* assertEquals(extractToml(str), {
|
|
|
|
* frontMatter: "module = 'front_matter'",
|
|
|
|
* body: "deno is awesome",
|
|
|
|
* attrs: { module: "front_matter" }
|
|
|
|
* });
|
2023-03-14 08:09:10 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-05-28 01:14:52 +00:00
|
|
|
* {@linkcode extractToml | extract} and {@linkcode test} support the following
|
|
|
|
* delimiters.
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
|
|
|
* ```markdown
|
|
|
|
* ---toml
|
|
|
|
* this = 'is'
|
|
|
|
* ---
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ```markdown
|
|
|
|
* = toml =
|
|
|
|
* parsed = 'as'
|
|
|
|
* toml = 'data'
|
|
|
|
* = toml =
|
|
|
|
* ```
|
|
|
|
*
|
2023-03-17 07:18:01 +00:00
|
|
|
* ```markdown
|
|
|
|
* +++
|
|
|
|
* is = 'that'
|
|
|
|
* not = 'cool?'
|
|
|
|
* +++
|
|
|
|
* ```
|
|
|
|
*
|
2024-03-20 01:38:07 +00:00
|
|
|
* ### YAML
|
|
|
|
*
|
|
|
|
* ```ts
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* import { test, extractYaml } from "@std/front-matter";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2024-03-20 01:38:07 +00:00
|
|
|
*
|
|
|
|
* const str = "---yaml\nmodule: front_matter\n---\ndeno is awesome";
|
|
|
|
*
|
docs(assert,cli,data-structures,expect,fmt,front-matter,html,http,jsonc,semver,streams,text,toml,webgpu): add snippet checks in module, function and class docs to doc checker (#4855)
* chore: add snippet checks to module docs
* fix
* work
* tweak
2024-05-31 02:01:46 +00:00
|
|
|
* assertEquals(test(str), true);
|
|
|
|
* assertEquals(extractYaml(str), {
|
|
|
|
* frontMatter: "module: front_matter",
|
|
|
|
* body: "deno is awesome",
|
|
|
|
* attrs: { module: "front_matter" }
|
|
|
|
* });
|
2024-03-20 01:38:07 +00:00
|
|
|
* ```
|
|
|
|
*
|
2024-05-28 01:14:52 +00:00
|
|
|
* {@linkcode extractYaml | extract} and {@linkcode test} support the following
|
|
|
|
* delimiters.
|
2024-03-20 01:38:07 +00:00
|
|
|
*
|
|
|
|
* ```front_matter
|
|
|
|
* ---
|
|
|
|
* these: are
|
|
|
|
* ---
|
|
|
|
* ```
|
2023-03-14 08:09:10 +00:00
|
|
|
*
|
|
|
|
* ```markdown
|
2024-03-20 01:38:07 +00:00
|
|
|
* ---yaml
|
|
|
|
* all: recognized
|
2023-03-14 08:09:10 +00:00
|
|
|
* ---
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ```markdown
|
2024-03-20 01:38:07 +00:00
|
|
|
* = yaml =
|
|
|
|
* as: yaml
|
|
|
|
* = yaml =
|
2023-03-14 08:09:10 +00:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @module
|
|
|
|
*/
|
2024-05-28 01:14:52 +00:00
|
|
|
import { extract as extractJson } from "./json.ts";
|
|
|
|
import { extract as extractToml } from "./toml.ts";
|
|
|
|
import { extract as extractYaml } from "./yaml.ts";
|
2023-03-14 08:09:10 +00:00
|
|
|
|
2023-09-14 09:19:57 +00:00
|
|
|
export * from "./test.ts";
|
2024-07-03 07:53:55 +00:00
|
|
|
export * from "./types.ts";
|
2024-05-28 01:14:52 +00:00
|
|
|
|
|
|
|
export { extractJson, extractToml, extractYaml };
|