@@ -36,4 +36,42 @@ describe("htmlToMarkdown", () => {
3636 expect ( htmlToMarkdown ( "" ) ) . toBeNull ( ) ;
3737 expect ( htmlToMarkdown ( "<p></p>" ) ) . toBeNull ( ) ;
3838 } ) ;
39+
40+ it . each ( [
41+ [ "ordered-list-style numbers" , "1. First 2. Second" ] ,
42+ [ "underscores in identifiers" , "call snake_case_name here" ] ,
43+ [ "square brackets" , "an array like arr[0] and [x]" ] ,
44+ [ "leading hash and dash" , "# not a heading - not a bullet" ] ,
45+ ] ) (
46+ "does not backslash-escape plain text (%s), so it defers to native paste" ,
47+ ( _ , text ) => {
48+ // Plain punctuation must not be mangled into "1\\.", "snake\\_case", etc.
49+ // When it stays intact it equals the plain-text fallback and returns null.
50+ expect ( htmlToMarkdown ( `<span>${ text } </span>` , text ) ) . toBeNull ( ) ;
51+ } ,
52+ ) ;
53+
54+ it ( "strips macOS <style> clipboard blocks instead of leaking CSS as text" , ( ) => {
55+ // Shape of the text/html macOS puts on the clipboard when copying rich
56+ // text from native apps. The CSS must not survive into the paste.
57+ const html = [
58+ '<meta charset="utf-8">' ,
59+ "<style>" ,
60+ "<!--" ,
61+ "p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}" ,
62+ "-->" ,
63+ "</style>" ,
64+ '<p class="p1">Yo dude</p>' ,
65+ ] . join ( "\n" ) ;
66+ // No formatting beyond the plain text once the CSS is gone, so it defers.
67+ expect ( htmlToMarkdown ( html , "Yo dude" ) ) . toBeNull ( ) ;
68+ expect ( htmlToMarkdown ( html ) ) . toBe ( "Yo dude" ) ;
69+ } ) ;
70+
71+ it ( "preserves real formatting without escaping surrounding punctuation" , ( ) => {
72+ const html = "<p>See <strong>item_1.</strong> in arr[0]</p>" ;
73+ expect ( htmlToMarkdown ( html , "See item_1. in arr[0]" ) ) . toBe (
74+ "See **item_1.** in arr[0]" ,
75+ ) ;
76+ } ) ;
3977} ) ;
0 commit comments