Changes
5 changed files (+66/-10)
-
-
@@ -121,6 +121,46 @@ },}); }); Deno.test("Should not throw when document has no frontmatter but frontmatter option is enabled", async () => { const fs = new MemoryFsReader([ { path: "Test.md", content: ` ## H2 `, }, ]); const fileReader = (await (fs.getRootDirectory().then((dir) => dir.read()).then((entries) => entries[0] ))) as FileReader; const parser = new ObsidianMarkdownParser({ frontmatter: true }); const content = await parser.parse({ documentMetadata: { title: "Test", name: "Test", }, fileReader, getAssetToken, getDocumentToken, }); assertObjectMatch(content, { content: { type: "root", children: [ { type: "heading", depth: 2, }, ], }, }); }); Deno.test("Should not drop metadata when parsing YAML frontmatter", async () => { const fs = new MemoryFsReader([ {
-
-
-
@@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com>// // SPDX-License-Identifier: Apache-2.0 import { test as testFrontmatter } from "../deps/deno.land/std/front_matter/test.ts"; import * as yamlFrontmatter from "../deps/deno.land/std/front_matter/yaml.ts"; import type * as Mdast from "../deps/esm.sh/mdast/types.ts"; import { fromMarkdown } from "../deps/esm.sh/mdast-util-from-markdown/mod.ts";
-
@@ -50,17 +51,16 @@ function getFrontMatterDate(frontmatter: Record<string, unknown>, key: string, ): Date | undefined { const str = getFrontMatterValue(frontmatter, key); if (typeof str !== "string") { return str; if (!(key in frontmatter)) { return undefined; } const timestamp = Date.parse(str); if (isNaN(timestamp)) { const value = frontmatter[key]; if (!(value instanceof Date) || isNaN(+value)) { return undefined; } return new Date(timestamp); return value; } export type ObsidianMarkdownDocument = DocumentContent<
-
@@ -141,9 +141,18 @@ }),}; } const frontmatter = yamlFrontmatter.extract( new TextDecoder().decode(bytes), ); const decoded = new TextDecoder().decode(bytes); if (!testFrontmatter(decoded)) { return { kind: "obsidian_markdown", content: await parseMarkdown(bytes, { getDocumentToken, getAssetToken, }), }; } const frontmatter = yamlFrontmatter.extract(decoded); const name = getFrontMatterValue(frontmatter.attrs, "name"); const title = getFrontMatterValue(frontmatter.attrs, "title");
-
-
-
@@ -162,6 +162,8 @@ "https://deno.land/std@0.223.0/cli/prompt_secret.ts": "3b2f95214422226482fba4a00cb25441475b6f97069a6f70f442c1c9a16c744c","https://deno.land/std@0.223.0/cli/spinner.ts": "cf873605771270b4324cc063b5031ab250d8efee8799e45e1a3bfdd333ff721d", "https://deno.land/std@0.223.0/cli/unicode_width.ts": "656dd4271ecc90684b6bf23a5fb8c1cf833da625ef2906b61273ad617038072f", "https://deno.land/std@0.223.0/fmt/colors.ts": "d239d84620b921ea520125d778947881f62c50e78deef2657073840b8af9559a", "https://deno.land/std@0.223.0/front_matter/_formats.ts": "9a8ac1524f93b3ae093bd66864a49fc0088037920c6d60863da136d10f92e04d", "https://deno.land/std@0.223.0/front_matter/test.ts": "6a72a690ef9bd606411e3e78dfd44f382fce58f722ed6e56ce57d65140368822", "https://deno.land/std@0.223.0/fs/exists.ts": "3d38cb7dcbca3cf313be343a7b8af18a87bddb4b5ca1bd2314be12d06533b50f", "https://deno.land/std@0.223.0/io/types.ts": "acecb3074c730b5ff487ba4fe9ce51e67bd982aa07c95e5f5679b7b2f24ad129", "https://deno.land/std@0.223.0/io/write_all.ts": "24aac2312bb21096ae3ae0b102b22c26164d3249dff96dbac130958aa736f038",
-
-
-
@@ -0,0 +1,5 @@// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com> // // SPDX-License-Identifier: Apache-2.0 export * from "https://deno.land/std@0.223.0/front_matter/test.ts";
-
-
-
@@ -55,7 +55,7 @@ resolveShortestPathWhenPossible: true,}); const contentParser = oneof( new JSONCanvasParser(), new ObsidianMarkdownParser(), new ObsidianMarkdownParser({ frontmatter: true }), ); const pageBuilder = new DefaultThemeBuilder({ copyright: "© 2024 Shota FUJI. This document is licensed under CC BY 4.0",
-