import { syntax } from "../src/lib/syntax"; import { html } from "../src/lib/html"; import { micromark } from "micromark"; describe("micromark-extension-wiki-link", () => { describe("parses a wikilink", () => { test("with 'raw' file format (default) that has no matching permalink", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); // note: class="internal new" expect(serialized).toBe( '

Wiki Link

' ); }); test("with 'raw' file format (default) that has a matching permalink", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [html({ permalinks: ["Wiki Link"] }) as any], // TODO type fix }); // note: class="internal" expect(serialized).toBe( '

Wiki Link

' ); }); test("with shortened Obsidian-style path that has no matching permalink", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [ html({ pathFormat: "obsidian-short", }) as any // TODO type fix ], }); // note: class="internal new" expect(serialized).toBe( '

Wiki Link

' ); }); test("with shortened Obsidian-style path that has a matching permalink", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [ html({ permalinks: ["/some/folder/Wiki Link"], pathFormat: "obsidian-short", }) as any // TODO type fix ], }); expect(serialized).toBe( '

Wiki Link

' ); }); // Obsidian absolute path doesn't have a leading slash test("with 'obsidian-absolute' path format that has no matching permalink", () => { const serialized = micromark("[[some/folder/Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [html({ pathFormat: "obsidian-absolute" }) as any], // TODO type fix }); expect(serialized).toBe( '

some/folder/Wiki Link

' ); }); // Obsidian absolute path doesn't have a leading slash test("with 'obsidian-absolute' path format that has a matching permalink", () => { const serialized = micromark("[[some/folder/Wiki Link]]", { extensions: [syntax()], htmlExtensions: [ html({ permalinks: ["/some/folder/Wiki Link"], pathFormat: "obsidian-absolute", }) as any // TODO type fix ], }); expect(serialized).toBe( '

some/folder/Wiki Link

' ); }); }); describe("aliases and headings", () => { test("parses a wiki link with heading", () => { const serialized = micromark("[[Wiki Link#Some Heading]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); // note: lowercased and hyphenated heading expect(serialized).toBe( '

Wiki Link#Some Heading

' ); }); test("parses a wiki link with heading and alias", () => { const serialized = micromark("[[Wiki Link#Some Heading|Alias]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); // note: lowercased and hyphenated heading expect(serialized).toBe( '

Alias

' ); }); test("parses a wiki link to a heading on the same page", () => { const serialized = micromark("[[#Some Heading]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '

Some Heading

' ); }); }); describe("image embeds", () => { test("parses an image embed of supported file format", () => { const serialized = micromark("![[My Image.jpg]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '

My Image.jpg

' ); }); test("parses an image embed of unsupported file format", () => { const serialized = micromark("![[My Image.xyz]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe("

![[My Image.xyz]]

"); }); test("parses and image ambed with a matching permalink", () => { const serialized = micromark("![[My Image.jpg]]", "ascii", { extensions: [syntax()], htmlExtensions: [html({ permalinks: ["My Image.jpg"] }) as any], // TODO type fix }); expect(serialized).toBe( '

My Image.jpg

' ); }); test("parses an image embed with a matching permalink and Obsidian-style shortedned path", () => { const serialized = micromark("![[My Image.jpg]]", { extensions: [syntax()], htmlExtensions: [ html({ permalinks: ["/assets/My Image.jpg"], pathFormat: "obsidian-short", }) as any // TODO type fix ], }); expect(serialized).toBe( '

My Image.jpg

' ); }); test("parses an image embed with an alt text", () => { const serialized = micromark("![[My Image.jpg|My Image Alt]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '

My Image Alt

' ); }); test("parses a pdf embed", () => { const serialized = micromark("![[My Document.pdf]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '