File size: 2,643 Bytes
0671a8c
 
 
 
 
 
 
 
 
 
90aef7e
0671a8c
 
 
 
 
 
 
 
 
 
 
 
 
 
90aef7e
 
 
 
 
 
 
 
 
 
 
 
0671a8c
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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>&nbsp;</span></span><![endif]>أنواع النفايات</p>
      <p class=MsoListParagraph style='mso-list:l0 level2 lfo1'><span style='mso-list:Ignore'>·<span>&nbsp;&nbsp;</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);
  });
});