import { describe, expect, it } from "vitest"; import { cleanThingiverseMarkdown, htmlToMarkdown } from "../src/services/descriptionMarkdown"; describe("htmlToMarkdown", () => { it("keeps headings, emphasis, lists and step images from a MakerWorld summary", () => { const html = "

Excavator Lamp

Boost MeA boost will really support my hobby!" + "" + '

STEP 1:

' + '

 

'; expect(htmlToMarkdown(html)).toBe( [ "## Excavator Lamp", "", "- **No supports needed.**", "", "### STEP 1:", "", "![](https://makerworld.bblmw.com/a.jpg)", "", "![](https://makerworld.bblmw.com/b.gif)", ].join("\n"), ); }); it("keeps links and drops images that aren't absolute http(s) URLs", () => { const html = '

See the guide.

Side view'; expect(htmlToMarkdown(html)).toBe( "See [the guide](https://example.com/guide).\n\n![Side view](https://media.printables.com/x.jpg)", ); }); it("writes compact list markers, numbering ordered lists from their start", () => { expect(htmlToMarkdown('
  1. Print
  2. Glue
')).toBe( "3. Print\n4. Glue\n - Let it dry", ); }); it("turns a data table without a header row into a Markdown table", () => { const html = "" + "" + "" + "" + "

Plate #

Part

1

Main Hexa

5 magnets | strong

2
"; expect(htmlToMarkdown(html)).toBe( ["| **Plate #** | **Part** |", "| --- | --- |", "| 1 | Main Hexa 5 magnets \\| strong |", "| 2 | |"].join("\n"), ); }); it("unrolls a layout table into its cells' content", () => { const html = '' + '

Added covers:

'; expect(htmlToMarkdown(html)).toBe( "*Added covers:*\n\n- [Lisbon](https://makerworld.com/m/1)\n\n![](https://makerworld.bblmw.com/c.png)", ); }); it("is null for an empty description", () => { expect(htmlToMarkdown("

 

")).toBeNull(); }); }); describe("cleanThingiverseMarkdown", () => { it("leaves plain Markdown alone", () => { expect(cleanThingiverseMarkdown("# Title\n\nA **flexible** dragon.\nSecond line.")).toBe( "# Title\n\nA **flexible** dragon.\nSecond line.", ); }); it("maps inline HTML onto Markdown without losing line breaks", () => { expect( cleanThingiverseMarkdown( 'Line one
Line two\n\nx & y', ), ).toBe("Line one\nLine **two**\n![](https://cdn.thingiverse.com/a.jpg)\n[x](https://x.com) & y"); }); });