import rehypeStringify from "rehype-stringify"; import remarkParse from "remark-parse"; import remarkRehype from "remark-rehype"; import rehypeParse from "rehype-parse"; import { unified } from "unified"; import rehypeSemanticBlockquotes from "./index.ts"; import test from "node:test"; import assert from "node:assert"; const markdownTests = [ [ "Do nothing if there is no linebreak between the credit and the content", `> Better to admit you walked through the wrong door than spend your life in the wrong room. > @ Josh Davis `, `

Better to admit you walked through the wrong door than spend your life in the wrong room. @ Josh Davis

`, ], [ "Does not transform markdown link", `> Better to admit you walked through the wrong door than spend your life in the wrong room. > > @ [Josh Davis](https://somewhere.com) `, `

Better to admit you walked through the wrong door than spend your life in the wrong room.

Josh Davis

`, ], [ "Does not transform complicated markdown syntax with reveral nodes", ` > Better to admit you walked through the wrong door than spend your life in the wrong room. > > @ Credit: [Josh Davis](https://www.somewhere.com), we obtained the quote at **some website** `, `

Better to admit you walked through the wrong door than spend your life in the wrong room.

Credit: Josh Davis, we obtained the quote at some website

`, ], [ "Transforms a multi-line blockquote with a caption", ` > Better to admit you walked through the wrong door > than spend your life in the wrong room. > > @ Josh Davis `, `

Better to admit you walked through the wrong door than spend your life in the wrong room.

Josh Davis

`, ], [ "Transforms a blockquote with a nested list in the content", ` > Here are some steps: > > 1. Do this > 2. Then do that > 3. Finally, do the other thing > > @ Jane Doe `, `

Here are some steps:

  1. Do this
  2. Then do that
  3. Finally, do the other thing

Jane Doe

`, ], [ "Transforms a blockquote with inline code in the content", ` > Use the \`console.log()\` function to debug your code. > > @ John Doe `, `

Use the console.log() function to debug your code.

John Doe

`, ], ]; const htmlTests = [ [ "Transforms a simple HTML blockquote with credit", `

Simple quote.

@ Author Name

`, `

Simple quote.

Author Name

` ], [ "Handles minified HTML", `

Minified quote.

@ Author

`, `

Minified quote.

Author

` ], [ "Handles nested elements in blockquote", `

Quote with emphasis and strong.

@ Author

`, `

Quote with emphasis and strong.

Author

` ], [ "Does not transform when credit syntax is not at the end", `

@ Not at the end.

This should not transform.

`, `

@ Not at the end.

This should not transform.

` ], [ "Handles multiple paragraphs in blockquote", `

First paragraph.

Second paragraph.

@ Author

`, `

First paragraph.

Second paragraph.

Author

` ], [ "Preserves whitespace in credit", `

Quote.

@ Author with spaces

`, `

Quote.

Author with spaces

` ] ]; markdownTests.forEach(async ([message, input, expected]) => { const actual = String( await unified() .use(remarkParse) .use(remarkRehype) .use(rehypeSemanticBlockquotes) .use(rehypeStringify) .process(input), ); test(`MD -> HTML: ${message}`, () => { assert.strictEqual(actual, expected); }); }); htmlTests.forEach(async ([message, input, expected]) => { const actual = String( await unified() .use(rehypeParse) .use(rehypeSemanticBlockquotes) .use(rehypeStringify) .process(input) ); test(`HTML: ${message}`, () => { assert.strictEqual(actual, expected); }); });