import { test } from "uvu"; import * as assert from "uvu/assert"; import { fromHtml } from "hast-util-from-html"; import { toPlaintextTree } from "../src"; const opts = { headingTags: ["h2", "h3"] }; test("toContentTree is a function", () => { assert.type(toPlaintextTree, "function"); }); test("output tree when headings found", () => { const doc = fromHtml( `

This is text at the top

Heading A

Text under A

Heading B

Text under B

Heading C

Text under C

`, { fragment: true } ); const tree = toPlaintextTree(doc, opts); assert.is(tree.length, 3); assert.is(tree[0][0], ""); assert.is(tree[0][1], "This is text at the top"); assert.is(tree[1][0], "Heading A"); assert.is(tree[1][1], "Text under A"); assert.is(tree[2][0], "Heading B"); assert.is(tree[2][1], "Text under B Heading C Text under C"); }); test("output string when no headings", () => { const doc = fromHtml( `

Paragraph 1

Paragraph 2

Paragraph 3

`, { fragment: true } ); const text = toPlaintextTree(doc, opts); assert.is(text, "Paragraph 1 Paragraph 2 Paragraph 3"); }); test("remove or keep emoji", () => { const doc = fromHtml(`

Emoji (⌚ 🧑‍🚀 ✅)

`, { fragment: true }); const text1 = toPlaintextTree(doc, { removeEmoji: true }); assert.is(text1, "Emoji ( )"); const text2 = toPlaintextTree(doc, { removeEmoji: false }); assert.is(text2, "Emoji (⌚ 🧑‍🚀 ✅)"); }); test.run();