jspdf-md-renderer 4.0.0 → 4.1.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/README.md +177 -269
- package/dist/index.d.mts +95 -3
- package/dist/index.d.ts +95 -3
- package/dist/index.js +747 -117
- package/dist/index.mjs +747 -118
- package/dist/index.umd.js +747 -117
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,94 @@
|
|
|
27
27
|
import jsPDF, { jsPDFOptions } from "jspdf";
|
|
28
28
|
import { UserOptions } from "jspdf-autotable";
|
|
29
29
|
|
|
30
|
+
//#region src/types/security.d.ts
|
|
31
|
+
type ViolationMode = 'skip' | 'throw' | 'placeholder';
|
|
32
|
+
type ViolationAction = 'skip' | 'placeholder';
|
|
33
|
+
type SecurityViolationType = 'link' | 'image' | 'markdown' | 'render';
|
|
34
|
+
type SecurityViolationCode = 'MARKDOWN_TOO_LARGE' | 'MAX_NESTED_DEPTH_EXCEEDED' | 'MAX_IMAGE_COUNT_EXCEEDED' | 'RENDER_TIMEOUT_EXCEEDED' | 'INVALID_URL' | 'LINK_PROTOCOL_BLOCKED' | 'IMAGE_PROTOCOL_BLOCKED' | 'IMAGE_DOMAIN_BLOCKED' | 'DATA_URL_BLOCKED' | 'SVG_BLOCKED' | 'LOCALHOST_BLOCKED' | 'PRIVATE_IP_BLOCKED' | 'LINK_LOCAL_IP_BLOCKED' | 'METADATA_IP_BLOCKED' | 'IMAGE_SIZE_EXCEEDED' | 'CUSTOM_VALIDATOR_BLOCKED';
|
|
35
|
+
interface SecurityViolation {
|
|
36
|
+
/** Machine-readable violation code. */
|
|
37
|
+
code: SecurityViolationCode;
|
|
38
|
+
/** High-level category of the violating input. */
|
|
39
|
+
type: SecurityViolationType;
|
|
40
|
+
/** Human-readable explanation of the violation. */
|
|
41
|
+
message: string;
|
|
42
|
+
/** Raw value that triggered the violation (URL, length, etc.). */
|
|
43
|
+
value?: string;
|
|
44
|
+
/** Optional execution context to help debugging (e.g. 'markdown-link'). */
|
|
45
|
+
context?: string;
|
|
46
|
+
/** ISO timestamp when the violation was recorded. */
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
declare class SecurityViolationError extends Error {
|
|
50
|
+
/** Structured violation payload used to construct this error. */
|
|
51
|
+
readonly violation: SecurityViolation;
|
|
52
|
+
constructor(violation: SecurityViolation);
|
|
53
|
+
}
|
|
54
|
+
interface RenderSecurityOptions {
|
|
55
|
+
/** Enables all built-in security checks. Default: false (opt-in). */
|
|
56
|
+
enabled?: boolean;
|
|
57
|
+
/** Allowed URI protocols for markdown links. Example: ['https:', 'mailto:']. */
|
|
58
|
+
allowedLinkProtocols?: string[];
|
|
59
|
+
/** If true, link text is rendered but PDF link actions are disabled. */
|
|
60
|
+
disablePdfLinks?: boolean;
|
|
61
|
+
/** Whether remote image fetching is allowed (http/https). */
|
|
62
|
+
allowRemoteImages?: boolean;
|
|
63
|
+
/** Allowed protocols for image URLs. Example: ['https:', 'http:']. */
|
|
64
|
+
allowedImageProtocols?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Optional domain allowlist for remote image hosts.
|
|
67
|
+
* - `undefined` (default): all domains are allowed.
|
|
68
|
+
* - `[]` (empty array): no domains are allowed.
|
|
69
|
+
* - `['example.com']`: only `example.com` and its subdomains are allowed.
|
|
70
|
+
*/
|
|
71
|
+
allowedImageDomains?: string[];
|
|
72
|
+
/** Whether inline data: image URLs are allowed. */
|
|
73
|
+
allowDataUrls?: boolean;
|
|
74
|
+
/** Whether SVG images are allowed. */
|
|
75
|
+
allowSvgImages?: boolean;
|
|
76
|
+
/** Blocks localhost image/link destinations when true. */
|
|
77
|
+
blockLocalhost?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Blocks private IPv4 ranges (10/8, 172.16/12, 192.168/16) when true.
|
|
80
|
+
* NOTE: In browser environments, IP-based checks cannot be enforced due to
|
|
81
|
+
* lack of DNS resolution APIs. Use a trusted server-side proxy for strict enforcement.
|
|
82
|
+
*/
|
|
83
|
+
blockPrivateIPs?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Blocks link-local IPv4 ranges (169.254/16) when true.
|
|
86
|
+
* NOTE: In browser environments, IP-based checks cannot be enforced due to
|
|
87
|
+
* lack of DNS resolution APIs. Use a trusted server-side proxy for strict enforcement.
|
|
88
|
+
*/
|
|
89
|
+
blockLinkLocalIPs?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Blocks known cloud metadata endpoints when true.
|
|
92
|
+
* NOTE: In browser environments, IP-based checks cannot be enforced due to
|
|
93
|
+
* lack of DNS resolution APIs. Use a trusted server-side proxy for strict enforcement.
|
|
94
|
+
*/
|
|
95
|
+
blockMetadataIPs?: boolean;
|
|
96
|
+
/** Maximum markdown input length in characters. */
|
|
97
|
+
maxMarkdownLength?: number;
|
|
98
|
+
/** Maximum number of markdown images allowed per render. */
|
|
99
|
+
maxImageCount?: number;
|
|
100
|
+
/** Maximum image payload size in bytes (fetched blob size or decoded data URL bytes). */
|
|
101
|
+
maxImageSizeBytes?: number;
|
|
102
|
+
/** Maximum supported markdown nesting depth. */
|
|
103
|
+
maxNestedDepth?: number;
|
|
104
|
+
/** Maximum total render time in milliseconds. */
|
|
105
|
+
renderTimeoutMs?: number;
|
|
106
|
+
/** Action taken when a violation occurs. */
|
|
107
|
+
violationMode?: ViolationMode;
|
|
108
|
+
/** Placeholder text used for blocked text-like content in placeholder mode. */
|
|
109
|
+
placeholderText?: string;
|
|
110
|
+
/** Placeholder text used for blocked images in placeholder mode. */
|
|
111
|
+
placeholderImageText?: string;
|
|
112
|
+
/** Optional custom URL validator. Return false to reject the URL. */
|
|
113
|
+
validateUrl?: (url: URL, type: 'link' | 'image') => boolean | Promise<boolean>;
|
|
114
|
+
/** Callback fired for every security violation, regardless of mode. */
|
|
115
|
+
onSecurityViolation?: (violation: SecurityViolation) => void;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
30
118
|
//#region src/types/renderOption.d.ts
|
|
31
119
|
type RenderOption = {
|
|
32
120
|
cursor: {
|
|
@@ -52,10 +140,13 @@ type RenderOption = {
|
|
|
52
140
|
bold: FontItem;
|
|
53
141
|
regular: FontItem;
|
|
54
142
|
light: FontItem;
|
|
143
|
+
italic?: FontItem;
|
|
144
|
+
boldItalic?: FontItem;
|
|
55
145
|
code?: FontItem;
|
|
56
146
|
};
|
|
57
147
|
heading?: {
|
|
58
|
-
/** Font size for h1-h6. Values are absolute (e.g. 22, 20, 18, 16, 14, 12). */
|
|
148
|
+
/** Whether headings should use bold font. Default: true */bold?: boolean; /** Font size for h1-h6. Values are absolute (e.g. 22, 20, 18, 16, 14, 12). */
|
|
149
|
+
h1?: number;
|
|
59
150
|
h2?: number;
|
|
60
151
|
h3?: number;
|
|
61
152
|
h4?: number;
|
|
@@ -72,7 +163,7 @@ type RenderOption = {
|
|
|
72
163
|
};
|
|
73
164
|
list?: {
|
|
74
165
|
/** Bullet character for unordered lists. Default: '\u2022 ' */bulletChar?: string; /** Extra indent per nesting level in doc units. Default: uses page.indent */
|
|
75
|
-
indentSize?: number; /** Vertical space between list items.
|
|
166
|
+
indentSize?: number; /** Vertical space between list items. Used when spacing.betweenListItems is not provided. */
|
|
76
167
|
itemSpacing?: number;
|
|
77
168
|
};
|
|
78
169
|
paragraph?: {
|
|
@@ -140,6 +231,7 @@ type RenderOption = {
|
|
|
140
231
|
};
|
|
141
232
|
pageBreakHandler?: (doc: jsPDF) => void;
|
|
142
233
|
endCursorYHandler: (y: number) => void;
|
|
234
|
+
security?: RenderSecurityOptions;
|
|
143
235
|
};
|
|
144
236
|
type Cursor = {
|
|
145
237
|
x: number;
|
|
@@ -332,4 +424,4 @@ declare enum MdTokenType {
|
|
|
332
424
|
//#region src/utils/options-validation.d.ts
|
|
333
425
|
declare const validateOptions: (options: RenderOption) => RenderOption;
|
|
334
426
|
//#endregion
|
|
335
|
-
export { MdTextParser, MdTextRender, MdTokenType, type ParsedElement, type RenderOption, type StyledLine, type StyledWordInfo, type TextStyle, renderInlineContent, renderPlainText, validateOptions };
|
|
427
|
+
export { MdTextParser, MdTextRender, MdTokenType, type ParsedElement, type RenderOption, type RenderSecurityOptions, type SecurityViolation, type SecurityViolationCode, SecurityViolationError, type StyledLine, type StyledWordInfo, type TextStyle, type ViolationAction, type ViolationMode, renderInlineContent, renderPlainText, validateOptions };
|