pd-markdown 2.0.1 → 2.0.3

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.
@@ -0,0 +1,358 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Type guard to check if node is a parent node
5
+ */
6
+ function isParent(node) {
7
+ return 'children' in node && Array.isArray(node.children);
8
+ }
9
+ /**
10
+ * Type guard to check if node is a literal node
11
+ */
12
+ function isLiteral(node) {
13
+ return 'value' in node && typeof node.value === 'string';
14
+ }
15
+ /**
16
+ * Type guard to check if node has specific type
17
+ */
18
+ function isNodeType(node, type) {
19
+ return node.type === type;
20
+ }
21
+
22
+ /**
23
+ * Traverse AST in depth-first order
24
+ *
25
+ * @param node - Root node to start traversal
26
+ * @param visitor - Visitor function called for each node
27
+ * Return `false` to skip children of current node
28
+ * Return `true` or `undefined` to continue
29
+ */
30
+ function traverseAst(node, visitor) {
31
+ function visit(current, index, parent) {
32
+ const result = visitor(current, index, parent);
33
+ // Skip children if visitor returns false
34
+ if (result === false) {
35
+ return;
36
+ }
37
+ if (isParent(current)) {
38
+ const children = current.children;
39
+ for (let i = 0; i < children.length; i++) {
40
+ visit(children[i], i, current);
41
+ }
42
+ }
43
+ }
44
+ visit(node, undefined, undefined);
45
+ }
46
+ /**
47
+ * Traverse AST with enter and leave callbacks
48
+ *
49
+ * @param node - Root node to start traversal
50
+ * @param callbacks - Object with optional enter and leave functions
51
+ */
52
+ function traverseAstWithCallbacks(node, callbacks) {
53
+ const { enter, leave } = callbacks;
54
+ function visit(current, index, parent) {
55
+ const shouldSkipChildren = enter?.(current, index, parent) === false;
56
+ if (!shouldSkipChildren && isParent(current)) {
57
+ const children = current.children;
58
+ for (let i = 0; i < children.length; i++) {
59
+ visit(children[i], i, current);
60
+ }
61
+ }
62
+ leave?.(current, index, parent);
63
+ }
64
+ visit(node, undefined, undefined);
65
+ }
66
+
67
+ /**
68
+ * Find all nodes of a specific type in the AST
69
+ *
70
+ * @param node - Root node to search from
71
+ * @param type - Node type to find
72
+ * @returns Array of matching nodes
73
+ */
74
+ function findNodes(node, type) {
75
+ const results = [];
76
+ function visit(current) {
77
+ if (current.type === type) {
78
+ results.push(current);
79
+ }
80
+ if (isParent(current)) {
81
+ for (const child of current.children) {
82
+ visit(child);
83
+ }
84
+ }
85
+ }
86
+ visit(node);
87
+ return results;
88
+ }
89
+ /**
90
+ * Find the first node of a specific type in the AST
91
+ *
92
+ * @param node - Root node to search from
93
+ * @param type - Node type to find
94
+ * @returns The first matching node or undefined
95
+ */
96
+ function findNode(node, type) {
97
+ let result;
98
+ function visit(current) {
99
+ if (current.type === type) {
100
+ result = current;
101
+ return true; // Found, stop searching
102
+ }
103
+ if (isParent(current)) {
104
+ for (const child of current.children) {
105
+ if (visit(child)) {
106
+ return true;
107
+ }
108
+ }
109
+ }
110
+ return false;
111
+ }
112
+ visit(node);
113
+ return result;
114
+ }
115
+ /**
116
+ * Find all nodes matching a predicate
117
+ *
118
+ * @param node - Root node to search from
119
+ * @param predicate - Function to test each node
120
+ * @returns Array of matching nodes
121
+ */
122
+ function findNodesBy(node, predicate) {
123
+ const results = [];
124
+ function visit(current) {
125
+ if (predicate(current)) {
126
+ results.push(current);
127
+ }
128
+ if (isParent(current)) {
129
+ for (const child of current.children) {
130
+ visit(child);
131
+ }
132
+ }
133
+ }
134
+ visit(node);
135
+ return results;
136
+ }
137
+ /**
138
+ * Get the parent of a node in the AST
139
+ * Note: This requires traversing from root, use sparingly
140
+ *
141
+ * @param root - Root node of the AST
142
+ * @param target - Node to find parent of
143
+ * @returns Parent node or undefined if not found or is root
144
+ */
145
+ function findParent(root, target) {
146
+ let result;
147
+ function visit(current, parent) {
148
+ if (current === target) {
149
+ result = parent;
150
+ return true;
151
+ }
152
+ if (isParent(current)) {
153
+ for (const child of current.children) {
154
+ if (visit(child, current)) {
155
+ return true;
156
+ }
157
+ }
158
+ }
159
+ return false;
160
+ }
161
+ visit(root, undefined);
162
+ return result;
163
+ }
164
+
165
+ /**
166
+ * Convert text to URL-safe slug
167
+ *
168
+ * @param text - Text to slugify
169
+ * @returns URL-safe slug
170
+ */
171
+ function slugify(text) {
172
+ return (text
173
+ // Convert to lowercase
174
+ .toLowerCase()
175
+ // Replace Chinese characters with pinyin-like representation (keep as-is for simplicity)
176
+ // Replace spaces and special chars with hyphens
177
+ .replace(/[\s_]+/g, '-')
178
+ // Remove characters that aren't alphanumeric, hyphens, or common CJK
179
+ .replace(/[^\w\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff-]/g, '')
180
+ // Replace multiple consecutive hyphens with single hyphen
181
+ .replace(/-+/g, '-')
182
+ // Remove leading/trailing hyphens
183
+ .replace(/^-+|-+$/g, ''));
184
+ }
185
+ /**
186
+ * Generate unique slug with counter suffix for duplicates
187
+ *
188
+ * @param text - Text to slugify
189
+ * @param existingSlugs - Set of existing slugs to check against
190
+ * @returns Unique slug
191
+ */
192
+ function uniqueSlugify(text, existingSlugs) {
193
+ const baseSlug = slugify(text);
194
+ let slug = baseSlug;
195
+ let counter = 1;
196
+ while (existingSlugs.has(slug)) {
197
+ slug = `${baseSlug}-${counter}`;
198
+ counter++;
199
+ }
200
+ existingSlugs.add(slug);
201
+ return slug;
202
+ }
203
+
204
+ /**
205
+ * HTML entities that need escaping
206
+ */
207
+ const HTML_ESCAPE_MAP = {
208
+ '&': '&amp;',
209
+ '<': '&lt;',
210
+ '>': '&gt;',
211
+ '"': '&quot;',
212
+ "'": '&#39;',
213
+ };
214
+ /**
215
+ * Escape HTML special characters
216
+ *
217
+ * @param text - Text to escape
218
+ * @returns Escaped text safe for HTML insertion
219
+ */
220
+ function escapeHtml(text) {
221
+ return text.replace(/[&<>"']/g, (char) => HTML_ESCAPE_MAP[char] || char);
222
+ }
223
+ /**
224
+ * Allowed HTML tags for sanitization
225
+ */
226
+ const ALLOWED_TAGS = new Set([
227
+ 'a',
228
+ 'abbr',
229
+ 'b',
230
+ 'blockquote',
231
+ 'br',
232
+ 'code',
233
+ 'dd',
234
+ 'del',
235
+ 'div',
236
+ 'dl',
237
+ 'dt',
238
+ 'em',
239
+ 'h1',
240
+ 'h2',
241
+ 'h3',
242
+ 'h4',
243
+ 'h5',
244
+ 'h6',
245
+ 'hr',
246
+ 'i',
247
+ 'img',
248
+ 'ins',
249
+ 'kbd',
250
+ 'li',
251
+ 'ol',
252
+ 'p',
253
+ 'pre',
254
+ 'q',
255
+ 's',
256
+ 'samp',
257
+ 'small',
258
+ 'span',
259
+ 'strong',
260
+ 'sub',
261
+ 'sup',
262
+ 'table',
263
+ 'tbody',
264
+ 'td',
265
+ 'tfoot',
266
+ 'th',
267
+ 'thead',
268
+ 'tr',
269
+ 'u',
270
+ 'ul',
271
+ ]);
272
+ /**
273
+ * Allowed attributes for sanitization
274
+ */
275
+ const ALLOWED_ATTRS = new Set([
276
+ 'href',
277
+ 'src',
278
+ 'alt',
279
+ 'title',
280
+ 'class',
281
+ 'id',
282
+ 'name',
283
+ 'target',
284
+ 'rel',
285
+ 'width',
286
+ 'height',
287
+ 'align',
288
+ 'colspan',
289
+ 'rowspan',
290
+ ]);
291
+ /**
292
+ * Sanitize HTML string by removing dangerous content
293
+ *
294
+ * @param html - HTML string to sanitize
295
+ * @returns Sanitized HTML string
296
+ */
297
+ function sanitizeHtml(html) {
298
+ let result = html;
299
+ // Remove script tags first
300
+ result = result.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
301
+ // Remove event handlers
302
+ result = result.replace(/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]*)/gi, '');
303
+ // Remove disallowed tags (keep content) and sanitize attributes
304
+ result = result.replace(/<\/?(\w+)([^>]*)>/g, (match, tagName, attrs) => {
305
+ const tag = tagName.toLowerCase();
306
+ if (!ALLOWED_TAGS.has(tag)) {
307
+ return '';
308
+ }
309
+ // For closing tags, just return them
310
+ if (match.startsWith('</')) {
311
+ return `</${tag}>`;
312
+ }
313
+ // Sanitize attributes
314
+ const sanitizedAttrs = [];
315
+ const attrRegex = /\s+([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/g;
316
+ let attrMatch;
317
+ while ((attrMatch = attrRegex.exec(attrs)) !== null) {
318
+ const [, attrName, v1, v2, v3] = attrMatch;
319
+ const attr = attrName.toLowerCase();
320
+ if (ALLOWED_ATTRS.has(attr)) {
321
+ let value = v1 ?? v2 ?? v3 ?? '';
322
+ // Check for dangerous URLs in href/src
323
+ if ((attr === 'href' || attr === 'src') && /^\s*javascript\s*:/i.test(value)) {
324
+ value = '';
325
+ }
326
+ sanitizedAttrs.push(`${attr}="${value}"`);
327
+ }
328
+ }
329
+ const attrStr = sanitizedAttrs.length > 0 ? ' ' + sanitizedAttrs.join(' ') : '';
330
+ return `<${tag}${attrStr}>`;
331
+ });
332
+ return result;
333
+ }
334
+ /**
335
+ * Strip all HTML tags from a string
336
+ *
337
+ * @param html - HTML string to strip
338
+ * @returns Plain text without HTML tags
339
+ */
340
+ function stripHtml(html) {
341
+ return html.replace(/<[^>]*>/g, '');
342
+ }
343
+
344
+ exports.escapeHtml = escapeHtml;
345
+ exports.findNode = findNode;
346
+ exports.findNodes = findNodes;
347
+ exports.findNodesBy = findNodesBy;
348
+ exports.findParent = findParent;
349
+ exports.isLiteral = isLiteral;
350
+ exports.isNodeType = isNodeType;
351
+ exports.isParent = isParent;
352
+ exports.sanitizeHtml = sanitizeHtml;
353
+ exports.slugify = slugify;
354
+ exports.stripHtml = stripHtml;
355
+ exports.traverseAst = traverseAst;
356
+ exports.traverseAstWithCallbacks = traverseAstWithCallbacks;
357
+ exports.uniqueSlugify = uniqueSlugify;
358
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/types/index.ts","../src/ast/traverse.ts","../src/ast/query.ts","../src/string/slugify.ts","../src/string/sanitize.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"mappings":";;AAiDA;;AAEG;AACG,SAAU,QAAQ,CAAC,IAA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;QACpB;;QAGA,MAAM,cAAc,GAAa,EAAE;QACnC,MAAM,SAAS,GAAG,kDAAkD;AACpE,QAAA,IAAI,SAAS;AAEb,QAAA,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE;AACnD,YAAA,MAAM,GAAG,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,SAAS;AAC1C,YAAA,MAAM,IAAI,GAAG,QAAQ,CAAC,WAAW,EAAE;AAEnC,YAAA,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBAC3B,IAAI,KAAK,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;;AAGhC,gBAAA,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK,KAAK,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;oBAC5E,KAAK,GAAG,EAAE;gBACZ;gBAEA,cAAc,CAAC,IAAI,CAAC,CAAA,EAAG,IAAI,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA,CAAG,CAAC;YAC3C;QACF;QAEA,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE;AAC/E,QAAA,OAAO,CAAA,CAAA,EAAI,GAAG,CAAA,EAAG,OAAO,GAAG;AAC7B,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;AAEA;;;;;AAKG;AACG,SAAU,SAAS,CAAC,IAAY,EAAA;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;AACrC;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,144 @@
1
+ import { Root, Content, Parent, Literal } from 'mdast';
2
+ export { Literal, Parent } from 'mdast';
3
+ import { Node } from 'unist';
4
+
5
+ /**
6
+ * All possible markdown node types
7
+ */
8
+ type MdNode = Root | Content;
9
+ /**
10
+ * Root node of markdown AST
11
+ */
12
+ type MdRoot = Root;
13
+ /**
14
+ * Visitor function for AST traversal
15
+ */
16
+ type Visitor<T extends Node = MdNode> = (node: T, index: number | undefined, parent: Parent | undefined) => void | boolean;
17
+ /**
18
+ * Plugin options base interface
19
+ */
20
+ interface PluginOptions {
21
+ [key: string]: unknown;
22
+ }
23
+ /**
24
+ * Position information in source
25
+ */
26
+ interface Position {
27
+ line: number;
28
+ column: number;
29
+ offset?: number;
30
+ }
31
+ /**
32
+ * Location in source
33
+ */
34
+ interface Location {
35
+ start: Position;
36
+ end: Position;
37
+ }
38
+ /**
39
+ * Type guard to check if node is a parent node
40
+ */
41
+ declare function isParent(node: Node): node is Parent;
42
+ /**
43
+ * Type guard to check if node is a literal node
44
+ */
45
+ declare function isLiteral(node: Node): node is Literal;
46
+ /**
47
+ * Type guard to check if node has specific type
48
+ */
49
+ declare function isNodeType<T extends MdNode>(node: Node, type: T['type']): node is T;
50
+
51
+ /**
52
+ * Traverse AST in depth-first order
53
+ *
54
+ * @param node - Root node to start traversal
55
+ * @param visitor - Visitor function called for each node
56
+ * Return `false` to skip children of current node
57
+ * Return `true` or `undefined` to continue
58
+ */
59
+ declare function traverseAst<T extends Node = MdNode>(node: T, visitor: Visitor<T>): void;
60
+ /**
61
+ * Traverse AST with enter and leave callbacks
62
+ *
63
+ * @param node - Root node to start traversal
64
+ * @param callbacks - Object with optional enter and leave functions
65
+ */
66
+ declare function traverseAstWithCallbacks<T extends Node = MdNode>(node: T, callbacks: {
67
+ enter?: Visitor<T>;
68
+ leave?: Visitor<T>;
69
+ }): void;
70
+
71
+ /**
72
+ * Find all nodes of a specific type in the AST
73
+ *
74
+ * @param node - Root node to search from
75
+ * @param type - Node type to find
76
+ * @returns Array of matching nodes
77
+ */
78
+ declare function findNodes<T extends Node = MdNode>(node: Node, type: string): T[];
79
+ /**
80
+ * Find the first node of a specific type in the AST
81
+ *
82
+ * @param node - Root node to search from
83
+ * @param type - Node type to find
84
+ * @returns The first matching node or undefined
85
+ */
86
+ declare function findNode<T extends Node = MdNode>(node: Node, type: string): T | undefined;
87
+ /**
88
+ * Find all nodes matching a predicate
89
+ *
90
+ * @param node - Root node to search from
91
+ * @param predicate - Function to test each node
92
+ * @returns Array of matching nodes
93
+ */
94
+ declare function findNodesBy<T extends Node = MdNode>(node: Node, predicate: (node: Node) => boolean): T[];
95
+ /**
96
+ * Get the parent of a node in the AST
97
+ * Note: This requires traversing from root, use sparingly
98
+ *
99
+ * @param root - Root node of the AST
100
+ * @param target - Node to find parent of
101
+ * @returns Parent node or undefined if not found or is root
102
+ */
103
+ declare function findParent(root: Node, target: Node): Parent | undefined;
104
+
105
+ /**
106
+ * Convert text to URL-safe slug
107
+ *
108
+ * @param text - Text to slugify
109
+ * @returns URL-safe slug
110
+ */
111
+ declare function slugify(text: string): string;
112
+ /**
113
+ * Generate unique slug with counter suffix for duplicates
114
+ *
115
+ * @param text - Text to slugify
116
+ * @param existingSlugs - Set of existing slugs to check against
117
+ * @returns Unique slug
118
+ */
119
+ declare function uniqueSlugify(text: string, existingSlugs: Set<string>): string;
120
+
121
+ /**
122
+ * Escape HTML special characters
123
+ *
124
+ * @param text - Text to escape
125
+ * @returns Escaped text safe for HTML insertion
126
+ */
127
+ declare function escapeHtml(text: string): string;
128
+ /**
129
+ * Sanitize HTML string by removing dangerous content
130
+ *
131
+ * @param html - HTML string to sanitize
132
+ * @returns Sanitized HTML string
133
+ */
134
+ declare function sanitizeHtml(html: string): string;
135
+ /**
136
+ * Strip all HTML tags from a string
137
+ *
138
+ * @param html - HTML string to strip
139
+ * @returns Plain text without HTML tags
140
+ */
141
+ declare function stripHtml(html: string): string;
142
+
143
+ export { escapeHtml, findNode, findNodes, findNodesBy, findParent, isLiteral, isNodeType, isParent, sanitizeHtml, slugify, stripHtml, traverseAst, traverseAstWithCallbacks, uniqueSlugify };
144
+ export type { Location, MdNode, MdRoot, PluginOptions, Position, Visitor };