apple-notes-mcp 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2436,19 +2436,21 @@ export class AppleNotesManager {
|
|
|
2436
2436
|
* Simple HTML to plaintext conversion for export.
|
|
2437
2437
|
*/
|
|
2438
2438
|
htmlToPlaintext(html) {
|
|
2439
|
-
return html
|
|
2439
|
+
return (html
|
|
2440
2440
|
.replace(/<br\s*\/?>/gi, "\n")
|
|
2441
2441
|
.replace(/<\/div>/gi, "\n")
|
|
2442
2442
|
.replace(/<\/p>/gi, "\n")
|
|
2443
2443
|
.replace(/<[^>]+>/g, "")
|
|
2444
2444
|
.replace(/ /g, " ")
|
|
2445
|
-
.replace(/&/g, "&")
|
|
2446
2445
|
.replace(/</g, "<")
|
|
2447
2446
|
.replace(/>/g, ">")
|
|
2448
2447
|
.replace(/"/g, '"')
|
|
2449
2448
|
.replace(/\/g, "\\")
|
|
2449
|
+
// Decode & LAST so an encoded entity like "&lt;" round-trips to the
|
|
2450
|
+
// literal "<" instead of being double-unescaped to "<".
|
|
2451
|
+
.replace(/&/g, "&")
|
|
2450
2452
|
.replace(/\n{3,}/g, "\n\n")
|
|
2451
|
-
.trim();
|
|
2453
|
+
.trim());
|
|
2452
2454
|
}
|
|
2453
2455
|
/**
|
|
2454
2456
|
* Exports all notes as a JSON structure for backup/migration.
|
|
@@ -2373,3 +2373,33 @@ describe("AppleNotesManager", () => {
|
|
|
2373
2373
|
});
|
|
2374
2374
|
});
|
|
2375
2375
|
});
|
|
2376
|
+
describe("htmlToPlaintext (export helper)", () => {
|
|
2377
|
+
// htmlToPlaintext is a private, pure string transform used by exportNote; it
|
|
2378
|
+
// touches no AppleScript, so we exercise it directly through a cast.
|
|
2379
|
+
const toPlaintext = (html) => new AppleNotesManager().htmlToPlaintext(html);
|
|
2380
|
+
it("decodes the basic HTML entities", () => {
|
|
2381
|
+
expect(toPlaintext("a & b")).toBe("a & b");
|
|
2382
|
+
expect(toPlaintext("<tag>")).toBe("<tag>");
|
|
2383
|
+
expect(toPlaintext("say "hi"")).toBe('say "hi"');
|
|
2384
|
+
expect(toPlaintext("path\file")).toBe("path\\file");
|
|
2385
|
+
expect(toPlaintext("a b")).toBe("a b");
|
|
2386
|
+
});
|
|
2387
|
+
it("decodes & last so encoded entities round-trip (no double-unescape)", () => {
|
|
2388
|
+
// The literal text "<" is stored in HTML as "&lt;" and must decode
|
|
2389
|
+
// back to "<", NOT be double-unescaped to "<".
|
|
2390
|
+
expect(toPlaintext("&lt;")).toBe("<");
|
|
2391
|
+
expect(toPlaintext("&gt;")).toBe(">");
|
|
2392
|
+
expect(toPlaintext("&amp;")).toBe("&");
|
|
2393
|
+
expect(toPlaintext("&nbsp;")).toBe(" ");
|
|
2394
|
+
});
|
|
2395
|
+
it("converts block/line tags to newlines and strips other tags", () => {
|
|
2396
|
+
expect(toPlaintext("one<br>two")).toBe("one\ntwo");
|
|
2397
|
+
expect(toPlaintext("<div>a</div><div>b</div>")).toBe("a\nb");
|
|
2398
|
+
expect(toPlaintext("<p>x</p><p>y</p>")).toBe("x\ny");
|
|
2399
|
+
expect(toPlaintext("<b>bold</b>")).toBe("bold");
|
|
2400
|
+
});
|
|
2401
|
+
it("collapses 3+ newlines and trims surrounding whitespace", () => {
|
|
2402
|
+
expect(toPlaintext("a<br><br><br><br>b")).toBe("a\n\nb");
|
|
2403
|
+
expect(toPlaintext(" <div>x</div> ")).toBe("x");
|
|
2404
|
+
});
|
|
2405
|
+
});
|
package/package.json
CHANGED