// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import {
  createExtractor,
  type Extractor,
  type Parser,
} from "./create_extractor.ts";
import { parse } from "jsr:/@std/toml@^1.0.0-rc.3/parse";

/**
 * Extracts and parses {@link https://toml.io | TOML} from the metadata of
 * front matter content.
 *
 * @example Extract TOML front matter
 * ```ts
 * import { extract } from "@std/front-matter/toml";
 * import { assertEquals } from "@std/assert";
 *
 * const output = `---toml
 * 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({
  ["toml"]: parse as Parser,
});

// denoCacheMetadata={"headers":{"access-control-allow-origin":"*","x-robots-tag":"noindex","content-length":"887","x-content-type-options":"nosniff","x-jsr-backend":"modules","cache-control":"public, max-age=31536000, immutable","set-cookie":"__cf_bm=eaopMN.DTTlTa7TeSPmcsm2f8zvW9p_5oyjO9U.OBJY-1785241874.9927611-1.0.1.1-ezFm0WdLpZKDL8xz0Z5FlVgY0UWzFPnDeO5qeFbvcQHeTicr7NtRDlEGC77.MNNyV4Q10NbMH_.vhDRvySWPNF7EsGFgJK44HyQxDxApHldL3AnwxfJWJD38BINisMiA; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cross-origin-resource-policy":"cross-origin","cf-ray":"a223e656afbd7db6-LAX","vary":"Origin","etag":"\"e93dba66089b9fc3668b00ae3fe7a9c8\"","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","server":"cloudflare","access-control-expose-headers":"*","content-type":"text/typescript","date":"Tue, 28 Jul 2026 12:31:15 GMT","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=8Myg2cwqOCziTI21irufld%2FtHsz6YJSxDGc32wtL6ehuZ0ArMJV6K%2BoPCn0DKrVtlnaY2o6KSEhiklt1Y4%2BwLG8YbAezK9K6JUTLM7hDiccBYFjwwW86Mhc%3D\"}]}"},"url":"https://jsr.io/@std/front-matter/0.224.3/toml.ts","time":1785241875}