punctilio 1.4.2 → 1.7.1
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.
- package/README.md +4 -6
- package/dist/dashes.d.ts.map +1 -1
- package/dist/dashes.js +7 -3
- package/dist/dashes.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/nbsp.d.ts +75 -0
- package/dist/nbsp.d.ts.map +1 -0
- package/dist/nbsp.js +195 -0
- package/dist/nbsp.js.map +1 -0
- package/dist/symbols.js +2 -2
- package/dist/symbols.js.map +1 -1
- package/package.json +1 -1
- package/src/dashes.ts +11 -3
- package/src/index.ts +32 -2
- package/src/nbsp.ts +252 -0
- package/src/symbols.ts +2 -2
- package/src/tests/dashes.test.ts +28 -0
- package/src/tests/index.test.ts +27 -0
- package/src/tests/nbsp.test.ts +255 -0
- package/src/tests/rehype.test.ts +39 -0
- package/src/tests/symbols.test.ts +9 -0
package/src/tests/rehype.test.ts
CHANGED
|
@@ -64,6 +64,17 @@ describe("rehypePunctilio", () => {
|
|
|
64
64
|
})
|
|
65
65
|
})
|
|
66
66
|
|
|
67
|
+
describe("dashes across element boundaries", () => {
|
|
68
|
+
it.each([
|
|
69
|
+
["multi-segment number preserved", "<p>1-<em>2</em>-3</p>", "<p>1-<em>2</em>-3</p>"],
|
|
70
|
+
["model name preserved", "<p><em>GPT</em>-3</p>", "<p><em>GPT</em>-3</p>"],
|
|
71
|
+
["simple range still converts", "<p>pages <em>1</em>-5</p>", `<p>pages <em>1</em>${EN_DASH}5</p>`],
|
|
72
|
+
["genuine negative at element start", "<p><em>-5</em> degrees</p>", "<p><em>\u22125</em> degrees</p>"],
|
|
73
|
+
])("%s", async (_name, html, expected) => {
|
|
74
|
+
expect(await processHtml(html)).toEqual(expected)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
67
78
|
describe("skipped elements", () => {
|
|
68
79
|
it.each(["code", "pre", "script", "style", "kbd", "var", "samp"])(
|
|
69
80
|
"skips %s elements",
|
|
@@ -388,6 +399,34 @@ describe("rehypePunctilio", () => {
|
|
|
388
399
|
const tree = h("div", [h("img")]) as Element
|
|
389
400
|
expect(collectTransformableElements(tree, ignoreNone)).toHaveLength(0)
|
|
390
401
|
})
|
|
402
|
+
|
|
403
|
+
it("stops at max recursion depth", () => {
|
|
404
|
+
let deep: Element = h("p", "deep") as Element
|
|
405
|
+
for (let i = 0; i < 1100; i++) deep = h("div", [deep]) as Element
|
|
406
|
+
expect(collectTransformableElements(deep, ignoreNone)).toHaveLength(0)
|
|
407
|
+
})
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
describe("nbsp option", () => {
|
|
412
|
+
const NBSP = UNICODE_SYMBOLS.NBSP
|
|
413
|
+
|
|
414
|
+
it("inserts nbsp when option enabled", async () => {
|
|
415
|
+
const result = await processHtml('<p>Dr. Smith has 5 kg of items.</p>', { nbsp: true })
|
|
416
|
+
expect(result).toContain(`Dr.${NBSP}Smith`)
|
|
417
|
+
expect(result).toContain(`5${NBSP}kg`)
|
|
418
|
+
})
|
|
419
|
+
|
|
420
|
+
it("does not insert nbsp when option disabled (default)", async () => {
|
|
421
|
+
const result = await processHtml('<p>Dr. Smith has 5 kg of items.</p>')
|
|
422
|
+
expect(result).not.toContain(NBSP)
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
it("works across element boundaries", async () => {
|
|
426
|
+
const result = await processHtml('<p>See <em>Fig.</em> 1</p>', { nbsp: true })
|
|
427
|
+
expect(result).toContain(`Fig.`)
|
|
428
|
+
// The nbsp should appear between Fig. and 1
|
|
429
|
+
expect(result).toContain(NBSP)
|
|
391
430
|
})
|
|
392
431
|
})
|
|
393
432
|
|
|
@@ -595,6 +595,15 @@ describe("symbolTransform", () => {
|
|
|
595
595
|
})
|
|
596
596
|
})
|
|
597
597
|
|
|
598
|
+
describe("multiplication ReDoS regression", () => {
|
|
599
|
+
it("handles 50k digits without quadratic slowdown", () => {
|
|
600
|
+
const start = performance.now()
|
|
601
|
+
multiplication("1".repeat(50_000))
|
|
602
|
+
// Before fix: ~4400ms (O(n²)). After fix: <50ms (O(n)).
|
|
603
|
+
expect(performance.now() - start).toBeLessThan(500)
|
|
604
|
+
})
|
|
605
|
+
})
|
|
606
|
+
|
|
598
607
|
describe("multiplication edge cases", () => {
|
|
599
608
|
it.each([
|
|
600
609
|
["1000000x2000000", `1000000${UNICODE_SYMBOLS.MULTIPLICATION}2000000`],
|