Changes
5 changed files (+80/-2)
-
-
@@ -241,3 +241,38 @@ const hash = c.getHash(["H1", "H2", "H3"]);assertEquals(hash, "H3"); }); Deno.test("Should resolve link to custom block identifier", async () => { const fs = new MemoryFsReader([ { path: "Test.md", content: ` Foo Bar ^foo-bar Baz `, }, ]); const fileReader = (await (fs.getRootDirectory().then((dir) => dir.read()).then((entries) => entries[0] ))) as FileReader; const parser = new ObsidianMarkdownParser(); const content = await parser.parse({ documentMetadata: { title: "Test", name: "Test", }, fileReader, getAssetToken, getDocumentToken, }); const c = "documentContent" in content ? content.documentContent : content; const hash = c.getHash(["^foo-bar"]); assertEquals(hash, "foo-bar"); });
-
-
-
@@ -8,12 +8,18 @@ import type * as Mdast from "../deps/esm.sh/mdast/types.ts";import { fromMarkdown } from "../deps/esm.sh/mdast-util-from-markdown/mod.ts"; import { toString } from "../deps/esm.sh/mdast-util-to-string/mod.ts"; import { headingRange } from "../deps/esm.sh/mdast-util-heading-range/mod.ts"; import { find as findNode } from "../deps/esm.sh/unist-util-find/mod.ts"; import { ofm } from "./obsidian_markdown/micromark_extension_ofm.ts"; import { ofmFromMarkdown } from "./obsidian_markdown/mdast_util_ofm.ts"; import { type OfmBlockIdentifier, ofmFromMarkdown, } from "./obsidian_markdown/mdast_util_ofm.ts"; import { macanaMarkAssets } from "./obsidian_markdown/mdast_util_macana_mark_assets.ts"; import { macanaMarkDocumentToken } from "./obsidian_markdown/mdast_util_macana_mark_document_token.ts"; import { autoHeadingIdFromMarkdown } from "./obsidian_markdown/mdast_util_auto_heading_id.ts"; import { logger } from "../logger.ts"; import type { ContentParser,
-
@@ -117,6 +123,26 @@ return null;} const [selector, ...rest] = selectors; if (selector.startsWith("^")) { const ident = selector.slice(1); const found = findNode(root, (node) => ( !!(node.data && node.type === "ofmBlockIdentifier" && (node as OfmBlockIdentifier).value === ident) )); if (!found) { logger().error( `Macana couldn't find a block having a block ID "${selector}".` + ` You have to manually define the block identifier at the target location.`, { selector }, ); return null; } return ident; } const text = toString(fromMarkdown(selector, { extensions: [ofm()],
-
-
-
@@ -28,6 +28,8 @@ type OfmCalloutToHastHandlersOptions,} from "./mdast_util_ofm_callout.ts"; import { ofmImageSize } from "./mdast_util_ofm_image_size.ts"; export type { OfmBlockIdentifier } from "./mdast_util_ofm_block_identifier.ts"; export function ofmFromMarkdown(): Extension[] { return [ ...gfmFromMarkdown(),
-
-
-
@@ -21,11 +21,26 @@ ```markdown- [[Overview|Alternative Title]] - [[Overview]] - [[Overview#Arbitrary document tree]] - [[GitHub Flavored Markdown#^alert-callout-compat]] ``` - [[Overview|Alternative Title]] - [[Overview]] - [[Overview#Arbitrary document tree]] - [[GitHub Flavored Markdown#^alert-callout-compat]] ### Block identifier Macana can generate corresponding anchor point if you create a block identifier. Links to automatically generated block identifier is not supported. - [Internal links - Obsidian Help](https://help.obsidian.md/Linking+notes+and+files/Internal+links#Link+to+a+block+in+a+note) ```markdown This is a paragraph. ^block-ident-demo ``` This is a paragraph. ^block-ident-demo ### Image size attributes
-
-
-
@@ -46,7 +46,7 @@ - [x] Shortest path when possible- [x] Wikilink - [x] Label - [x] Heading - [ ] Block reference - [x] Block reference - [x] Defining a block - [x] Image size annotation - [ ] Embeddings
-