Skip to content

Commit a2d5993

Browse files
committed
Added markdown attrs
1 parent cd6681e commit a2d5993

7 files changed

Lines changed: 18 additions & 1 deletion

File tree

bun.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@mdit/plugin-img-size": "^0.22.3",
2424
"commander": "^14.0.2",
2525
"markdown-it": "^14.1.0",
26+
"markdown-it-attrs": "^4.3.1",
2627
"markdown-it-image-size": "^15.0.1",
2728
"markdown-it-mathjax3": "^5.2.0",
2829
"pdf-lib": "^1.17.1",

src/utils/markdown.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ describe("markdown", () => {
4545
const result = convertMarkdownToHtml(markdown);
4646
expect(result).toContain('<div style="page-break-after: always;"></div>');
4747
});
48+
49+
test("should support attribute list syntax (markdown-it-attrs)", () => {
50+
const markdown = "### Hello {#greet .big}";
51+
const result = convertMarkdownToHtml(markdown);
52+
expect(result).toContain('<h3 id="greet" class="big">Hello</h3>');
53+
});
4854
});
4955

5056
describe("parseMarkdownIntoChunks", () => {

src/utils/markdown.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { pathToFileURL } from "url";
44
import MarkdownIt from "markdown-it";
55
import mathjax3 from "markdown-it-mathjax3";
66
import { imgSize } from "@mdit/plugin-img-size";
7+
// @ts-expect-error No types available
8+
import attrs from "markdown-it-attrs";
79
import { Chunk } from "../types";
810

911
const md = new MarkdownIt({
@@ -14,6 +16,7 @@ const md = new MarkdownIt({
1416
xhtmlOut: true,
1517
})
1618
.use(mathjax3)
19+
.use(attrs)
1720
.use(imgSize);
1821

1922
// helper: try to inline a local image file as a data URI. Returns null on

src/utils/pdf.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ describe("pdf utils", () => {
125125
</html>`;
126126
expect(mockPage.setContent).toHaveBeenCalledWith(expectedHtml, {
127127
timeout: 60000,
128-
waitUntil: "networkidle2",
128+
waitUntil: "networkidle0",
129129
});
130130
expect(mockPage.pdf).toHaveBeenCalledWith({
131131
path: outputFilePath,
132132
format: "A4",
133+
preferCSSPageSize: true,
133134
printBackground: true,
134135
});
135136
expect(mockBrowser.close).toHaveBeenCalled();

tests/fixtures/markdown/attrs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Attributes Fixture
2+
3+
## Hello {#greet}
13.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)