diff --git a/packages/remark-wiki-link/src/lib/fromMarkdown.ts b/packages/remark-wiki-link/src/lib/fromMarkdown.ts
index 088142248..096ed463f 100644
--- a/packages/remark-wiki-link/src/lib/fromMarkdown.ts
+++ b/packages/remark-wiki-link/src/lib/fromMarkdown.ts
@@ -157,6 +157,12 @@ function fromMarkdown(opts: FromMarkdownOptions = {}) {
width: '100%',
src: `${hrefTemplate(link)}#toolbar=0`,
};
+ } else if (format === 'csv') {
+ // CSV support
+ wikiLink.data.hName = 'FlatUiTable';
+ wikiLink.data.hProperties = {
+ data: { url: hrefTemplate(link) },
+ };
} else {
const hasDimensions = alias && /^\d+(x\d+)?$/.test(alias);
// Take the target as alt text except if alt name was provided [[target|alt text]]
diff --git a/packages/remark-wiki-link/src/lib/html.ts b/packages/remark-wiki-link/src/lib/html.ts
index a95c0c6a8..b0e5dd9be 100644
--- a/packages/remark-wiki-link/src/lib/html.ts
+++ b/packages/remark-wiki-link/src/lib/html.ts
@@ -127,6 +127,11 @@ function html(opts: HtmlOptions = {}) {
link
)}#toolbar=0" class="${classNames}" />`
);
+ } else if (format === 'csv') {
+ // CSV support
+ this.tag(
+ ``
+ );
} else {
const hasDimensions = alias && /^\d+(x\d+)?$/.test(alias);
// Take the target as alt text except if alt name was provided [[target|alt text]]
diff --git a/packages/remark-wiki-link/src/lib/isSupportedFileFormat.ts b/packages/remark-wiki-link/src/lib/isSupportedFileFormat.ts
index bb3d44ad2..368e8f3ec 100644
--- a/packages/remark-wiki-link/src/lib/isSupportedFileFormat.ts
+++ b/packages/remark-wiki-link/src/lib/isSupportedFileFormat.ts
@@ -11,6 +11,7 @@ export const supportedFileFormats = [
"avif",
"ico",
"pdf",
+ "csv",
];
export const isSupportedFileFormat = (filePath: string): [boolean, string] => {
diff --git a/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts b/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
index da010cdc0..20011a402 100644
--- a/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
+++ b/packages/remark-wiki-link/test/micromarkExtensionWikiLink.spec.ts
@@ -161,7 +161,44 @@ describe("micromark-extension-wiki-link", () => {
'
'
);
});
-
+ // CSV tests
+ test("parses a CSV file embed of supported file format", () => {
+ const serialized = micromark("![[data.csv]]", "ascii", {
+ extensions: [syntax()],
+ htmlExtensions: [html() as any], // TODO type fix
+ });
+ expect(serialized).toBe(
+ ''
+ );
+ });
+
+ test("leaves a CSV file embed of unsupported file format as plain text", () => {
+ const serialized = micromark("![[data.xyz]]", "ascii", {
+ extensions: [syntax()],
+ htmlExtensions: [html() as any], // TODO type fix
+ });
+ expect(serialized).toBe('![[data.xyz]]
');
+ });
+
+ test("parses a CSV file embed with a matching permalink", () => {
+ const serialized = micromark("![[data.csv]]", "ascii", {
+ extensions: [syntax()],
+ htmlExtensions: [html({ permalinks: ["data.csv"] }) as any], // TODO type fix
+ });
+ expect(serialized).toBe(
+ ''
+ );
+ });
+ // Ignore the table alias test
+ // test("parses a CSV file embed with an alias", () => {
+ // const serialized = micromark("![[data.csv|My CSV File]]", "ascii", {
+ // extensions: [syntax()],
+ // htmlExtensions: [html() as any], // TODO type fix
+ // });
+ // expect(serialized).toBe(
+ // ''
+ // );
+ // });
// TODO: Fix alt attribute
test("Can identify the dimensions of the image if exists", () => {
const serialized = micromark("![[My Image.jpg|200x200]]", "ascii", {
diff --git a/packages/remark-wiki-link/test/remarkWikiLink.spec.ts b/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
index 72975df09..cb90f4eaf 100644
--- a/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
+++ b/packages/remark-wiki-link/test/remarkWikiLink.spec.ts
@@ -381,6 +381,23 @@ describe("remark-wiki-link", () => {
);
});
});
+
+ test("parses a CSV embed", () => {
+ const processor = unified().use(markdown).use(wikiLinkPlugin);
+
+ let ast = processor.parse("![[My Data.csv]]");
+ ast = processor.runSync(ast);
+
+ expect(select("wikiLink", ast)).not.toEqual(null);
+
+ visit(ast, "wikiLink", (node: Node) => {
+ expect(node.data?.isEmbed).toEqual(true);
+ expect(node.data?.target).toEqual("My Data.csv");
+ expect(node.data?.permalink).toEqual("My Data.csv");
+ expect(node.data?.hName).toEqual("FlatUiTable");
+ expect((node.data?.hProperties as any).data).toEqual({ url: "My Data.csv" });
+ });
+ });
});
describe("Links with special characters", () => {