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( '
' ); }); 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( '' ); }); 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( '' ); }); 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( '' ); }); // 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( '' ); }); // 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( '' ); }); }); 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( '' ); }); 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( '' ); }); 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( '' ); }); }); 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.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( '


[[Wiki Link
"); }); test("doesn't parse a wiki link with one missing closing bracket", () => { const serialized = micromark("[[Wiki Link]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe("[[Wiki Link]
"); }); test("doesn't parse a wiki link with a missing opening bracket", () => { const serialized = micromark("[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe("[Wiki Link]]
"); }); test("doesn't parse a wiki link in single brackets", () => { const serialized = micromark("[Wiki Link]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe("[Wiki Link]
"); }); }); describe("other options", () => { test("parses a wiki link with a custom class", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [ html({ newClassName: "test-new", wikiLinkClassName: "test-wiki-link", }) as any // TODO type fix ], }); expect(serialized).toBe( '' ); }); test("parses a wiki link with a custom divider", () => { const serialized = micromark("[[Wiki Link:Alias Name]]", "ascii", { extensions: [syntax({ aliasDivider: ":" })], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '' ); }); test("parses a wiki link with a custom page resolver", () => { const serialized = micromark("[[Wiki Link]]", "ascii", { extensions: [syntax()], htmlExtensions: [ html({ wikiLinkResolver: (page) => [ page.replace(/\s+/, "-").toLowerCase(), ], }) as any // TODO type fix ], }); expect(serialized).toBe( '' ); }); }); test("parses wiki links to index files", () => { const serialized = micromark("[[/some/folder/index]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '' ); }); describe("other", () => { test("parses a wiki link to some index page in a folder with no matching permalink", () => { const serialized = micromark("[[/some/folder/index]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '' ); }); test("parses a wiki link to some index page in a folder with a matching permalink", () => { const serialized = micromark("[[/some/folder/index]]", "ascii", { extensions: [syntax()], htmlExtensions: [html({ permalinks: ["/some/folder"] }) as any], // TODO type fix }); expect(serialized).toBe( '' ); }); test("parses a wiki link to home index page with no matching permalink", () => { const serialized = micromark("[[/index]]", "ascii", { extensions: [syntax()], htmlExtensions: [html() as any], // TODO type fix }); expect(serialized).toBe( '' ); }); test("parses a wiki link to home index page with a matching permalink", () => { const serialized = micromark("[[/index]]", "ascii", { extensions: [syntax()], htmlExtensions: [html({ permalinks: ["/"] }) as any], // TODO type fix }); expect(serialized).toBe(''); }); }); });