@pdfme/converter 6.1.1 → 6.1.2-dev.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.
- package/README.md +51 -0
- package/dist/md2pdf.d.ts +32 -0
- package/dist/md2pdf.js +498 -0
- package/dist/md2pdf.js.map +1 -0
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -2,4 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
This library provides utility functions for converting PDFs to other formats or converting data—such as Markdown—into PDF(WIP).
|
|
4
4
|
|
|
5
|
+
## Markdown to pdfme template
|
|
6
|
+
|
|
7
|
+
`md2pdf` converts GitHub Flavored Markdown into a pdfme `Template` and `inputs` pair.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { md2pdf } from '@pdfme/converter/md2pdf';
|
|
11
|
+
|
|
12
|
+
const { template, inputs } = await md2pdf('# Hello\n\nVisit [pdfme](https://pdfme.com).');
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The initial MVP emits text, headings, lists, tables, code blocks, blockquotes, horizontal rules, and data URI images. `md2pdf` is exposed as a subpath export so normal converter imports do not pull the Markdown parser into browser bundles.
|
|
16
|
+
|
|
17
|
+
When passing the result to `generate`, register the plugins for the Markdown features you use. Horizontal rules (`---`) are emitted as `line` schemas, so documents that contain them need the `Line` plugin.
|
|
18
|
+
|
|
19
|
+
### CJK and Japanese text
|
|
20
|
+
|
|
21
|
+
The default pdfme font is Roboto, which does not include Japanese/CJK glyphs. For Japanese Markdown, set a CJK-capable `fontName` during conversion and pass the same font to `generate` or UI options.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { readFile } from 'node:fs/promises';
|
|
25
|
+
import { md2pdf } from '@pdfme/converter/md2pdf';
|
|
26
|
+
import { generate } from '@pdfme/generator';
|
|
27
|
+
import { image, line, list, table, text } from '@pdfme/schemas';
|
|
28
|
+
|
|
29
|
+
const fontData = await readFile('./fonts/NotoSansJP-Regular.ttf');
|
|
30
|
+
const { template, inputs } = await md2pdf('# 日本語\n\nこれはPDF生成のテストです。', {
|
|
31
|
+
style: { fontName: 'NotoSansJP' },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const pdf = await generate({
|
|
35
|
+
template,
|
|
36
|
+
inputs,
|
|
37
|
+
plugins: { Text: text, List: list, Table: table, Image: image, Line: line },
|
|
38
|
+
options: {
|
|
39
|
+
font: {
|
|
40
|
+
NotoSansJP: { data: fontData, fallback: true, subset: false },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Current limitations:
|
|
47
|
+
|
|
48
|
+
- Pagination is handled by pdfme dynamic layout after conversion. Long text/list/table content can split across pages, while image keep-together behavior is intentionally basic.
|
|
49
|
+
- Table cells are plain text; inline Markdown styling inside cells is stripped.
|
|
50
|
+
- Code block language tags are parsed but not rendered yet.
|
|
51
|
+
- Blockquotes are rendered as indented text with a light background, not as full nested block layouts.
|
|
52
|
+
- Remote Markdown images are emitted as links for now; image fetching/asset metadata is left for a later step.
|
|
53
|
+
- PNG/JPEG data URI images are rendered at a fixed initial height and do not preserve aspect ratio yet.
|
|
54
|
+
- Complex list item children such as nested code blocks or blockquotes are flattened into list item text.
|
|
55
|
+
|
|
5
56
|
For the complete pdfme documentation, see [this link](https://pdfme.com/docs/converter).
|
package/dist/md2pdf.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type BlankPdf, type PageOrientation, type PageSize, type Template } from '@pdfme/common';
|
|
2
|
+
type BoxSides = {
|
|
3
|
+
top?: number;
|
|
4
|
+
right?: number;
|
|
5
|
+
bottom?: number;
|
|
6
|
+
left?: number;
|
|
7
|
+
x?: number;
|
|
8
|
+
y?: number;
|
|
9
|
+
};
|
|
10
|
+
type HeadingDepth = 1 | 2 | 3 | 4 | 5 | 6;
|
|
11
|
+
type MarkdownMargin = number | [number, number, number, number] | BoxSides;
|
|
12
|
+
export type Md2PdfOptions = {
|
|
13
|
+
page?: {
|
|
14
|
+
size?: PageSize;
|
|
15
|
+
orientation?: PageOrientation;
|
|
16
|
+
margin?: MarkdownMargin;
|
|
17
|
+
};
|
|
18
|
+
basePdf?: BlankPdf;
|
|
19
|
+
style?: {
|
|
20
|
+
fontName?: string;
|
|
21
|
+
fontSize?: number;
|
|
22
|
+
lineHeight?: number;
|
|
23
|
+
fontColor?: string;
|
|
24
|
+
headingScale?: Partial<Record<HeadingDepth, number>>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export type Md2PdfResult = {
|
|
28
|
+
template: Template;
|
|
29
|
+
inputs: Record<string, string>[];
|
|
30
|
+
};
|
|
31
|
+
export declare const md2pdf: (markdown: string, options?: Md2PdfOptions) => Promise<Md2PdfResult>;
|
|
32
|
+
export {};
|
package/dist/md2pdf.js
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { normalizeLinkHref, pt2mm, resolvePageSize } from "@pdfme/common";
|
|
2
|
+
import remarkGfm from "remark-gfm";
|
|
3
|
+
import remarkParse from "remark-parse";
|
|
4
|
+
import { unified } from "unified";
|
|
5
|
+
//#region src/md2pdf.ts
|
|
6
|
+
var DEFAULT_PAGE_MARGIN = [
|
|
7
|
+
20,
|
|
8
|
+
15,
|
|
9
|
+
20,
|
|
10
|
+
15
|
|
11
|
+
];
|
|
12
|
+
var DEFAULT_FONT_SIZE = 10;
|
|
13
|
+
var DEFAULT_LINE_HEIGHT = 1.25;
|
|
14
|
+
var DEFAULT_FONT_COLOR = "#111827";
|
|
15
|
+
var DEFAULT_HEADING_SCALE = {
|
|
16
|
+
1: 2,
|
|
17
|
+
2: 1.65,
|
|
18
|
+
3: 1.35,
|
|
19
|
+
4: 1.15,
|
|
20
|
+
5: 1,
|
|
21
|
+
6: 1
|
|
22
|
+
};
|
|
23
|
+
var BLOCK_GAP = 4;
|
|
24
|
+
var LIST_ITEM_SPACING = 1.4;
|
|
25
|
+
var TABLE_HEADER_HEIGHT = 8.5;
|
|
26
|
+
var TABLE_ROW_HEIGHT = 7.5;
|
|
27
|
+
var IMAGE_HEIGHT = 45;
|
|
28
|
+
var CODE_BLOCK_BACKGROUND_COLOR = "#f6f8fa";
|
|
29
|
+
var CODE_BLOCK_BORDER_COLOR = "#d0d7de";
|
|
30
|
+
var CODE_BLOCK_BORDER_WIDTH = .1;
|
|
31
|
+
var CODE_BLOCK_PADDING = {
|
|
32
|
+
top: 2,
|
|
33
|
+
right: 3,
|
|
34
|
+
bottom: 2,
|
|
35
|
+
left: 3
|
|
36
|
+
};
|
|
37
|
+
var BLOCKQUOTE_BACKGROUND_COLOR = "#f8fafc";
|
|
38
|
+
var BLOCKQUOTE_BORDER_COLOR = "#d0d7de";
|
|
39
|
+
var BLOCKQUOTE_BORDER_WIDTH = {
|
|
40
|
+
top: 0,
|
|
41
|
+
right: 0,
|
|
42
|
+
bottom: 0,
|
|
43
|
+
left: .8
|
|
44
|
+
};
|
|
45
|
+
var BLOCKQUOTE_PADDING = {
|
|
46
|
+
top: 2,
|
|
47
|
+
right: 3,
|
|
48
|
+
bottom: 2,
|
|
49
|
+
left: 3
|
|
50
|
+
};
|
|
51
|
+
var HORIZONTAL_RULE_COLOR = "#d0d7de";
|
|
52
|
+
var HORIZONTAL_RULE_HEIGHT = .25;
|
|
53
|
+
var TABLE_BORDER_COLOR = "#d0d7de";
|
|
54
|
+
var TABLE_CELL_BORDER_WIDTH = .1;
|
|
55
|
+
var TABLE_HEAD_BACKGROUND_COLOR = "#f6f8fa";
|
|
56
|
+
var TABLE_BODY_ALTERNATE_BACKGROUND_COLOR = "#f9fafb";
|
|
57
|
+
var TABLE_CELL_PADDING = 3;
|
|
58
|
+
var MARKDOWN_ESCAPE_PATTERN = /[\\*~`[\]()]/g;
|
|
59
|
+
var DATA_IMAGE_PATTERN = /^data:image\/(?:png|jpe?g);base64,/i;
|
|
60
|
+
var RENDERABLE_BLOCK_TYPES = new Set([
|
|
61
|
+
"blockquote",
|
|
62
|
+
"code",
|
|
63
|
+
"heading",
|
|
64
|
+
"html",
|
|
65
|
+
"list",
|
|
66
|
+
"paragraph",
|
|
67
|
+
"table",
|
|
68
|
+
"thematicBreak"
|
|
69
|
+
]);
|
|
70
|
+
var markdownProcessor = unified().use(remarkParse).use(remarkGfm);
|
|
71
|
+
var md2pdf = async (markdown, options = {}) => {
|
|
72
|
+
const root = markdownProcessor.parse(markdown);
|
|
73
|
+
const builder = createBuilder(options);
|
|
74
|
+
root.children.forEach((node) => renderBlock(node, builder));
|
|
75
|
+
return {
|
|
76
|
+
template: {
|
|
77
|
+
basePdf: builder.basePdf,
|
|
78
|
+
schemas: [builder.schemas]
|
|
79
|
+
},
|
|
80
|
+
inputs: [{}]
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
var createBuilder = (options) => {
|
|
84
|
+
const basePdf = options.basePdf ?? createBlankPdf(options);
|
|
85
|
+
const [top, right, bottom, left] = basePdf.padding;
|
|
86
|
+
const headingScale = {
|
|
87
|
+
...DEFAULT_HEADING_SCALE,
|
|
88
|
+
...options.style?.headingScale
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
basePdf,
|
|
92
|
+
contentFrame: {
|
|
93
|
+
x: left,
|
|
94
|
+
y: top,
|
|
95
|
+
width: Math.max(0, basePdf.width - left - right),
|
|
96
|
+
height: Math.max(0, basePdf.height - top - bottom)
|
|
97
|
+
},
|
|
98
|
+
cursorY: top,
|
|
99
|
+
fontName: options.style?.fontName,
|
|
100
|
+
fontSize: options.style?.fontSize ?? DEFAULT_FONT_SIZE,
|
|
101
|
+
lineHeight: options.style?.lineHeight ?? DEFAULT_LINE_HEIGHT,
|
|
102
|
+
fontColor: options.style?.fontColor ?? DEFAULT_FONT_COLOR,
|
|
103
|
+
headingScale,
|
|
104
|
+
nameCounters: {},
|
|
105
|
+
schemas: [],
|
|
106
|
+
usedNames: /* @__PURE__ */ new Set()
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
var createBlankPdf = (options) => {
|
|
110
|
+
const pageSize = resolvePageSize(options.page?.size ?? "A4", options.page?.orientation ?? "portrait");
|
|
111
|
+
return {
|
|
112
|
+
width: pageSize.width,
|
|
113
|
+
height: pageSize.height,
|
|
114
|
+
padding: resolveMargin(options.page?.margin ?? DEFAULT_PAGE_MARGIN)
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
var resolveMargin = (margin) => {
|
|
118
|
+
if (typeof margin === "number") return [
|
|
119
|
+
margin,
|
|
120
|
+
margin,
|
|
121
|
+
margin,
|
|
122
|
+
margin
|
|
123
|
+
];
|
|
124
|
+
if (Array.isArray(margin)) return margin;
|
|
125
|
+
const x = margin.x ?? 0;
|
|
126
|
+
const y = margin.y ?? 0;
|
|
127
|
+
return [
|
|
128
|
+
margin.top ?? y,
|
|
129
|
+
margin.right ?? x,
|
|
130
|
+
margin.bottom ?? y,
|
|
131
|
+
margin.left ?? x
|
|
132
|
+
];
|
|
133
|
+
};
|
|
134
|
+
var renderBlock = (node, builder) => {
|
|
135
|
+
switch (node.type) {
|
|
136
|
+
case "heading":
|
|
137
|
+
renderHeading(node, builder);
|
|
138
|
+
return;
|
|
139
|
+
case "paragraph":
|
|
140
|
+
renderParagraph(node, builder);
|
|
141
|
+
return;
|
|
142
|
+
case "list":
|
|
143
|
+
renderList(node, builder);
|
|
144
|
+
return;
|
|
145
|
+
case "code":
|
|
146
|
+
renderCode(node, builder);
|
|
147
|
+
return;
|
|
148
|
+
case "blockquote":
|
|
149
|
+
renderBlockquote(node, builder);
|
|
150
|
+
return;
|
|
151
|
+
case "table":
|
|
152
|
+
renderTable(node, builder);
|
|
153
|
+
return;
|
|
154
|
+
case "thematicBreak":
|
|
155
|
+
renderLine(builder);
|
|
156
|
+
return;
|
|
157
|
+
case "html":
|
|
158
|
+
case "definition":
|
|
159
|
+
case "footnoteDefinition":
|
|
160
|
+
case "yaml": return;
|
|
161
|
+
default: renderNestedBlocks(node, builder);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var renderNestedBlocks = (node, builder) => {
|
|
165
|
+
if ("children" in node && Array.isArray(node.children)) node.children.forEach((child) => {
|
|
166
|
+
if (isBlockContent(child)) renderBlock(child, builder);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
var renderHeading = (node, builder) => {
|
|
170
|
+
const depth = Math.min(Math.max(node.depth, 1), 6);
|
|
171
|
+
const content = renderInlineChildren(node.children);
|
|
172
|
+
const fontSize = builder.fontSize * builder.headingScale[depth];
|
|
173
|
+
addTextSchema(builder, {
|
|
174
|
+
name: resolveName(builder, slugify(toPlainText(node)) || `heading_${depth}`),
|
|
175
|
+
content,
|
|
176
|
+
fontSize,
|
|
177
|
+
height: estimateTextHeight(content, fontSize, builder.lineHeight),
|
|
178
|
+
gap: depth <= 1 ? 5 : depth === 2 ? 4.5 : BLOCK_GAP,
|
|
179
|
+
textFormat: "inline-markdown"
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
var renderParagraph = (node, builder) => {
|
|
183
|
+
if (node.children.length === 1 && node.children[0]?.type === "image") {
|
|
184
|
+
renderImage(node.children[0], builder);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const content = renderInlineChildren(node.children);
|
|
188
|
+
if (!content.trim()) return;
|
|
189
|
+
addTextSchema(builder, {
|
|
190
|
+
content,
|
|
191
|
+
textFormat: "inline-markdown"
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
var renderList = (node, builder) => {
|
|
195
|
+
const items = collectListItems(node);
|
|
196
|
+
if (items.length === 0) return;
|
|
197
|
+
const fontSize = builder.fontSize;
|
|
198
|
+
const height = items.length * estimateTextHeight("", fontSize, builder.lineHeight) + Math.max(0, items.length - 1) * LIST_ITEM_SPACING;
|
|
199
|
+
addSchema(builder, {
|
|
200
|
+
name: resolveAutoName(builder, "list"),
|
|
201
|
+
type: "list",
|
|
202
|
+
content: JSON.stringify(items),
|
|
203
|
+
position: {
|
|
204
|
+
x: builder.contentFrame.x,
|
|
205
|
+
y: builder.cursorY
|
|
206
|
+
},
|
|
207
|
+
width: builder.contentFrame.width,
|
|
208
|
+
height,
|
|
209
|
+
readOnly: true,
|
|
210
|
+
alignment: "left",
|
|
211
|
+
verticalAlignment: "top",
|
|
212
|
+
fontSize,
|
|
213
|
+
fontName: builder.fontName,
|
|
214
|
+
lineHeight: builder.lineHeight,
|
|
215
|
+
characterSpacing: 0,
|
|
216
|
+
fontColor: builder.fontColor,
|
|
217
|
+
backgroundColor: "",
|
|
218
|
+
listStyle: node.ordered ? "ordered" : "bullet",
|
|
219
|
+
markerWidth: 6,
|
|
220
|
+
markerGap: 2,
|
|
221
|
+
indentSize: 6,
|
|
222
|
+
itemSpacing: LIST_ITEM_SPACING,
|
|
223
|
+
textFormat: "inline-markdown",
|
|
224
|
+
overflow: "expand"
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
var renderCode = (node, builder) => {
|
|
228
|
+
const content = node.value;
|
|
229
|
+
addTextSchema(builder, {
|
|
230
|
+
content,
|
|
231
|
+
backgroundColor: CODE_BLOCK_BACKGROUND_COLOR,
|
|
232
|
+
borderColor: CODE_BLOCK_BORDER_COLOR,
|
|
233
|
+
borderWidth: resolveBoxSides(CODE_BLOCK_BORDER_WIDTH),
|
|
234
|
+
padding: CODE_BLOCK_PADDING,
|
|
235
|
+
textFormat: "plain"
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
var renderBlockquote = (node, builder) => {
|
|
239
|
+
const content = node.children.map((child) => blockToMarkdown(child)).join("\n").trim();
|
|
240
|
+
if (!content.trim()) return;
|
|
241
|
+
addTextSchema(builder, {
|
|
242
|
+
content,
|
|
243
|
+
backgroundColor: BLOCKQUOTE_BACKGROUND_COLOR,
|
|
244
|
+
borderColor: BLOCKQUOTE_BORDER_COLOR,
|
|
245
|
+
borderWidth: BLOCKQUOTE_BORDER_WIDTH,
|
|
246
|
+
padding: BLOCKQUOTE_PADDING,
|
|
247
|
+
textFormat: "inline-markdown"
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
var renderTable = (node, builder) => {
|
|
251
|
+
const rows = node.children.map(tableRowToStrings).filter((row) => row.length > 0);
|
|
252
|
+
if (rows.length === 0) return;
|
|
253
|
+
const columnCount = Math.max(...rows.map((row) => row.length));
|
|
254
|
+
const head = normalizeRowLength(rows[0], columnCount);
|
|
255
|
+
const body = rows.slice(1).map((row) => normalizeRowLength(row, columnCount));
|
|
256
|
+
const height = TABLE_HEADER_HEIGHT + Math.max(1, body.length) * TABLE_ROW_HEIGHT;
|
|
257
|
+
const columnWidths = Array.from({ length: columnCount }, () => 100 / columnCount);
|
|
258
|
+
addSchema(builder, {
|
|
259
|
+
name: resolveAutoName(builder, "table"),
|
|
260
|
+
type: "table",
|
|
261
|
+
content: JSON.stringify(body),
|
|
262
|
+
position: {
|
|
263
|
+
x: builder.contentFrame.x,
|
|
264
|
+
y: builder.cursorY
|
|
265
|
+
},
|
|
266
|
+
width: builder.contentFrame.width,
|
|
267
|
+
height,
|
|
268
|
+
readOnly: true,
|
|
269
|
+
showHead: true,
|
|
270
|
+
repeatHead: false,
|
|
271
|
+
head,
|
|
272
|
+
headWidthPercentages: columnWidths,
|
|
273
|
+
tableStyles: {
|
|
274
|
+
borderColor: TABLE_BORDER_COLOR,
|
|
275
|
+
borderWidth: .2
|
|
276
|
+
},
|
|
277
|
+
headStyles: {
|
|
278
|
+
...defaultCellStyle(builder),
|
|
279
|
+
backgroundColor: TABLE_HEAD_BACKGROUND_COLOR,
|
|
280
|
+
borderColor: TABLE_BORDER_COLOR,
|
|
281
|
+
borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH)
|
|
282
|
+
},
|
|
283
|
+
bodyStyles: {
|
|
284
|
+
...defaultCellStyle(builder),
|
|
285
|
+
borderColor: TABLE_BORDER_COLOR,
|
|
286
|
+
borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH),
|
|
287
|
+
alternateBackgroundColor: TABLE_BODY_ALTERNATE_BACKGROUND_COLOR
|
|
288
|
+
},
|
|
289
|
+
columnStyles: {}
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
var renderImage = (node, builder) => {
|
|
293
|
+
if (!DATA_IMAGE_PATTERN.test(node.url)) {
|
|
294
|
+
const link = normalizeLinkHref(node.url);
|
|
295
|
+
const label = node.alt || node.title || node.url;
|
|
296
|
+
addTextSchema(builder, {
|
|
297
|
+
content: link ? `[${escapeInlineMarkdown(label)}](${escapeLinkDestination(link)})` : escapeInlineMarkdown(label),
|
|
298
|
+
textFormat: "inline-markdown"
|
|
299
|
+
});
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
addSchema(builder, {
|
|
303
|
+
name: resolveAutoName(builder, "image"),
|
|
304
|
+
type: "image",
|
|
305
|
+
content: node.url,
|
|
306
|
+
position: {
|
|
307
|
+
x: builder.contentFrame.x,
|
|
308
|
+
y: builder.cursorY
|
|
309
|
+
},
|
|
310
|
+
width: builder.contentFrame.width,
|
|
311
|
+
height: IMAGE_HEIGHT,
|
|
312
|
+
readOnly: true
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
var renderLine = (builder) => {
|
|
316
|
+
addSchema(builder, {
|
|
317
|
+
name: resolveAutoName(builder, "line"),
|
|
318
|
+
type: "line",
|
|
319
|
+
position: {
|
|
320
|
+
x: builder.contentFrame.x,
|
|
321
|
+
y: builder.cursorY
|
|
322
|
+
},
|
|
323
|
+
width: builder.contentFrame.width,
|
|
324
|
+
height: HORIZONTAL_RULE_HEIGHT,
|
|
325
|
+
readOnly: true,
|
|
326
|
+
color: HORIZONTAL_RULE_COLOR
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
var addTextSchema = (builder, options) => {
|
|
330
|
+
const fontSize = options.fontSize ?? builder.fontSize;
|
|
331
|
+
const content = options.content;
|
|
332
|
+
const boxVerticalInset = getBoxVerticalInset(options);
|
|
333
|
+
addSchema(builder, {
|
|
334
|
+
name: options.name ?? resolveAutoName(builder, "text"),
|
|
335
|
+
type: "text",
|
|
336
|
+
content,
|
|
337
|
+
position: {
|
|
338
|
+
x: options.x ?? builder.contentFrame.x,
|
|
339
|
+
y: builder.cursorY
|
|
340
|
+
},
|
|
341
|
+
width: options.width ?? builder.contentFrame.width,
|
|
342
|
+
height: (options.height ?? estimateTextHeight(content, fontSize, builder.lineHeight)) + boxVerticalInset,
|
|
343
|
+
readOnly: true,
|
|
344
|
+
alignment: "left",
|
|
345
|
+
verticalAlignment: "top",
|
|
346
|
+
fontSize,
|
|
347
|
+
fontName: builder.fontName,
|
|
348
|
+
lineHeight: builder.lineHeight,
|
|
349
|
+
characterSpacing: 0,
|
|
350
|
+
fontColor: builder.fontColor,
|
|
351
|
+
backgroundColor: options.backgroundColor ?? "",
|
|
352
|
+
borderColor: options.borderColor,
|
|
353
|
+
borderWidth: options.borderWidth,
|
|
354
|
+
padding: options.padding,
|
|
355
|
+
textFormat: options.textFormat ?? "plain",
|
|
356
|
+
overflow: "expand"
|
|
357
|
+
}, options.gap);
|
|
358
|
+
};
|
|
359
|
+
var addSchema = (builder, schema, gap = BLOCK_GAP) => {
|
|
360
|
+
builder.schemas.push(schema);
|
|
361
|
+
builder.cursorY += schema.height + gap;
|
|
362
|
+
};
|
|
363
|
+
var collectListItems = (node, level = 0) => node.children.flatMap((item) => {
|
|
364
|
+
const prefix = typeof item.checked === "boolean" ? `[${item.checked ? "x" : " "}] ` : "";
|
|
365
|
+
const text = item.children.filter((child) => child.type !== "list").map((child) => blockToMarkdown(child)).join(" ").trim();
|
|
366
|
+
return [`${" ".repeat(level)}${prefix}${text}`, ...item.children.filter(isList).flatMap((child) => collectListItems(child, level + 1))];
|
|
367
|
+
});
|
|
368
|
+
var blockToMarkdown = (node) => {
|
|
369
|
+
switch (node.type) {
|
|
370
|
+
case "paragraph":
|
|
371
|
+
case "heading": return renderInlineChildren(node.children);
|
|
372
|
+
case "code": return node.value;
|
|
373
|
+
case "list": return collectListItems(node).join("\n");
|
|
374
|
+
case "blockquote": return node.children.map(blockToMarkdown).join("\n");
|
|
375
|
+
case "table": return node.children.map((row) => tableRowToStrings(row).join(" | ")).join("\n");
|
|
376
|
+
case "thematicBreak": return "---";
|
|
377
|
+
default: return "";
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
var renderInlineChildren = (children) => children.map(renderInline).join("");
|
|
381
|
+
var renderInline = (node) => {
|
|
382
|
+
switch (node.type) {
|
|
383
|
+
case "text": return escapeInlineMarkdown(node.value);
|
|
384
|
+
case "emphasis": return `*${renderInlineChildren(node.children)}*`;
|
|
385
|
+
case "strong": return `**${renderInlineChildren(node.children)}**`;
|
|
386
|
+
case "delete": return `~~${renderInlineChildren(node.children)}~~`;
|
|
387
|
+
case "inlineCode": return renderInlineCode(node);
|
|
388
|
+
case "break": return "\n";
|
|
389
|
+
case "link": return renderLink(node);
|
|
390
|
+
case "image": return renderInlineImage(node);
|
|
391
|
+
case "html": return "";
|
|
392
|
+
default: return "children" in node && Array.isArray(node.children) ? renderInlineChildren(node.children) : "";
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
var renderInlineCode = (node) => `\`${node.value.replaceAll("`", "\\`")}\``;
|
|
396
|
+
var renderLink = (node) => {
|
|
397
|
+
const label = renderInlineChildren(node.children);
|
|
398
|
+
const href = normalizeLinkHref(node.url);
|
|
399
|
+
if (!href) return label;
|
|
400
|
+
return `[${label}](${escapeLinkDestination(href)})`;
|
|
401
|
+
};
|
|
402
|
+
var renderInlineImage = (node) => {
|
|
403
|
+
const label = node.alt || node.title || node.url;
|
|
404
|
+
const href = normalizeLinkHref(node.url);
|
|
405
|
+
if (!href) return escapeInlineMarkdown(label);
|
|
406
|
+
return `[${escapeInlineMarkdown(label)}](${escapeLinkDestination(href)})`;
|
|
407
|
+
};
|
|
408
|
+
var tableRowToStrings = (row) => row.children.map(tableCellToString);
|
|
409
|
+
var tableCellToString = (cell) => cell.children.map(inlineToPlainText).join("");
|
|
410
|
+
var normalizeRowLength = (row, columnCount) => Array.from({ length: columnCount }, (_, index) => row[index] ?? "");
|
|
411
|
+
var defaultCellStyle = (builder) => ({
|
|
412
|
+
fontName: builder.fontName,
|
|
413
|
+
alignment: "left",
|
|
414
|
+
verticalAlignment: "middle",
|
|
415
|
+
fontSize: builder.fontSize,
|
|
416
|
+
lineHeight: builder.lineHeight,
|
|
417
|
+
characterSpacing: 0,
|
|
418
|
+
fontColor: builder.fontColor,
|
|
419
|
+
backgroundColor: "#ffffff",
|
|
420
|
+
borderColor: TABLE_BORDER_COLOR,
|
|
421
|
+
borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH),
|
|
422
|
+
padding: resolveBoxSides(TABLE_CELL_PADDING)
|
|
423
|
+
});
|
|
424
|
+
var resolveBoxSides = (value) => {
|
|
425
|
+
if (typeof value === "number") return {
|
|
426
|
+
top: value,
|
|
427
|
+
right: value,
|
|
428
|
+
bottom: value,
|
|
429
|
+
left: value
|
|
430
|
+
};
|
|
431
|
+
const x = value.x ?? 0;
|
|
432
|
+
const y = value.y ?? 0;
|
|
433
|
+
return {
|
|
434
|
+
top: value.top ?? y,
|
|
435
|
+
right: value.right ?? x,
|
|
436
|
+
bottom: value.bottom ?? y,
|
|
437
|
+
left: value.left ?? x
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
var getBoxVerticalInset = (value) => (value.borderWidth?.top ?? 0) + (value.borderWidth?.bottom ?? 0) + (value.padding?.top ?? 0) + (value.padding?.bottom ?? 0);
|
|
441
|
+
var resolveAutoName = (builder, prefix) => {
|
|
442
|
+
let name = "";
|
|
443
|
+
do {
|
|
444
|
+
builder.nameCounters[prefix] = (builder.nameCounters[prefix] ?? 0) + 1;
|
|
445
|
+
name = `${prefix}_${builder.nameCounters[prefix]}`;
|
|
446
|
+
} while (builder.usedNames.has(name));
|
|
447
|
+
builder.usedNames.add(name);
|
|
448
|
+
return name;
|
|
449
|
+
};
|
|
450
|
+
var resolveName = (builder, baseName) => {
|
|
451
|
+
let name = baseName;
|
|
452
|
+
let index = 0;
|
|
453
|
+
while (builder.usedNames.has(name)) {
|
|
454
|
+
index += 1;
|
|
455
|
+
name = `${baseName}_${index}`;
|
|
456
|
+
}
|
|
457
|
+
builder.usedNames.add(name);
|
|
458
|
+
return name;
|
|
459
|
+
};
|
|
460
|
+
var estimateTextHeight = (content, fontSize, lineHeight) => {
|
|
461
|
+
const lineCount = Math.max(1, content.split("\n").length);
|
|
462
|
+
return Math.max(4, lineCount * pt2mm(fontSize * lineHeight) + 1);
|
|
463
|
+
};
|
|
464
|
+
var escapeInlineMarkdown = (value) => value.replace(MARKDOWN_ESCAPE_PATTERN, (match) => `\\${match}`);
|
|
465
|
+
var escapeLinkDestination = (href) => encodeURI(href).replace(/[\\()]/g, (match) => `\\${match}`);
|
|
466
|
+
var slugify = (value) => value.trim().toLowerCase().replace(/[^\p{Letter}\p{Number}]+/gu, "-").replace(/^-|-$/g, "");
|
|
467
|
+
var toPlainText = (node) => node.children.map((child) => {
|
|
468
|
+
if ("value" in child && typeof child.value === "string") return child.value;
|
|
469
|
+
if ("alt" in child && typeof child.alt === "string") return child.alt;
|
|
470
|
+
if ("children" in child && Array.isArray(child.children)) return child.children.map((grandchild) => toPlainInlineText(grandchild)).join("");
|
|
471
|
+
return "";
|
|
472
|
+
}).join("");
|
|
473
|
+
var toPlainInlineText = (node) => {
|
|
474
|
+
if ("value" in node && typeof node.value === "string") return node.value;
|
|
475
|
+
if ("alt" in node && typeof node.alt === "string") return node.alt;
|
|
476
|
+
if ("children" in node && Array.isArray(node.children)) return node.children.map(toPlainInlineText).join("");
|
|
477
|
+
return "";
|
|
478
|
+
};
|
|
479
|
+
var inlineToPlainText = (node) => {
|
|
480
|
+
switch (node.type) {
|
|
481
|
+
case "text":
|
|
482
|
+
case "inlineCode": return node.value;
|
|
483
|
+
case "break": return "\n";
|
|
484
|
+
case "image": return node.alt || node.title || node.url;
|
|
485
|
+
case "link":
|
|
486
|
+
case "emphasis":
|
|
487
|
+
case "strong":
|
|
488
|
+
case "delete": return node.children.map(inlineToPlainText).join("");
|
|
489
|
+
case "html": return "";
|
|
490
|
+
default: return "children" in node && Array.isArray(node.children) ? node.children.map(inlineToPlainText).join("") : "";
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var isBlockContent = (node) => typeof node === "object" && node !== null && "type" in node && typeof node.type === "string" && RENDERABLE_BLOCK_TYPES.has(node.type);
|
|
494
|
+
var isList = (node) => node.type === "list";
|
|
495
|
+
//#endregion
|
|
496
|
+
export { md2pdf };
|
|
497
|
+
|
|
498
|
+
//# sourceMappingURL=md2pdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"md2pdf.js","names":[],"sources":["../src/md2pdf.ts"],"sourcesContent":["import {\n normalizeLinkHref,\n pt2mm,\n resolvePageSize,\n type BlankPdf,\n type PageOrientation,\n type PageSize,\n type Schema,\n type Template,\n} from '@pdfme/common';\nimport type {\n BlockContent,\n Blockquote,\n Code,\n Heading,\n Image,\n InlineCode,\n Link,\n List,\n ListItem,\n Paragraph,\n PhrasingContent,\n Root,\n RootContent,\n Table,\n TableCell,\n TableRow,\n} from 'mdast';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport { unified } from 'unified';\n\ntype BoxSides = {\n top?: number;\n right?: number;\n bottom?: number;\n left?: number;\n x?: number;\n y?: number;\n};\ntype ResolvedBoxSides = { top: number; right: number; bottom: number; left: number };\ntype HeadingDepth = 1 | 2 | 3 | 4 | 5 | 6;\ntype MarkdownMargin = number | [number, number, number, number] | BoxSides;\n\nexport type Md2PdfOptions = {\n page?: {\n size?: PageSize;\n orientation?: PageOrientation;\n margin?: MarkdownMargin;\n };\n basePdf?: BlankPdf;\n style?: {\n fontName?: string;\n fontSize?: number;\n lineHeight?: number;\n fontColor?: string;\n headingScale?: Partial<Record<HeadingDepth, number>>;\n };\n};\n\nexport type Md2PdfResult = {\n template: Template;\n inputs: Record<string, string>[];\n};\n\ntype Builder = {\n basePdf: BlankPdf;\n contentFrame: { x: number; y: number; width: number; height: number };\n cursorY: number;\n fontName?: string;\n fontSize: number;\n lineHeight: number;\n fontColor: string;\n headingScale: Record<HeadingDepth, number>;\n nameCounters: Record<string, number>;\n schemas: Schema[];\n usedNames: Set<string>;\n};\n\ntype TableCellStyle = {\n fontName?: string;\n alignment: 'left' | 'center' | 'right';\n verticalAlignment: 'top' | 'middle' | 'bottom';\n fontSize: number;\n lineHeight: number;\n characterSpacing: number;\n fontColor: string;\n backgroundColor: string;\n borderColor: string;\n borderWidth: ResolvedBoxSides;\n padding: ResolvedBoxSides;\n alternateBackgroundColor?: string;\n};\n\nconst DEFAULT_PAGE_MARGIN: [number, number, number, number] = [20, 15, 20, 15];\nconst DEFAULT_FONT_SIZE = 10;\nconst DEFAULT_LINE_HEIGHT = 1.25;\nconst DEFAULT_FONT_COLOR = '#111827';\nconst DEFAULT_HEADING_SCALE: Record<HeadingDepth, number> = {\n 1: 2,\n 2: 1.65,\n 3: 1.35,\n 4: 1.15,\n 5: 1,\n 6: 1,\n};\nconst BLOCK_GAP = 4;\nconst LIST_ITEM_SPACING = 1.4;\nconst TABLE_HEADER_HEIGHT = 8.5;\nconst TABLE_ROW_HEIGHT = 7.5;\nconst IMAGE_HEIGHT = 45;\nconst CODE_BLOCK_BACKGROUND_COLOR = '#f6f8fa';\nconst CODE_BLOCK_BORDER_COLOR = '#d0d7de';\nconst CODE_BLOCK_BORDER_WIDTH = 0.1;\nconst CODE_BLOCK_PADDING: ResolvedBoxSides = { top: 2, right: 3, bottom: 2, left: 3 };\nconst BLOCKQUOTE_BACKGROUND_COLOR = '#f8fafc';\nconst BLOCKQUOTE_BORDER_COLOR = '#d0d7de';\nconst BLOCKQUOTE_BORDER_WIDTH: ResolvedBoxSides = { top: 0, right: 0, bottom: 0, left: 0.8 };\nconst BLOCKQUOTE_PADDING: ResolvedBoxSides = { top: 2, right: 3, bottom: 2, left: 3 };\nconst HORIZONTAL_RULE_COLOR = '#d0d7de';\nconst HORIZONTAL_RULE_HEIGHT = 0.25;\nconst TABLE_BORDER_COLOR = '#d0d7de';\nconst TABLE_CELL_BORDER_WIDTH = 0.1;\nconst TABLE_HEAD_BACKGROUND_COLOR = '#f6f8fa';\nconst TABLE_BODY_ALTERNATE_BACKGROUND_COLOR = '#f9fafb';\nconst TABLE_CELL_PADDING = 3;\n\nconst MARKDOWN_ESCAPE_PATTERN = /[\\\\*~`[\\]()]/g;\nconst DATA_IMAGE_PATTERN = /^data:image\\/(?:png|jpe?g);base64,/i;\nconst RENDERABLE_BLOCK_TYPES = new Set([\n 'blockquote',\n 'code',\n 'heading',\n 'html',\n 'list',\n 'paragraph',\n 'table',\n 'thematicBreak',\n]);\n\nconst markdownProcessor = unified().use(remarkParse).use(remarkGfm);\n\nexport const md2pdf = async (\n markdown: string,\n options: Md2PdfOptions = {},\n): Promise<Md2PdfResult> => {\n const root = markdownProcessor.parse(markdown) as Root;\n const builder = createBuilder(options);\n\n root.children.forEach((node) => renderBlock(node, builder));\n\n return {\n template: {\n basePdf: builder.basePdf,\n schemas: [builder.schemas],\n },\n inputs: [{}],\n };\n};\n\nconst createBuilder = (options: Md2PdfOptions): Builder => {\n const basePdf = options.basePdf ?? createBlankPdf(options);\n const [top, right, bottom, left] = basePdf.padding;\n const headingScale = { ...DEFAULT_HEADING_SCALE, ...options.style?.headingScale };\n\n return {\n basePdf,\n contentFrame: {\n x: left,\n y: top,\n width: Math.max(0, basePdf.width - left - right),\n height: Math.max(0, basePdf.height - top - bottom),\n },\n cursorY: top,\n fontName: options.style?.fontName,\n fontSize: options.style?.fontSize ?? DEFAULT_FONT_SIZE,\n lineHeight: options.style?.lineHeight ?? DEFAULT_LINE_HEIGHT,\n fontColor: options.style?.fontColor ?? DEFAULT_FONT_COLOR,\n headingScale,\n nameCounters: {},\n schemas: [],\n usedNames: new Set(),\n };\n};\n\nconst createBlankPdf = (options: Md2PdfOptions): BlankPdf => {\n const pageSize = resolvePageSize(\n options.page?.size ?? 'A4',\n options.page?.orientation ?? 'portrait',\n );\n return {\n width: pageSize.width,\n height: pageSize.height,\n padding: resolveMargin(options.page?.margin ?? DEFAULT_PAGE_MARGIN),\n };\n};\n\nconst resolveMargin = (margin: MarkdownMargin): [number, number, number, number] => {\n if (typeof margin === 'number') return [margin, margin, margin, margin];\n if (Array.isArray(margin)) return margin;\n\n const x = margin.x ?? 0;\n const y = margin.y ?? 0;\n return [margin.top ?? y, margin.right ?? x, margin.bottom ?? y, margin.left ?? x];\n};\n\nconst renderBlock = (node: RootContent | BlockContent, builder: Builder): void => {\n switch (node.type) {\n case 'heading':\n renderHeading(node, builder);\n return;\n case 'paragraph':\n renderParagraph(node, builder);\n return;\n case 'list':\n renderList(node, builder);\n return;\n case 'code':\n renderCode(node, builder);\n return;\n case 'blockquote':\n renderBlockquote(node, builder);\n return;\n case 'table':\n renderTable(node, builder);\n return;\n case 'thematicBreak':\n renderLine(builder);\n return;\n case 'html':\n case 'definition':\n case 'footnoteDefinition':\n case 'yaml':\n return;\n default:\n renderNestedBlocks(node, builder);\n }\n};\n\nconst renderNestedBlocks = (node: RootContent | BlockContent, builder: Builder): void => {\n if ('children' in node && Array.isArray(node.children)) {\n node.children.forEach((child) => {\n if (isBlockContent(child)) renderBlock(child, builder);\n });\n }\n};\n\nconst renderHeading = (node: Heading, builder: Builder): void => {\n const depth = Math.min(Math.max(node.depth, 1), 6) as HeadingDepth;\n const content = renderInlineChildren(node.children);\n const fontSize = builder.fontSize * builder.headingScale[depth];\n addTextSchema(builder, {\n name: resolveName(builder, slugify(toPlainText(node)) || `heading_${depth}`),\n content,\n fontSize,\n height: estimateTextHeight(content, fontSize, builder.lineHeight),\n gap: depth <= 1 ? 5 : depth === 2 ? 4.5 : BLOCK_GAP,\n textFormat: 'inline-markdown',\n });\n};\n\nconst renderParagraph = (node: Paragraph, builder: Builder): void => {\n if (node.children.length === 1 && node.children[0]?.type === 'image') {\n renderImage(node.children[0], builder);\n return;\n }\n\n const content = renderInlineChildren(node.children);\n if (!content.trim()) return;\n addTextSchema(builder, {\n content,\n textFormat: 'inline-markdown',\n });\n};\n\nconst renderList = (node: List, builder: Builder): void => {\n const items = collectListItems(node);\n if (items.length === 0) return;\n\n const fontSize = builder.fontSize;\n const height =\n items.length * estimateTextHeight('', fontSize, builder.lineHeight) +\n Math.max(0, items.length - 1) * LIST_ITEM_SPACING;\n\n const schema: Schema = {\n name: resolveAutoName(builder, 'list'),\n type: 'list',\n content: JSON.stringify(items),\n position: { x: builder.contentFrame.x, y: builder.cursorY },\n width: builder.contentFrame.width,\n height,\n readOnly: true,\n alignment: 'left',\n verticalAlignment: 'top',\n fontSize,\n fontName: builder.fontName,\n lineHeight: builder.lineHeight,\n characterSpacing: 0,\n fontColor: builder.fontColor,\n backgroundColor: '',\n listStyle: node.ordered ? 'ordered' : 'bullet',\n markerWidth: 6,\n markerGap: 2,\n indentSize: 6,\n itemSpacing: LIST_ITEM_SPACING,\n textFormat: 'inline-markdown',\n overflow: 'expand',\n };\n\n addSchema(builder, schema);\n};\n\nconst renderCode = (node: Code, builder: Builder): void => {\n const content = node.value;\n addTextSchema(builder, {\n content,\n backgroundColor: CODE_BLOCK_BACKGROUND_COLOR,\n borderColor: CODE_BLOCK_BORDER_COLOR,\n borderWidth: resolveBoxSides(CODE_BLOCK_BORDER_WIDTH),\n padding: CODE_BLOCK_PADDING,\n textFormat: 'plain',\n });\n};\n\nconst renderBlockquote = (node: Blockquote, builder: Builder): void => {\n const content = node.children\n .map((child) => blockToMarkdown(child))\n .join('\\n')\n .trim();\n\n if (!content.trim()) return;\n addTextSchema(builder, {\n content,\n backgroundColor: BLOCKQUOTE_BACKGROUND_COLOR,\n borderColor: BLOCKQUOTE_BORDER_COLOR,\n borderWidth: BLOCKQUOTE_BORDER_WIDTH,\n padding: BLOCKQUOTE_PADDING,\n textFormat: 'inline-markdown',\n });\n};\n\nconst renderTable = (node: Table, builder: Builder): void => {\n const rows = node.children.map(tableRowToStrings).filter((row) => row.length > 0);\n if (rows.length === 0) return;\n\n const columnCount = Math.max(...rows.map((row) => row.length));\n const head = normalizeRowLength(rows[0], columnCount);\n const body = rows.slice(1).map((row) => normalizeRowLength(row, columnCount));\n const height = TABLE_HEADER_HEIGHT + Math.max(1, body.length) * TABLE_ROW_HEIGHT;\n const columnWidths = Array.from({ length: columnCount }, () => 100 / columnCount);\n\n const schema: Schema = {\n name: resolveAutoName(builder, 'table'),\n type: 'table',\n content: JSON.stringify(body),\n position: { x: builder.contentFrame.x, y: builder.cursorY },\n width: builder.contentFrame.width,\n height,\n readOnly: true,\n showHead: true,\n repeatHead: false,\n head,\n headWidthPercentages: columnWidths,\n tableStyles: {\n borderColor: TABLE_BORDER_COLOR,\n borderWidth: 0.2,\n },\n headStyles: {\n ...defaultCellStyle(builder),\n backgroundColor: TABLE_HEAD_BACKGROUND_COLOR,\n borderColor: TABLE_BORDER_COLOR,\n borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH),\n },\n bodyStyles: {\n ...defaultCellStyle(builder),\n borderColor: TABLE_BORDER_COLOR,\n borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH),\n alternateBackgroundColor: TABLE_BODY_ALTERNATE_BACKGROUND_COLOR,\n },\n columnStyles: {},\n };\n\n addSchema(builder, schema);\n};\n\nconst renderImage = (node: Image, builder: Builder): void => {\n if (!DATA_IMAGE_PATTERN.test(node.url)) {\n const link = normalizeLinkHref(node.url);\n const label = node.alt || node.title || node.url;\n addTextSchema(builder, {\n content: link\n ? `[${escapeInlineMarkdown(label)}](${escapeLinkDestination(link)})`\n : escapeInlineMarkdown(label),\n textFormat: 'inline-markdown',\n });\n return;\n }\n\n const schema: Schema = {\n name: resolveAutoName(builder, 'image'),\n type: 'image',\n content: node.url,\n position: { x: builder.contentFrame.x, y: builder.cursorY },\n width: builder.contentFrame.width,\n height: IMAGE_HEIGHT,\n readOnly: true,\n };\n\n addSchema(builder, schema);\n};\n\nconst renderLine = (builder: Builder): void => {\n const schema: Schema = {\n name: resolveAutoName(builder, 'line'),\n type: 'line',\n position: { x: builder.contentFrame.x, y: builder.cursorY },\n width: builder.contentFrame.width,\n height: HORIZONTAL_RULE_HEIGHT,\n readOnly: true,\n color: HORIZONTAL_RULE_COLOR,\n };\n\n addSchema(builder, schema);\n};\n\nconst addTextSchema = (\n builder: Builder,\n options: {\n name?: string;\n content: string;\n fontSize?: number;\n height?: number;\n gap?: number;\n backgroundColor?: string;\n borderColor?: string;\n borderWidth?: ResolvedBoxSides;\n padding?: ResolvedBoxSides;\n textFormat?: 'plain' | 'inline-markdown';\n x?: number;\n width?: number;\n },\n): void => {\n const fontSize = options.fontSize ?? builder.fontSize;\n const content = options.content;\n const boxVerticalInset = getBoxVerticalInset(options);\n const schema: Schema = {\n name: options.name ?? resolveAutoName(builder, 'text'),\n type: 'text',\n content,\n position: { x: options.x ?? builder.contentFrame.x, y: builder.cursorY },\n width: options.width ?? builder.contentFrame.width,\n height:\n (options.height ?? estimateTextHeight(content, fontSize, builder.lineHeight)) +\n boxVerticalInset,\n readOnly: true,\n alignment: 'left',\n verticalAlignment: 'top',\n fontSize,\n fontName: builder.fontName,\n lineHeight: builder.lineHeight,\n characterSpacing: 0,\n fontColor: builder.fontColor,\n backgroundColor: options.backgroundColor ?? '',\n borderColor: options.borderColor,\n borderWidth: options.borderWidth,\n padding: options.padding,\n textFormat: options.textFormat ?? 'plain',\n overflow: 'expand',\n };\n\n addSchema(builder, schema, options.gap);\n};\n\nconst addSchema = (builder: Builder, schema: Schema, gap = BLOCK_GAP): void => {\n builder.schemas.push(schema);\n builder.cursorY += schema.height + gap;\n};\n\nconst collectListItems = (node: List, level = 0): string[] =>\n node.children.flatMap((item) => {\n const prefix = typeof item.checked === 'boolean' ? `[${item.checked ? 'x' : ' '}] ` : '';\n const text = item.children\n .filter((child) => child.type !== 'list')\n .map((child) => blockToMarkdown(child))\n .join(' ')\n .trim();\n const current = `${'\\t'.repeat(level)}${prefix}${text}`;\n const nested = item.children\n .filter(isList)\n .flatMap((child) => collectListItems(child, level + 1));\n return [current, ...nested];\n });\n\nconst blockToMarkdown = (node: RootContent | BlockContent): string => {\n switch (node.type) {\n case 'paragraph':\n case 'heading':\n return renderInlineChildren(node.children);\n case 'code':\n return node.value;\n case 'list':\n return collectListItems(node).join('\\n');\n case 'blockquote':\n return node.children.map(blockToMarkdown).join('\\n');\n case 'table':\n return node.children.map((row) => tableRowToStrings(row).join(' | ')).join('\\n');\n case 'thematicBreak':\n return '---';\n default:\n return '';\n }\n};\n\nconst renderInlineChildren = (children: PhrasingContent[]): string =>\n children.map(renderInline).join('');\n\nconst renderInline = (node: PhrasingContent): string => {\n switch (node.type) {\n case 'text':\n return escapeInlineMarkdown(node.value);\n case 'emphasis':\n return `*${renderInlineChildren(node.children)}*`;\n case 'strong':\n return `**${renderInlineChildren(node.children)}**`;\n case 'delete':\n return `~~${renderInlineChildren(node.children)}~~`;\n case 'inlineCode':\n return renderInlineCode(node);\n case 'break':\n return '\\n';\n case 'link':\n return renderLink(node);\n case 'image':\n return renderInlineImage(node);\n case 'html':\n return '';\n default:\n return 'children' in node && Array.isArray(node.children)\n ? renderInlineChildren(node.children as PhrasingContent[])\n : '';\n }\n};\n\nconst renderInlineCode = (node: InlineCode): string => `\\`${node.value.replaceAll('`', '\\\\`')}\\``;\n\nconst renderLink = (node: Link): string => {\n const label = renderInlineChildren(node.children);\n const href = normalizeLinkHref(node.url);\n if (!href) return label;\n return `[${label}](${escapeLinkDestination(href)})`;\n};\n\nconst renderInlineImage = (node: Image): string => {\n const label = node.alt || node.title || node.url;\n const href = normalizeLinkHref(node.url);\n if (!href) return escapeInlineMarkdown(label);\n return `[${escapeInlineMarkdown(label)}](${escapeLinkDestination(href)})`;\n};\n\nconst tableRowToStrings = (row: TableRow): string[] => row.children.map(tableCellToString);\n\nconst tableCellToString = (cell: TableCell): string =>\n cell.children.map(inlineToPlainText).join('');\n\nconst normalizeRowLength = (row: string[], columnCount: number): string[] =>\n Array.from({ length: columnCount }, (_, index) => row[index] ?? '');\n\nconst defaultCellStyle = (builder: Builder): TableCellStyle => ({\n fontName: builder.fontName,\n alignment: 'left',\n verticalAlignment: 'middle',\n fontSize: builder.fontSize,\n lineHeight: builder.lineHeight,\n characterSpacing: 0,\n fontColor: builder.fontColor,\n backgroundColor: '#ffffff',\n borderColor: TABLE_BORDER_COLOR,\n borderWidth: resolveBoxSides(TABLE_CELL_BORDER_WIDTH),\n padding: resolveBoxSides(TABLE_CELL_PADDING),\n});\n\nconst resolveBoxSides = (value: number | BoxSides): ResolvedBoxSides => {\n if (typeof value === 'number') return { top: value, right: value, bottom: value, left: value };\n const x = value.x ?? 0;\n const y = value.y ?? 0;\n return {\n top: value.top ?? y,\n right: value.right ?? x,\n bottom: value.bottom ?? y,\n left: value.left ?? x,\n };\n};\n\nconst getBoxVerticalInset = (value: {\n borderWidth?: ResolvedBoxSides;\n padding?: ResolvedBoxSides;\n}) =>\n (value.borderWidth?.top ?? 0) +\n (value.borderWidth?.bottom ?? 0) +\n (value.padding?.top ?? 0) +\n (value.padding?.bottom ?? 0);\n\nconst resolveAutoName = (builder: Builder, prefix: string): string => {\n let name = '';\n do {\n builder.nameCounters[prefix] = (builder.nameCounters[prefix] ?? 0) + 1;\n name = `${prefix}_${builder.nameCounters[prefix]}`;\n } while (builder.usedNames.has(name));\n builder.usedNames.add(name);\n return name;\n};\n\nconst resolveName = (builder: Builder, baseName: string): string => {\n let name = baseName;\n let index = 0;\n while (builder.usedNames.has(name)) {\n index += 1;\n name = `${baseName}_${index}`;\n }\n builder.usedNames.add(name);\n return name;\n};\n\nconst estimateTextHeight = (content: string, fontSize: number, lineHeight: number): number => {\n const lineCount = Math.max(1, content.split('\\n').length);\n return Math.max(4, lineCount * pt2mm(fontSize * lineHeight) + 1);\n};\n\nconst escapeInlineMarkdown = (value: string): string =>\n value.replace(MARKDOWN_ESCAPE_PATTERN, (match) => `\\\\${match}`);\n\nconst escapeLinkDestination = (href: string): string =>\n encodeURI(href).replace(/[\\\\()]/g, (match) => `\\\\${match}`);\n\nconst slugify = (value: string): string =>\n value\n .trim()\n .toLowerCase()\n .replace(/[^\\p{Letter}\\p{Number}]+/gu, '-')\n .replace(/^-|-$/g, '');\n\nconst toPlainText = (node: Heading): string =>\n node.children\n .map((child) => {\n if ('value' in child && typeof child.value === 'string') return child.value;\n if ('alt' in child && typeof child.alt === 'string') return child.alt;\n if ('children' in child && Array.isArray(child.children)) {\n return (child.children as PhrasingContent[])\n .map((grandchild) => toPlainInlineText(grandchild))\n .join('');\n }\n return '';\n })\n .join('');\n\nconst toPlainInlineText = (node: PhrasingContent): string => {\n if ('value' in node && typeof node.value === 'string') return node.value;\n if ('alt' in node && typeof node.alt === 'string') return node.alt;\n if ('children' in node && Array.isArray(node.children)) {\n return (node.children as PhrasingContent[]).map(toPlainInlineText).join('');\n }\n return '';\n};\n\nconst inlineToPlainText = (node: PhrasingContent): string => {\n switch (node.type) {\n case 'text':\n case 'inlineCode':\n return node.value;\n case 'break':\n return '\\n';\n case 'image':\n return node.alt || node.title || node.url;\n case 'link':\n case 'emphasis':\n case 'strong':\n case 'delete':\n return node.children.map(inlineToPlainText).join('');\n case 'html':\n return '';\n default:\n return 'children' in node && Array.isArray(node.children)\n ? (node.children as PhrasingContent[]).map(inlineToPlainText).join('')\n : '';\n }\n};\n\nconst isBlockContent = (node: unknown): node is BlockContent =>\n typeof node === 'object' &&\n node !== null &&\n 'type' in node &&\n typeof node.type === 'string' &&\n RENDERABLE_BLOCK_TYPES.has(node.type);\n\nconst isList = (node: ListItem['children'][number]): node is List => node.type === 'list';\n"],"mappings":";;;;;AA8FA,IAAM,sBAAwD;CAAC;CAAI;CAAI;CAAI;CAAG;AAC9E,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAC3B,IAAM,wBAAsD;CAC1D,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACJ;AACD,IAAM,YAAY;AAClB,IAAM,oBAAoB;AAC1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C/D,KAAI,cAAc,QAAQ,MAAM,QAAQ,KAAK,SAAS,CACpD,QAAQ,KAAK,SAA+B,IAAI,kBAAkB,CAAC,KAAK,GAAG;AAE7E,QAAO;;AAGT,IAAM,qBAAqB,SAAkC;AAC3D,SAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK,aACH,QAAO,KAAK;EACd,KAAK,QACH,QAAO;EACT,KAAK,QACH,QAAO,KAAK,OAAO,KAAK,SAAS,KAAK;EACxC,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO,KAAK,SAAS,IAAI,kBAAkB,CAAC,KAAK,GAAG;EACtD,KAAK,OACH,QAAO;EACT,QACE,QAAO,cAAc,QAAQ,MAAM,QAAQ,KAAK,SAAS,GACpD,KAAK,SAA+B,IAAI,kBAAkB,CAAC,KAAK,GAAG,GACpE;;;AAIV,IAAM,kBAAkB,SACtB,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACV,OAAO,KAAK,SAAS,YACrB,uBAAuB,IAAI,KAAK,KAAK;AAEvC,IAAM,UAAU,SAAqD,KAAK,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pdfme/converter",
|
|
3
|
-
"version": "6.1.
|
|
3
|
+
"version": "6.1.2-dev.2",
|
|
4
4
|
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pdf",
|
|
@@ -35,6 +35,12 @@
|
|
|
35
35
|
"browser": "./dist/index.js",
|
|
36
36
|
"node": "./dist/index.node.js",
|
|
37
37
|
"default": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./md2pdf": {
|
|
40
|
+
"types": "./dist/md2pdf.d.ts",
|
|
41
|
+
"browser": "./dist/md2pdf.js",
|
|
42
|
+
"node": "./dist/md2pdf.js",
|
|
43
|
+
"default": "./dist/md2pdf.js"
|
|
38
44
|
}
|
|
39
45
|
},
|
|
40
46
|
"publishConfig": {
|
|
@@ -52,9 +58,14 @@
|
|
|
52
58
|
"@napi-rs/canvas": "^0.1.100",
|
|
53
59
|
"@pdfme/common": "*",
|
|
54
60
|
"@pdfme/pdf-lib": "*",
|
|
55
|
-
"pdfjs-dist": "^5.7.284"
|
|
61
|
+
"pdfjs-dist": "^5.7.284",
|
|
62
|
+
"remark-gfm": "^4.0.1",
|
|
63
|
+
"remark-parse": "^11.0.0",
|
|
64
|
+
"unified": "^11.0.5"
|
|
56
65
|
},
|
|
57
66
|
"devDependencies": {
|
|
58
|
-
"@pdfme/generator": "*"
|
|
67
|
+
"@pdfme/generator": "*",
|
|
68
|
+
"@pdfme/schemas": "*",
|
|
69
|
+
"@types/mdast": "^4.0.4"
|
|
59
70
|
}
|
|
60
71
|
}
|