[remark-wiki-link/test][xs]:specify format

- also temporarily force any type on htmlExtension
This commit is contained in:
olayway 2023-06-06 16:55:00 +02:00
parent 310a4cc42a
commit 00166a5975

View File

@ -5,9 +5,9 @@ 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]]", {
const serialized = micromark("[[Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
// note: class="internal new"
expect(serialized).toBe(
@ -16,9 +16,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("with 'raw' file format (default) that has a matching permalink", () => {
const serialized = micromark("[[Wiki Link]]", {
const serialized = micromark("[[Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ permalinks: ["Wiki Link"] })],
htmlExtensions: [html({ permalinks: ["Wiki Link"] }) as any], // TODO type fix
});
// note: class="internal"
expect(serialized).toBe(
@ -27,12 +27,12 @@ describe("micromark-extension-wiki-link", () => {
});
test("with shortened Obsidian-style path that has no matching permalink", () => {
const serialized = micromark("[[Wiki Link]]", {
const serialized = micromark("[[Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [
html({
pathFormat: "obsidian-short",
}),
}) as any // TODO type fix
],
});
// note: class="internal new"
@ -42,13 +42,13 @@ describe("micromark-extension-wiki-link", () => {
});
test("with shortened Obsidian-style path that has a matching permalink", () => {
const serialized = micromark("[[Wiki Link]]", {
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(
@ -58,9 +58,9 @@ describe("micromark-extension-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]]", {
const serialized = micromark("[[some/folder/Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ pathFormat: "obsidian-absolute" })],
htmlExtensions: [html({ pathFormat: "obsidian-absolute" }) as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="/some/folder/Wiki Link" class="internal new">some/folder/Wiki Link</a></p>'
@ -75,7 +75,7 @@ describe("micromark-extension-wiki-link", () => {
html({
permalinks: ["/some/folder/Wiki Link"],
pathFormat: "obsidian-absolute",
}),
}) as any // TODO type fix
],
});
expect(serialized).toBe(
@ -86,9 +86,9 @@ describe("micromark-extension-wiki-link", () => {
describe("aliases and headings", () => {
test("parses a wiki link with heading", () => {
const serialized = micromark("[[Wiki Link#Some Heading]]", {
const serialized = micromark("[[Wiki Link#Some Heading]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
// note: lowercased and hyphenated heading
expect(serialized).toBe(
@ -97,9 +97,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link with heading and alias", () => {
const serialized = micromark("[[Wiki Link#Some Heading|Alias]]", {
const serialized = micromark("[[Wiki Link#Some Heading|Alias]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
// note: lowercased and hyphenated heading
expect(serialized).toBe(
@ -108,9 +108,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link to a heading on the same page", () => {
const serialized = micromark("[[#Some Heading]]", {
const serialized = micromark("[[#Some Heading]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="#some-heading" class="internal new">Some Heading</a></p>'
@ -120,9 +120,9 @@ describe("micromark-extension-wiki-link", () => {
describe("image embeds", () => {
test("parses an image embed of supported file format", () => {
const serialized = micromark("![[My Image.jpg]]", {
const serialized = micromark("![[My Image.jpg]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><img src="My Image.jpg" alt="My Image.jpg" class="internal new" /></p>'
@ -130,17 +130,17 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses an image embed of unsupported file format", () => {
const serialized = micromark("![[My Image.xyz]]", {
const serialized = micromark("![[My Image.xyz]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe("<p>![[My Image.xyz]]</p>");
});
test("parses and image ambed with a matching permalink", () => {
const serialized = micromark("![[My Image.jpg]]", {
const serialized = micromark("![[My Image.jpg]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ permalinks: ["My Image.jpg"] })],
htmlExtensions: [html({ permalinks: ["My Image.jpg"] }) as any], // TODO type fix
});
expect(serialized).toBe(
'<p><img src="My Image.jpg" alt="My Image.jpg" class="internal" /></p>'
@ -154,7 +154,7 @@ describe("micromark-extension-wiki-link", () => {
html({
permalinks: ["/assets/My Image.jpg"],
pathFormat: "obsidian-short",
}),
}) as any // TODO type fix
],
});
expect(serialized).toBe(
@ -163,9 +163,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses an image embed with an alt text", () => {
const serialized = micromark("![[My Image.jpg|My Image Alt]]", {
const serialized = micromark("![[My Image.jpg|My Image Alt]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><img src="My Image.jpg" alt="My Image Alt" class="internal new" /></p>'
@ -173,9 +173,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a pdf embed", () => {
const serialized = micromark("![[My Document.pdf]]", {
const serialized = micromark("![[My Document.pdf]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><iframe width="100%" src="My Document.pdf#toolbar=0" class="internal new" /></p>'
@ -185,33 +185,33 @@ describe("micromark-extension-wiki-link", () => {
describe("invalid wiki links", () => {
test("doesn't parse a wiki link with two missing closing brackets", () => {
const serialized = micromark("[[Wiki Link", {
const serialized = micromark("[[Wiki Link", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe("<p>[[Wiki Link</p>");
});
test("doesn't parse a wiki link with one missing closing bracket", () => {
const serialized = micromark("[[Wiki Link]", {
const serialized = micromark("[[Wiki Link]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe("<p>[[Wiki Link]</p>");
});
test("doesn't parse a wiki link with a missing opening bracket", () => {
const serialized = micromark("[Wiki Link]]", {
const serialized = micromark("[Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe("<p>[Wiki Link]]</p>");
});
test("doesn't parse a wiki link in single brackets", () => {
const serialized = micromark("[Wiki Link]", {
const serialized = micromark("[Wiki Link]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe("<p>[Wiki Link]</p>");
});
@ -219,13 +219,13 @@ describe("micromark-extension-wiki-link", () => {
describe("other options", () => {
test("parses a wiki link with a custom class", () => {
const serialized = micromark("[[Wiki Link]]", {
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(
@ -234,9 +234,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link with a custom divider", () => {
const serialized = micromark("[[Wiki Link:Alias Name]]", {
const serialized = micromark("[[Wiki Link:Alias Name]]", "ascii", {
extensions: [syntax({ aliasDivider: ":" })],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="Wiki Link" class="internal new">Alias Name</a></p>'
@ -244,14 +244,14 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link with a custom page resolver", () => {
const serialized = micromark("[[Wiki Link]]", {
const serialized = micromark("[[Wiki Link]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [
html({
wikiLinkResolver: (page) => [
page.replace(/\s+/, "-").toLowerCase(),
],
}),
}) as any // TODO type fix
],
});
expect(serialized).toBe(
@ -261,9 +261,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses wiki links to index files", () => {
const serialized = micromark("[[/some/folder/index]]", {
const serialized = micromark("[[/some/folder/index]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="/some/folder" class="internal new">/some/folder/index</a></p>'
@ -272,9 +272,9 @@ describe("micromark-extension-wiki-link", () => {
describe("other", () => {
test("parses a wiki link to some index page in a folder with no matching permalink", () => {
const serialized = micromark("[[/some/folder/index]]", {
const serialized = micromark("[[/some/folder/index]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="/some/folder" class="internal new">/some/folder/index</a></p>'
@ -282,9 +282,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link to some index page in a folder with a matching permalink", () => {
const serialized = micromark("[[/some/folder/index]]", {
const serialized = micromark("[[/some/folder/index]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ permalinks: ["/some/folder"] })],
htmlExtensions: [html({ permalinks: ["/some/folder"] }) as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="/some/folder" class="internal">/some/folder/index</a></p>'
@ -292,9 +292,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link to home index page with no matching permalink", () => {
const serialized = micromark("[[/index]]", {
const serialized = micromark("[[/index]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html()],
htmlExtensions: [html() as any], // TODO type fix
});
expect(serialized).toBe(
'<p><a href="/" class="internal new">/index</a></p>'
@ -302,9 +302,9 @@ describe("micromark-extension-wiki-link", () => {
});
test("parses a wiki link to home index page with a matching permalink", () => {
const serialized = micromark("[[/index]]", {
const serialized = micromark("[[/index]]", "ascii", {
extensions: [syntax()],
htmlExtensions: [html({ permalinks: ["/"] })],
htmlExtensions: [html({ permalinks: ["/"] }) as any], // TODO type fix
});
expect(serialized).toBe('<p><a href="/" class="internal">/index</a></p>');
});