Download apps/web/src/lib/pasteMarkdown.test.ts from aliroya/contiai: direct link, hf CLI and curl.
- Browser
- Download file 2.64 kB
-
https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/web/src/lib/pasteMarkdown.test.ts
- Command line
-
hf download hf://spaces/aliroya/contiai/apps/web/src/lib/pasteMarkdown.test.ts
-
curl -L -o pasteMarkdown.test.ts https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/web/src/lib/pasteMarkdown.test.ts
2.64 kB
| import { describe, expect, it } from "vitest"; | |
| import { hasStructure, htmlToMarkdown } from "./pasteMarkdown"; | |
| describe("a formatted paste keeps its levels", () => { | |
| it("reads ChatGPT and Claude: headings and lists inside lists", () => { | |
| const html = `<h2>الفصل الأول: النفايات</h2> | |
| <ol><li>أنواع النفايات<ul><li>النفايات <strong>البيولوجية</strong></li> | |
| <li>النفايات الكيميائية</li></ul></li><li>التخلص الآمن</li></ol>`; | |
| expect(hasStructure(html)).toBe(true); | |
| expect(htmlToMarkdown(html)).toBe( | |
| "## الفصل الأول: النفايات\n1. أنواع النفايات\n - النفايات **البيولوجية**\n - النفايات الكيميائية\n1. التخلص الآمن", | |
| ); | |
| }); | |
| it("reads Word: heading styles and list paragraphs by their level, without the drawn bullet", () => { | |
| const html = `<html><head><style>p{}</style></head><body> | |
| <h1>الفصل: عندما تحدث المخاطر</h1> | |
| <p class=MsoListParagraph style='mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>1.<span> </span></span><![endif]>أنواع النفايات</p> | |
| <p class=MsoListParagraph style='mso-list:l0 level2 lfo1'><span style='mso-list:Ignore'>·<span> </span></span>النفايات البيولوجية</p> | |
| <!--[if !supportLists]--><p>نص عادي</p></body></html>`; | |
| expect(htmlToMarkdown(html)).toBe( | |
| "# الفصل: عندما تحدث المخاطر\n- أنواع النفايات\n - النفايات البيولوجية\nنص عادي", | |
| ); | |
| }); | |
| it("keeps the bullet of a list item whose words sit in a <p> (ChatGPT, Claude)", () => { | |
| const html = `<h1>TAZA | طازة</h1><p><strong>Brand Identity Design Brief</strong></p> | |
| <h3>2. طبيعة النشاط</h3><p>المشروع عبارة عن منظومة متكاملة تشمل:</p> | |
| <ul><li><p>محلات وفروع فعلية.</p></li><li><p>تطبيق موبايل.</p> | |
| <ul><li><p>طلب أونلاين</p></li></ul></li></ul><p>نص بعدها</p>`; | |
| expect(htmlToMarkdown(html)).toBe( | |
| "# TAZA | طازة\n**Brand Identity Design Brief**\n### 2. طبيعة النشاط\n" | |
| + "المشروع عبارة عن منظومة متكاملة تشمل:\n- محلات وفروع فعلية.\n- تطبيق موبايل.\n" | |
| + " - طلب أونلاين\nنص بعدها", | |
| ); | |
| }); | |
| it("leaves a paste with no structure to the box", () => { | |
| expect(hasStructure("<p>سطر</p><p>سطر آخر</p>")).toBe(false); | |
| }); | |
| }); | |