| 1 |
1 |
|
import { describe, expect, it } from "bun:test"; |
| 2 |
|
- |
import { parseFrontmatter, resolvePostPath } from "../src/lib/markdown"; |
|
2 |
+ |
import { |
|
3 |
+ |
parseFrontmatter, |
|
4 |
+ |
resolvePostPath, |
|
5 |
+ |
stripMarkdownForText, |
|
6 |
+ |
} from "../src/lib/markdown"; |
| 3 |
7 |
|
import type { BlogPost } from "../src/lib/types"; |
| 4 |
8 |
|
|
| 5 |
9 |
|
describe("parseFrontmatter", () => { |
|
| 415 |
419 |
|
); |
| 416 |
420 |
|
}); |
| 417 |
421 |
|
}); |
|
422 |
+ |
|
|
423 |
+ |
describe("stripMarkdownForText", () => { |
|
424 |
+ |
it("removes h1 through h6 headers", () => { |
|
425 |
+ |
expect( |
|
426 |
+ |
stripMarkdownForText("# H1\n## H2\n### H3\n#### H4\n##### H5\n###### H6"), |
|
427 |
+ |
).toBe("H1\nH2\nH3\nH4\nH5\nH6"); |
|
428 |
+ |
}); |
|
429 |
+ |
|
|
430 |
+ |
it("removes bold formatting", () => { |
|
431 |
+ |
expect(stripMarkdownForText("This is **bold** text.")).toBe( |
|
432 |
+ |
"This is bold text.", |
|
433 |
+ |
); |
|
434 |
+ |
}); |
|
435 |
+ |
|
|
436 |
+ |
it("removes italic formatting", () => { |
|
437 |
+ |
expect(stripMarkdownForText("This is *italic* text.")).toBe( |
|
438 |
+ |
"This is italic text.", |
|
439 |
+ |
); |
|
440 |
+ |
}); |
|
441 |
+ |
|
|
442 |
+ |
it("removes links but keeps link text", () => { |
|
443 |
+ |
expect(stripMarkdownForText("[click here](https://example.com)")).toBe( |
|
444 |
+ |
"click here", |
|
445 |
+ |
); |
|
446 |
+ |
}); |
|
447 |
+ |
|
|
448 |
+ |
it("removes fenced code blocks", () => { |
|
449 |
+ |
const input = "before\n```\nconst x = 1;\n```\nafter"; |
|
450 |
+ |
expect(stripMarkdownForText(input)).toBe("before\n\nafter"); |
|
451 |
+ |
}); |
|
452 |
+ |
|
|
453 |
+ |
it("removes inline code formatting", () => { |
|
454 |
+ |
expect(stripMarkdownForText("Run `npm install` to install.")).toBe( |
|
455 |
+ |
"Run npm install to install.", |
|
456 |
+ |
); |
|
457 |
+ |
}); |
|
458 |
+ |
|
|
459 |
+ |
it("removes images", () => { |
|
460 |
+ |
expect(stripMarkdownForText("before  after")).toBe( |
|
461 |
+ |
"before after", |
|
462 |
+ |
); |
|
463 |
+ |
}); |
|
464 |
+ |
|
|
465 |
+ |
it("normalizes three or more consecutive newlines to two", () => { |
|
466 |
+ |
expect(stripMarkdownForText("line 1\n\n\n\nline 2")).toBe( |
|
467 |
+ |
"line 1\n\nline 2", |
|
468 |
+ |
); |
|
469 |
+ |
}); |
|
470 |
+ |
|
|
471 |
+ |
it("removes single tilde strikethrough", () => { |
|
472 |
+ |
expect(stripMarkdownForText("~strikethrough~")).toBe("strikethrough"); |
|
473 |
+ |
}); |
|
474 |
+ |
|
|
475 |
+ |
it("removes double tilde strikethrough", () => { |
|
476 |
+ |
expect(stripMarkdownForText("~~strikethrough~~")).toBe("strikethrough"); |
|
477 |
+ |
}); |
|
478 |
+ |
|
|
479 |
+ |
it("removes HTML comments but preserves -- outside comments", () => { |
|
480 |
+ |
expect(stripMarkdownForText("a -- b <!-- c -- d --> e -- f")).toBe( |
|
481 |
+ |
"a -- b e -- f", |
|
482 |
+ |
); |
|
483 |
+ |
}); |
|
484 |
+ |
|
|
485 |
+ |
it("removes footnote definitions but not inline references", () => { |
|
486 |
+ |
const input = |
|
487 |
+ |
"Text with[^1] a reference.\n\n[^1]: The footnote definition."; |
|
488 |
+ |
expect(stripMarkdownForText(input)).toBe("Text with[^1] a reference."); |
|
489 |
+ |
}); |
|
490 |
+ |
|
|
491 |
+ |
it("trims leading and trailing whitespace", () => { |
|
492 |
+ |
expect(stripMarkdownForText("\n\nhello\n\n")).toBe("hello"); |
|
493 |
+ |
}); |
|
494 |
+ |
}); |