jspdf-md-renderer 3.4.0 → 3.5.0
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/dist/index.d.mts +124 -0
- package/dist/index.d.ts +124 -1
- package/dist/index.js +1685 -4
- package/dist/index.mjs +1348 -660
- package/dist/index.umd.js +1691 -4
- package/package.json +4 -6
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* jspdf-md-renderer
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Jeel Gajera
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
import { UserOptions } from "jspdf-autotable";
|
|
28
|
+
import jsPDF, { jsPDFOptions } from "jspdf";
|
|
29
|
+
|
|
30
|
+
//#region src/types/renderOption.d.ts
|
|
31
|
+
type RenderOption = {
|
|
32
|
+
cursor: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
page: {
|
|
37
|
+
format?: string | number[];
|
|
38
|
+
unit?: jsPDFOptions['unit'];
|
|
39
|
+
orientation?: jsPDFOptions['orientation'];
|
|
40
|
+
maxContentWidth: number;
|
|
41
|
+
maxContentHeight: number;
|
|
42
|
+
lineSpace: number;
|
|
43
|
+
defaultLineHeightFactor: number;
|
|
44
|
+
defaultFontSize: number;
|
|
45
|
+
defaultTitleFontSize: number;
|
|
46
|
+
topmargin: number;
|
|
47
|
+
xpading: number;
|
|
48
|
+
xmargin: number;
|
|
49
|
+
indent: number;
|
|
50
|
+
};
|
|
51
|
+
font: {
|
|
52
|
+
bold: FontItem;
|
|
53
|
+
regular: FontItem;
|
|
54
|
+
light: FontItem;
|
|
55
|
+
code?: FontItem;
|
|
56
|
+
};
|
|
57
|
+
content?: {
|
|
58
|
+
textAlignment: 'left' | 'right' | 'center' | 'justify';
|
|
59
|
+
};
|
|
60
|
+
codespan?: {
|
|
61
|
+
/** Background color for inline code. Default: '#EEEEEE' */backgroundColor?: string; /** Padding around inline code text. Default: 0.5 */
|
|
62
|
+
padding?: number; /** Whether to show background rectangle. Default: true */
|
|
63
|
+
showBackground?: boolean; /** Font size scale factor for code. Default: 0.9 */
|
|
64
|
+
fontSizeScale?: number;
|
|
65
|
+
};
|
|
66
|
+
link?: {
|
|
67
|
+
linkColor: [number, number, number];
|
|
68
|
+
};
|
|
69
|
+
table?: UserOptions;
|
|
70
|
+
image?: {
|
|
71
|
+
/** Default alignment for images: 'left' | 'center' | 'right'. Default: 'left' */defaultAlign?: 'left' | 'center' | 'right';
|
|
72
|
+
};
|
|
73
|
+
pageBreakHandler?: (doc: jsPDF) => void;
|
|
74
|
+
endCursorYHandler: (y: number) => void;
|
|
75
|
+
};
|
|
76
|
+
type FontItem = {
|
|
77
|
+
name: string;
|
|
78
|
+
style: string;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/renderer/MdTextRender.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Renders parsed markdown text into jsPDF document.
|
|
84
|
+
*
|
|
85
|
+
* @param doc - The jsPDF document.
|
|
86
|
+
* @param text - The markdown content to render.
|
|
87
|
+
* @param options - The render options (fonts, page margins, etc.).
|
|
88
|
+
*/
|
|
89
|
+
declare const MdTextRender: (doc: jsPDF, text: string, options: RenderOption) => Promise<void>;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/types/parsedElement.d.ts
|
|
92
|
+
type ParsedElement = {
|
|
93
|
+
type: string;
|
|
94
|
+
content?: string;
|
|
95
|
+
depth?: number;
|
|
96
|
+
items?: ParsedElement[];
|
|
97
|
+
ordered?: boolean;
|
|
98
|
+
start?: number;
|
|
99
|
+
lang?: string;
|
|
100
|
+
code?: string;
|
|
101
|
+
src?: string;
|
|
102
|
+
alt?: string;
|
|
103
|
+
href?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
header?: ParsedElement[];
|
|
106
|
+
rows?: ParsedElement[][];
|
|
107
|
+
data?: string;
|
|
108
|
+
width?: number;
|
|
109
|
+
height?: number;
|
|
110
|
+
align?: 'left' | 'center' | 'right';
|
|
111
|
+
naturalWidth?: number;
|
|
112
|
+
naturalHeight?: number;
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/parser/MdTextParser.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* Parses markdown into tokens and converts to a custom parsed structure.
|
|
118
|
+
*
|
|
119
|
+
* @param text - The markdown content to parse.
|
|
120
|
+
* @returns Parsed markdown elements.
|
|
121
|
+
*/
|
|
122
|
+
declare const MdTextParser: (text: string) => Promise<ParsedElement[]>;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { MdTextParser, MdTextRender, type RenderOption };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* jspdf-md-renderer
|
|
3
|
+
*
|
|
4
|
+
* MIT License
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2026 Jeel Gajera
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
import jsPDF, { jsPDFOptions } from "jspdf";
|
|
28
|
+
import { UserOptions } from "jspdf-autotable";
|
|
29
|
+
|
|
30
|
+
//#region src/types/renderOption.d.ts
|
|
31
|
+
type RenderOption = {
|
|
32
|
+
cursor: {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
};
|
|
36
|
+
page: {
|
|
37
|
+
format?: string | number[];
|
|
38
|
+
unit?: jsPDFOptions['unit'];
|
|
39
|
+
orientation?: jsPDFOptions['orientation'];
|
|
40
|
+
maxContentWidth: number;
|
|
41
|
+
maxContentHeight: number;
|
|
42
|
+
lineSpace: number;
|
|
43
|
+
defaultLineHeightFactor: number;
|
|
44
|
+
defaultFontSize: number;
|
|
45
|
+
defaultTitleFontSize: number;
|
|
46
|
+
topmargin: number;
|
|
47
|
+
xpading: number;
|
|
48
|
+
xmargin: number;
|
|
49
|
+
indent: number;
|
|
50
|
+
};
|
|
51
|
+
font: {
|
|
52
|
+
bold: FontItem;
|
|
53
|
+
regular: FontItem;
|
|
54
|
+
light: FontItem;
|
|
55
|
+
code?: FontItem;
|
|
56
|
+
};
|
|
57
|
+
content?: {
|
|
58
|
+
textAlignment: 'left' | 'right' | 'center' | 'justify';
|
|
59
|
+
};
|
|
60
|
+
codespan?: {
|
|
61
|
+
/** Background color for inline code. Default: '#EEEEEE' */backgroundColor?: string; /** Padding around inline code text. Default: 0.5 */
|
|
62
|
+
padding?: number; /** Whether to show background rectangle. Default: true */
|
|
63
|
+
showBackground?: boolean; /** Font size scale factor for code. Default: 0.9 */
|
|
64
|
+
fontSizeScale?: number;
|
|
65
|
+
};
|
|
66
|
+
link?: {
|
|
67
|
+
linkColor: [number, number, number];
|
|
68
|
+
};
|
|
69
|
+
table?: UserOptions;
|
|
70
|
+
image?: {
|
|
71
|
+
/** Default alignment for images: 'left' | 'center' | 'right'. Default: 'left' */defaultAlign?: 'left' | 'center' | 'right';
|
|
72
|
+
};
|
|
73
|
+
pageBreakHandler?: (doc: jsPDF) => void;
|
|
74
|
+
endCursorYHandler: (y: number) => void;
|
|
75
|
+
};
|
|
76
|
+
type FontItem = {
|
|
77
|
+
name: string;
|
|
78
|
+
style: string;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/renderer/MdTextRender.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Renders parsed markdown text into jsPDF document.
|
|
84
|
+
*
|
|
85
|
+
* @param doc - The jsPDF document.
|
|
86
|
+
* @param text - The markdown content to render.
|
|
87
|
+
* @param options - The render options (fonts, page margins, etc.).
|
|
88
|
+
*/
|
|
89
|
+
declare const MdTextRender: (doc: jsPDF, text: string, options: RenderOption) => Promise<void>;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/types/parsedElement.d.ts
|
|
92
|
+
type ParsedElement = {
|
|
93
|
+
type: string;
|
|
94
|
+
content?: string;
|
|
95
|
+
depth?: number;
|
|
96
|
+
items?: ParsedElement[];
|
|
97
|
+
ordered?: boolean;
|
|
98
|
+
start?: number;
|
|
99
|
+
lang?: string;
|
|
100
|
+
code?: string;
|
|
101
|
+
src?: string;
|
|
102
|
+
alt?: string;
|
|
103
|
+
href?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
header?: ParsedElement[];
|
|
106
|
+
rows?: ParsedElement[][];
|
|
107
|
+
data?: string;
|
|
108
|
+
width?: number;
|
|
109
|
+
height?: number;
|
|
110
|
+
align?: 'left' | 'center' | 'right';
|
|
111
|
+
naturalWidth?: number;
|
|
112
|
+
naturalHeight?: number;
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/parser/MdTextParser.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* Parses markdown into tokens and converts to a custom parsed structure.
|
|
118
|
+
*
|
|
119
|
+
* @param text - The markdown content to parse.
|
|
120
|
+
* @returns Parsed markdown elements.
|
|
121
|
+
*/
|
|
122
|
+
declare const MdTextParser: (text: string) => Promise<ParsedElement[]>;
|
|
123
|
+
//#endregion
|
|
124
|
+
export { MdTextParser, MdTextRender, type RenderOption };
|