diff --git a/src/index.ts b/src/index.ts index 44f2bc5..30605d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ export interface Config { }; } -const defaultConfig: Config = { +export const defaultConfig: Config = { customHTMLTags: { enabled: false, }, diff --git a/test/index.test.ts b/test/index.test.ts index d6209d4..1e52643 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -6,7 +6,7 @@ import remarkDirective from "remark-directive"; import remarkParse from "remark-parse"; import remarkRehype from "remark-rehype"; import { unified } from "unified"; -import remarkCard from "../src"; +import remarkCard, { type Config, defaultConfig } from "../src/index.js"; const normalizeHtml = (html: string) => { return html.replace(/[\n\s]*(<)|>([\n\s]*)/g, (_match, p1, _p2) => @@ -14,32 +14,34 @@ const normalizeHtml = (html: string) => { ); }; -const parseMarkdown = mock(async (markdown: string, debug = false) => { - const remarkProcessor = unified() - .use(remarkParse) - .use(remarkDirective) - .use(remarkCard) - .use(remarkRehype) - .use(rehypeStringify); - - if (debug) { - const remarkOutput = await remarkProcessor.run( - remarkProcessor.parse(markdown), - ); - console.log("Remark output:", JSON.stringify(remarkOutput, null, 2)); - } - - const output = String(await remarkProcessor.process(markdown)); - - if (debug) { - console.log( - `HTML output: +const parseMarkdown = mock( + async (markdown: string, options: Config = defaultConfig, debug = false) => { + const remarkProcessor = unified() + .use(remarkParse) + .use(remarkDirective) + .use(remarkCard, options) + .use(remarkRehype) + .use(rehypeStringify); + + if (debug) { + const remarkOutput = await remarkProcessor.run( + remarkProcessor.parse(markdown), + ); + console.log("Remark output:", JSON.stringify(remarkOutput, null, 2)); + } + + const output = String(await remarkProcessor.process(markdown)); + + if (debug) { + console.log( + `HTML output: ${normalizeHtml(output)}`, - ); - } + ); + } - return output; -}); + return output; + }, +); describe("Test the basic usage of card", () => { test("Card with single-line text & image", async () => { @@ -323,6 +325,29 @@ describe("Test the basic usage of card", () => { expect(normalizeHtml(html)).toBe(normalizeHtml(output)); }); + + test("Custom Tag Card with single-line text & image", async () => { + const input = ` + :::card + ![image alt](https://xxxxx.xxx/yyy.jpg) + Single-line text + ::: + `; + const output = ` + +
+ image alt +
+
Single-line text
+
+ `; + + const html = await parseMarkdown(input, { + customHTMLTags: { enabled: true }, + }); + + expect(normalizeHtml(html)).toBe(normalizeHtml(output)); + }); }); describe("Test the basic usage of card-grid", () => { @@ -475,4 +500,51 @@ describe("Test the basic usage of card-grid", () => { expect(normalizeHtml(html)).toBe(normalizeHtml(output)); }); + + test("Custom Tag Card grid & some cards", async () => { + const input = ` + ::::card-grid + :::card{.card-1} + ![card 1](https://xxxxx.xxx/yyy.jpg) + Card 1 + ::: + :::card{.card-2} + ![card 2](https://xxxxx.xxx/yyy.jpg) + Card 2 + ::: + :::card{.card-3} + ![card 3](https://xxxxx.xxx/yyy.jpg) + Card 3 + ::: + :::: + `; + const output = ` + + +
+ card 1 +
+
Card 1
+
+ +
+ card 2 +
+
Card 2
+
+ +
+ card 3 +
+
Card 3
+
+
+ `; + + const html = await parseMarkdown(input, { + customHTMLTags: { enabled: true }, + }); + + expect(normalizeHtml(html)).toBe(normalizeHtml(output)); + }); });