@bernierllc/markdown-parser 1.5.1 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/markdown-parser",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "High-performance markdown parser with CommonMark, GFM, and plugin support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Bernier LLC",
20
20
  "license": "SEE LICENSE IN LICENSE",
21
21
  "dependencies": {
22
- "@bernierllc/logger": "1.7.1",
23
- "@bernierllc/crypto-utils": "1.4.0"
22
+ "@bernierllc/crypto-utils": "1.4.0",
23
+ "@bernierllc/logger": "2.0.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/jest": "^29.0.0",
@@ -1,46 +0,0 @@
1
- import { MarkdownParserConfig, ParseResult } from './types';
2
- /**
3
- * High-performance markdown parser with caching and plugin support
4
- */
5
- export declare class MarkdownParser {
6
- private config;
7
- private cacheManager;
8
- private logger;
9
- constructor(config?: MarkdownParserConfig);
10
- /**
11
- * Parse markdown string to AST
12
- */
13
- parse(markdown: string): Promise<ParseResult>;
14
- /**
15
- * Core parsing logic (CommonMark + GFM)
16
- */
17
- private parseToAST;
18
- /**
19
- * Parse inline formatting (bold, italic, code, links, images)
20
- */
21
- private parseInline;
22
- /**
23
- * Parse GFM table
24
- */
25
- private parseTable;
26
- /**
27
- * Create position information
28
- */
29
- private createPosition;
30
- /**
31
- * Clear the parse cache
32
- */
33
- clearCache(): void;
34
- /**
35
- * Get cache statistics
36
- */
37
- getCacheStats(): {
38
- size: number;
39
- enabled: boolean;
40
- };
41
- /**
42
- * Prune expired cache entries
43
- */
44
- pruneCache(): number;
45
- }
46
- //# sourceMappingURL=MarkdownParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MarkdownParser.d.ts","sourceRoot":"","sources":["../src/MarkdownParser.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAqB,MAAM,SAAS,CAAC;AAI/E;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,oBAAoB;IAoBzC;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA8DnD;;OAEG;YACW,UAAU;IAmLxB;;OAEG;IACH,OAAO,CAAC,WAAW;IA4HnB;;OAEG;IACH,OAAO,CAAC,UAAU;IAyDlB;;OAEG;IACH,OAAO,CAAC,cAAc;IAOtB;;OAEG;IACH,UAAU,IAAI,IAAI;IAOlB;;OAEG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE;IAOnD;;OAEG;IACH,UAAU,IAAI,MAAM;CAQrB"}
@@ -1,461 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MarkdownParser = void 0;
11
- const cache_1 = require("./utils/cache");
12
- const ast_utils_1 = require("./utils/ast-utils");
13
- /**
14
- * High-performance markdown parser with caching and plugin support
15
- */
16
- class MarkdownParser {
17
- config;
18
- cacheManager;
19
- logger;
20
- constructor(config) {
21
- this.config = {
22
- gfm: config?.gfm ?? true,
23
- commonmark: config?.commonmark ?? true,
24
- plugins: config?.plugins ?? [],
25
- cache: {
26
- enabled: config?.cache?.enabled ?? false,
27
- maxSize: config?.cache?.maxSize ?? 1000,
28
- ttl: config?.cache?.ttl ?? 3600,
29
- },
30
- logger: config?.logger ?? console,
31
- };
32
- this.cacheManager = this.config.cache.enabled
33
- ? new cache_1.CacheManager(this.config.cache.maxSize, this.config.cache.ttl)
34
- : null;
35
- this.logger = this.config.logger;
36
- }
37
- /**
38
- * Parse markdown string to AST
39
- */
40
- async parse(markdown) {
41
- const startTime = Date.now();
42
- // Check cache
43
- if (this.cacheManager) {
44
- const cacheKey = this.cacheManager.generateKey(markdown);
45
- const cached = this.cacheManager.get(cacheKey);
46
- if (cached) {
47
- this.logger.debug('Markdown parse cache hit', { cacheKey });
48
- return {
49
- success: true,
50
- ast: cached,
51
- metadata: {
52
- parseTime: Date.now() - startTime,
53
- nodeCount: (0, ast_utils_1.countNodes)(cached),
54
- cached: true,
55
- },
56
- };
57
- }
58
- }
59
- try {
60
- // Parse markdown to AST
61
- let ast = await this.parseToAST(markdown);
62
- // Apply plugins
63
- for (const plugin of this.config.plugins) {
64
- ast = plugin.transform(ast);
65
- }
66
- // Cache result
67
- if (this.cacheManager) {
68
- const cacheKey = this.cacheManager.generateKey(markdown);
69
- this.cacheManager.set(cacheKey, ast);
70
- }
71
- const parseTime = Date.now() - startTime;
72
- this.logger.debug('Markdown parsed successfully', {
73
- parseTime,
74
- nodeCount: (0, ast_utils_1.countNodes)(ast),
75
- });
76
- return {
77
- success: true,
78
- ast,
79
- metadata: {
80
- parseTime,
81
- nodeCount: (0, ast_utils_1.countNodes)(ast),
82
- cached: false,
83
- },
84
- };
85
- }
86
- catch (err) {
87
- const error = err instanceof Error ? err : new Error('Unknown parse error');
88
- this.logger.error('Markdown parse failed', error);
89
- return {
90
- success: false,
91
- error: error.message,
92
- };
93
- }
94
- }
95
- /**
96
- * Core parsing logic (CommonMark + GFM)
97
- */
98
- async parseToAST(markdown) {
99
- const lines = markdown.split('\n');
100
- const root = { type: 'root', children: [] };
101
- let lineNumber = 0;
102
- let i = 0;
103
- while (i < lines.length) {
104
- const line = lines[i];
105
- lineNumber = i + 1;
106
- // Skip empty lines
107
- if (!line.trim()) {
108
- i++;
109
- continue;
110
- }
111
- // Heading
112
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
113
- if (headingMatch) {
114
- const level = headingMatch[1].length;
115
- const text = headingMatch[2].trim();
116
- root.children.push({
117
- type: 'heading',
118
- attributes: { level },
119
- children: this.parseInline(text),
120
- position: this.createPosition(lineNumber, 0, line.length),
121
- });
122
- i++;
123
- continue;
124
- }
125
- // Horizontal rule
126
- if (line.match(/^(\*{3,}|-{3,}|_{3,})$/)) {
127
- root.children.push({
128
- type: 'horizontalRule',
129
- position: this.createPosition(lineNumber, 0, line.length),
130
- });
131
- i++;
132
- continue;
133
- }
134
- // Code block (fenced)
135
- if (line.match(/^```/)) {
136
- const language = line.slice(3).trim();
137
- const codeLines = [];
138
- const startLine = lineNumber;
139
- i++;
140
- while (i < lines.length && !lines[i].match(/^```/)) {
141
- codeLines.push(lines[i]);
142
- i++;
143
- }
144
- root.children.push({
145
- type: 'codeBlock',
146
- value: codeLines.join('\n'),
147
- attributes: { language: language || 'plaintext' },
148
- position: this.createPosition(startLine, 0, i - startLine),
149
- });
150
- i++; // Skip closing ```
151
- continue;
152
- }
153
- // Blockquote
154
- if (line.match(/^>\s/)) {
155
- const quoteLines = [];
156
- const startLine = lineNumber;
157
- while (i < lines.length && lines[i].match(/^>\s/)) {
158
- quoteLines.push(lines[i].replace(/^>\s/, ''));
159
- i++;
160
- }
161
- const quoteContent = quoteLines.join('\n');
162
- const quotedAst = await this.parseToAST(quoteContent);
163
- root.children.push({
164
- type: 'blockquote',
165
- children: quotedAst.children,
166
- position: this.createPosition(startLine, 0, i - startLine),
167
- });
168
- continue;
169
- }
170
- // Task list (GFM) - Check BEFORE unordered list since "- [ ]" matches "- " pattern
171
- if (this.config.gfm && line.match(/^[\s]*-\s\[\s*[ xX]\s*\]/)) {
172
- const checked = line.includes('[x]') || line.includes('[X]');
173
- const text = line.replace(/^[\s]*-\s\[\s*[ xX]\s*\]\s*/, '');
174
- root.children.push({
175
- type: 'taskListItem',
176
- attributes: { checked },
177
- children: this.parseInline(text),
178
- position: this.createPosition(lineNumber, 0, line.length),
179
- });
180
- i++;
181
- continue;
182
- }
183
- // Unordered list
184
- if (line.match(/^[\s]*[-*+]\s/)) {
185
- const listItems = [];
186
- const startLine = lineNumber;
187
- while (i < lines.length && lines[i].match(/^[\s]*[-*+]\s/)) {
188
- const itemText = lines[i].replace(/^[\s]*[-*+]\s/, '');
189
- listItems.push({
190
- type: 'listItem',
191
- children: this.parseInline(itemText),
192
- });
193
- i++;
194
- }
195
- root.children.push({
196
- type: 'list',
197
- attributes: { ordered: false },
198
- children: listItems,
199
- position: this.createPosition(startLine, 0, i - startLine),
200
- });
201
- continue;
202
- }
203
- // Ordered list
204
- if (line.match(/^[\s]*\d+\.\s/)) {
205
- const listItems = [];
206
- const startLine = lineNumber;
207
- while (i < lines.length && lines[i].match(/^[\s]*\d+\.\s/)) {
208
- const itemText = lines[i].replace(/^[\s]*\d+\.\s/, '');
209
- listItems.push({
210
- type: 'listItem',
211
- children: this.parseInline(itemText),
212
- });
213
- i++;
214
- }
215
- root.children.push({
216
- type: 'list',
217
- attributes: { ordered: true },
218
- children: listItems,
219
- position: this.createPosition(startLine, 0, i - startLine),
220
- });
221
- continue;
222
- }
223
- // Table (GFM)
224
- if (this.config.gfm && i + 1 < lines.length && lines[i + 1].match(/^\|?[\s]*:?-+:?[\s]*\|/)) {
225
- const table = this.parseTable(lines, i);
226
- root.children.push(table.node);
227
- i = table.nextIndex;
228
- continue;
229
- }
230
- // Paragraph (default)
231
- const paragraphLines = [line];
232
- const startLine = lineNumber;
233
- i++;
234
- // Collect continuation lines
235
- while (i < lines.length &&
236
- lines[i].trim() &&
237
- !lines[i].match(/^(#{1,6}\s|```|>\s|[-*+]\s|\d+\.\s|\*{3,}|-{3,}|_{3,})/)) {
238
- paragraphLines.push(lines[i]);
239
- i++;
240
- }
241
- const paragraphText = paragraphLines.join(' ');
242
- root.children.push({
243
- type: 'paragraph',
244
- children: this.parseInline(paragraphText),
245
- position: this.createPosition(startLine, 0, paragraphLines.length),
246
- });
247
- }
248
- return root;
249
- }
250
- /**
251
- * Parse inline formatting (bold, italic, code, links, images)
252
- */
253
- parseInline(text) {
254
- const nodes = [];
255
- let remaining = text;
256
- while (remaining.length > 0) {
257
- // Bold (**text** or __text__)
258
- const boldMatch = remaining.match(/^(\*\*|__)(.+?)\1/);
259
- if (boldMatch) {
260
- nodes.push({
261
- type: 'strong',
262
- children: [{ type: 'text', value: boldMatch[2] }],
263
- });
264
- remaining = remaining.slice(boldMatch[0].length);
265
- continue;
266
- }
267
- // Italic (*text* or _text_)
268
- const italicMatch = remaining.match(/^(\*|_)(.+?)\1/);
269
- if (italicMatch) {
270
- nodes.push({
271
- type: 'emphasis',
272
- children: [{ type: 'text', value: italicMatch[2] }],
273
- });
274
- remaining = remaining.slice(italicMatch[0].length);
275
- continue;
276
- }
277
- // Inline code (`code`)
278
- const codeMatch = remaining.match(/^`([^`]+)`/);
279
- if (codeMatch) {
280
- nodes.push({
281
- type: 'code',
282
- value: codeMatch[1],
283
- });
284
- remaining = remaining.slice(codeMatch[0].length);
285
- continue;
286
- }
287
- // Strikethrough (GFM: ~~text~~)
288
- if (this.config.gfm) {
289
- const strikeMatch = remaining.match(/^~~(.+?)~~/);
290
- if (strikeMatch) {
291
- nodes.push({
292
- type: 'strikethrough',
293
- children: [{ type: 'text', value: strikeMatch[1] }],
294
- });
295
- remaining = remaining.slice(strikeMatch[0].length);
296
- continue;
297
- }
298
- }
299
- // Image (![alt](url))
300
- const imageMatch = remaining.match(/^!\[([^\]]*)\]\(([^)]+)\)/);
301
- if (imageMatch) {
302
- nodes.push({
303
- type: 'image',
304
- attributes: {
305
- alt: imageMatch[1],
306
- src: imageMatch[2],
307
- },
308
- });
309
- remaining = remaining.slice(imageMatch[0].length);
310
- continue;
311
- }
312
- // Link ([text](url))
313
- const linkMatch = remaining.match(/^\[([^\]]+)\]\(([^)]+)\)/);
314
- if (linkMatch) {
315
- nodes.push({
316
- type: 'link',
317
- attributes: {
318
- href: linkMatch[2],
319
- },
320
- children: [{ type: 'text', value: linkMatch[1] }],
321
- });
322
- remaining = remaining.slice(linkMatch[0].length);
323
- continue;
324
- }
325
- // Autolink (GFM: https://example.com)
326
- if (this.config.gfm) {
327
- const autolinkMatch = remaining.match(/^(https?:\/\/[^\s]+)/);
328
- if (autolinkMatch) {
329
- nodes.push({
330
- type: 'autolink',
331
- attributes: {
332
- href: autolinkMatch[1],
333
- },
334
- children: [{ type: 'text', value: autolinkMatch[1] }],
335
- });
336
- remaining = remaining.slice(autolinkMatch[0].length);
337
- continue;
338
- }
339
- }
340
- // Line break (two spaces + newline or backslash + newline)
341
- if (remaining.match(/^( \n|\\\n)/)) {
342
- nodes.push({ type: 'lineBreak' });
343
- remaining = remaining.slice(remaining.match(/^( \n|\\\n)/)[0].length);
344
- continue;
345
- }
346
- // Plain text (consume until next special character or URL)
347
- const textMatch = remaining.match(/^((?:(?!https?:\/\/)[^*_`~!\[\n])+)/);
348
- if (textMatch) {
349
- nodes.push({
350
- type: 'text',
351
- value: textMatch[1],
352
- });
353
- remaining = remaining.slice(textMatch[1].length);
354
- continue;
355
- }
356
- // Single character fallback
357
- nodes.push({
358
- type: 'text',
359
- value: remaining[0],
360
- });
361
- remaining = remaining.slice(1);
362
- }
363
- return nodes;
364
- }
365
- /**
366
- * Parse GFM table
367
- */
368
- parseTable(lines, startIndex) {
369
- const headerLine = lines[startIndex];
370
- const separatorLine = lines[startIndex + 1];
371
- // Parse header
372
- const headerCells = headerLine.split('|').filter((cell) => cell.trim());
373
- const headerRow = {
374
- type: 'tableRow',
375
- children: headerCells.map((cell) => ({
376
- type: 'tableCell',
377
- attributes: { header: true },
378
- children: this.parseInline(cell.trim()),
379
- })),
380
- };
381
- // Parse alignment from separator
382
- const alignments = separatorLine
383
- .split('|')
384
- .filter((cell) => cell.trim())
385
- .map((cell) => {
386
- const trimmed = cell.trim();
387
- if (trimmed.startsWith(':') && trimmed.endsWith(':'))
388
- return 'center';
389
- if (trimmed.endsWith(':'))
390
- return 'right';
391
- if (trimmed.startsWith(':'))
392
- return 'left';
393
- return 'left';
394
- });
395
- // Parse body rows
396
- const bodyRows = [];
397
- let i = startIndex + 2;
398
- while (i < lines.length && lines[i].includes('|')) {
399
- const cells = lines[i].split('|').filter((cell) => cell.trim());
400
- bodyRows.push({
401
- type: 'tableRow',
402
- children: cells.map((cell, index) => ({
403
- type: 'tableCell',
404
- attributes: {
405
- header: false,
406
- align: alignments[index] || 'left',
407
- },
408
- children: this.parseInline(cell.trim()),
409
- })),
410
- });
411
- i++;
412
- }
413
- return {
414
- node: {
415
- type: 'table',
416
- children: [headerRow, ...bodyRows],
417
- position: this.createPosition(startIndex + 1, 0, i - startIndex),
418
- },
419
- nextIndex: i,
420
- };
421
- }
422
- /**
423
- * Create position information
424
- */
425
- createPosition(line, column, length) {
426
- return {
427
- start: { line, column, offset: 0 },
428
- end: { line: line + length - 1, column: column + length, offset: 0 },
429
- };
430
- }
431
- /**
432
- * Clear the parse cache
433
- */
434
- clearCache() {
435
- if (this.cacheManager) {
436
- this.cacheManager.clear();
437
- this.logger.debug('Markdown parse cache cleared');
438
- }
439
- }
440
- /**
441
- * Get cache statistics
442
- */
443
- getCacheStats() {
444
- return {
445
- size: this.cacheManager?.size() ?? 0,
446
- enabled: this.config.cache.enabled,
447
- };
448
- }
449
- /**
450
- * Prune expired cache entries
451
- */
452
- pruneCache() {
453
- if (this.cacheManager) {
454
- const removed = this.cacheManager.prune();
455
- this.logger.debug('Pruned expired cache entries', { removed });
456
- return removed;
457
- }
458
- return 0;
459
- }
460
- }
461
- exports.MarkdownParser = MarkdownParser;
package/dist/errors.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export type MarkdownParserErrorCode = 'MARKDOWN_PARSER_ERROR' | 'INVALID_INPUT' | 'OPERATION_FAILED';
2
- export interface MarkdownParserErrorOptions {
3
- cause?: Error;
4
- code?: MarkdownParserErrorCode;
5
- context?: Record<string, unknown>;
6
- }
7
- export declare class MarkdownParserError extends Error {
8
- readonly code: MarkdownParserErrorCode;
9
- readonly context?: Record<string, unknown>;
10
- constructor(message: string, options?: MarkdownParserErrorOptions);
11
- }
12
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,uBAAuB,GAC/B,uBAAuB,GACvB,eAAe,GACf,kBAAkB,CAAC;AAEvB,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,0BAA0B;CASlE"}
package/dist/errors.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code only within the scope of the project it was delivered for.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MarkdownParserError = void 0;
11
- class MarkdownParserError extends Error {
12
- code;
13
- context;
14
- constructor(message, options) {
15
- super(message, options?.cause ? { cause: options.cause } : undefined);
16
- this.name = 'MarkdownParserError';
17
- this.code = options?.code ?? 'MARKDOWN_PARSER_ERROR';
18
- if (options?.context !== undefined) {
19
- this.context = options.context;
20
- }
21
- Error.captureStackTrace?.(this, this.constructor);
22
- }
23
- }
24
- exports.MarkdownParserError = MarkdownParserError;
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { MarkdownParser } from './MarkdownParser';
2
- export * from './types';
3
- export * from './plugins';
4
- export * from './utils/ast-utils';
5
- export { CacheManager } from './utils/cache';
6
- export { MarkdownParserError } from './errors';
7
- export type { MarkdownParserErrorCode, MarkdownParserErrorOptions, } from './errors';
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,YAAY,EACV,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,UAAU,CAAC"}
package/dist/index.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.MarkdownParserError = exports.CacheManager = exports.MarkdownParser = void 0;
25
- var MarkdownParser_1 = require("./MarkdownParser");
26
- Object.defineProperty(exports, "MarkdownParser", { enumerable: true, get: function () { return MarkdownParser_1.MarkdownParser; } });
27
- __exportStar(require("./types"), exports);
28
- __exportStar(require("./plugins"), exports);
29
- __exportStar(require("./utils/ast-utils"), exports);
30
- var cache_1 = require("./utils/cache");
31
- Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return cache_1.CacheManager; } });
32
- // Errors
33
- var errors_1 = require("./errors");
34
- Object.defineProperty(exports, "MarkdownParserError", { enumerable: true, get: function () { return errors_1.MarkdownParserError; } });
@@ -1,6 +0,0 @@
1
- import { MarkdownPlugin } from '../types';
2
- /**
3
- * CommonMark specification plugin
4
- */
5
- export declare const commonmarkPlugin: MarkdownPlugin;
6
- //# sourceMappingURL=commonmark.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commonmark.d.ts","sourceRoot":"","sources":["../../src/plugins/commonmark.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAW,MAAM,UAAU,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,cAS9B,CAAC"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.commonmarkPlugin = void 0;
11
- /**
12
- * CommonMark specification plugin
13
- */
14
- exports.commonmarkPlugin = {
15
- name: 'commonmark',
16
- version: '1.0.0',
17
- transform: (ast) => {
18
- // This is a placeholder - CommonMark features are built into the main parser
19
- // when commonmark config is enabled. This plugin can be used for additional
20
- // post-processing transformations specific to CommonMark.
21
- return ast;
22
- },
23
- };
@@ -1,6 +0,0 @@
1
- import { MarkdownPlugin } from '../types';
2
- /**
3
- * GitHub-Flavored Markdown extensions plugin
4
- */
5
- export declare const gfmPlugin: MarkdownPlugin;
6
- //# sourceMappingURL=gfm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gfm.d.ts","sourceRoot":"","sources":["../../src/plugins/gfm.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAW,MAAM,UAAU,CAAC;AAEnD;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,cASvB,CAAC"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.gfmPlugin = void 0;
11
- /**
12
- * GitHub-Flavored Markdown extensions plugin
13
- */
14
- exports.gfmPlugin = {
15
- name: 'gfm',
16
- version: '1.0.0',
17
- transform: (ast) => {
18
- // This is a placeholder - GFM features are built into the main parser
19
- // when gfm config is enabled. This plugin can be used for additional
20
- // post-processing transformations specific to GFM.
21
- return ast;
22
- },
23
- };
@@ -1,3 +0,0 @@
1
- export * from './gfm';
2
- export * from './commonmark';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAQA,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC"}
@@ -1,25 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- var desc = Object.getOwnPropertyDescriptor(m, k);
12
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
- desc = { enumerable: true, get: function() { return m[k]; } };
14
- }
15
- Object.defineProperty(o, k2, desc);
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- __exportStar(require("./gfm"), exports);
25
- __exportStar(require("./commonmark"), exports);
package/dist/types.d.ts DELETED
@@ -1,78 +0,0 @@
1
- import { Logger } from '@bernierllc/logger';
2
- /**
3
- * Markdown Parser Configuration
4
- */
5
- export interface MarkdownParserConfig {
6
- /** Enable GitHub-Flavored Markdown extensions */
7
- gfm?: boolean;
8
- /** Enable CommonMark strict mode */
9
- commonmark?: boolean;
10
- /** Custom plugins to apply */
11
- plugins?: MarkdownPlugin[];
12
- /** Enable caching of parsed AST */
13
- cache?: {
14
- enabled: boolean;
15
- maxSize?: number;
16
- ttl?: number;
17
- };
18
- /** Logger instance */
19
- logger?: Logger;
20
- }
21
- /**
22
- * Position information in source document
23
- */
24
- export interface Position {
25
- start: {
26
- line: number;
27
- column: number;
28
- offset: number;
29
- };
30
- end: {
31
- line: number;
32
- column: number;
33
- offset: number;
34
- };
35
- }
36
- /**
37
- * Markdown Abstract Syntax Tree Node
38
- */
39
- export interface ASTNode {
40
- type: NodeType;
41
- value?: string;
42
- children?: ASTNode[];
43
- attributes?: Record<string, unknown>;
44
- position?: Position;
45
- }
46
- /**
47
- * Node types supported by the parser
48
- */
49
- export type NodeType = 'root' | 'heading' | 'paragraph' | 'text' | 'emphasis' | 'strong' | 'link' | 'image' | 'code' | 'codeBlock' | 'blockquote' | 'list' | 'listItem' | 'table' | 'tableRow' | 'tableCell' | 'html' | 'horizontalRule' | 'lineBreak' | 'strikethrough' | 'taskList' | 'taskListItem' | 'autolink' | 'footnote' | 'footnoteReference';
50
- /**
51
- * Parse result with metadata
52
- */
53
- export interface ParseResult {
54
- success: boolean;
55
- ast?: ASTNode;
56
- error?: string;
57
- metadata?: {
58
- parseTime: number;
59
- nodeCount: number;
60
- cached: boolean;
61
- };
62
- }
63
- /**
64
- * Plugin interface for custom extensions
65
- */
66
- export interface MarkdownPlugin {
67
- name: string;
68
- version: string;
69
- transform: (ast: ASTNode) => ASTNode;
70
- }
71
- /**
72
- * Cache entry structure
73
- */
74
- export interface CacheEntry {
75
- ast: ASTNode;
76
- timestamp: number;
77
- }
78
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,oCAAoC;IACpC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAE3B,mCAAmC;IACnC,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IAEF,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,SAAS,GACT,WAAW,GACX,MAAM,GACN,UAAU,GACV,QAAQ,GACR,MAAM,GACN,OAAO,GACP,MAAM,GACN,WAAW,GACX,YAAY,GACZ,MAAM,GACN,UAAU,GACV,OAAO,GACP,UAAU,GACV,WAAW,GACX,MAAM,GACN,gBAAgB,GAChB,WAAW,GAEX,eAAe,GACf,UAAU,GACV,cAAc,GACd,UAAU,GACV,UAAU,GACV,mBAAmB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,OAAO,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB"}
package/dist/types.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +0,0 @@
1
- import { ASTNode } from '../types';
2
- /**
3
- * Count total nodes in AST
4
- */
5
- export declare function countNodes(node: ASTNode): number;
6
- /**
7
- * Visit each node in the AST
8
- */
9
- export declare function visitNodes(node: ASTNode, visitor: (node: ASTNode) => void): void;
10
- /**
11
- * Transform AST nodes recursively
12
- */
13
- export declare function transformNodes(node: ASTNode, transformer: (node: ASTNode) => ASTNode): ASTNode;
14
- /**
15
- * Find nodes matching a predicate
16
- */
17
- export declare function findNodes(node: ASTNode, predicate: (node: ASTNode) => boolean): ASTNode[];
18
- /**
19
- * Clone an AST node deeply
20
- */
21
- export declare function cloneNode(node: ASTNode): ASTNode;
22
- //# sourceMappingURL=ast-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ast-utils.d.ts","sourceRoot":"","sources":["../../src/utils/ast-utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAQhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAOhF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAS9F;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,EAAE,CAWzF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAYhD"}
@@ -1,81 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.countNodes = countNodes;
11
- exports.visitNodes = visitNodes;
12
- exports.transformNodes = transformNodes;
13
- exports.findNodes = findNodes;
14
- exports.cloneNode = cloneNode;
15
- /**
16
- * Count total nodes in AST
17
- */
18
- function countNodes(node) {
19
- let count = 1;
20
- if (node.children) {
21
- for (const child of node.children) {
22
- count += countNodes(child);
23
- }
24
- }
25
- return count;
26
- }
27
- /**
28
- * Visit each node in the AST
29
- */
30
- function visitNodes(node, visitor) {
31
- visitor(node);
32
- if (node.children) {
33
- for (const child of node.children) {
34
- visitNodes(child, visitor);
35
- }
36
- }
37
- }
38
- /**
39
- * Transform AST nodes recursively
40
- */
41
- function transformNodes(node, transformer) {
42
- const transformed = transformer(node);
43
- if (transformed.children) {
44
- return {
45
- ...transformed,
46
- children: transformed.children.map((child) => transformNodes(child, transformer)),
47
- };
48
- }
49
- return transformed;
50
- }
51
- /**
52
- * Find nodes matching a predicate
53
- */
54
- function findNodes(node, predicate) {
55
- const results = [];
56
- if (predicate(node)) {
57
- results.push(node);
58
- }
59
- if (node.children) {
60
- for (const child of node.children) {
61
- results.push(...findNodes(child, predicate));
62
- }
63
- }
64
- return results;
65
- }
66
- /**
67
- * Clone an AST node deeply
68
- */
69
- function cloneNode(node) {
70
- return {
71
- ...node,
72
- children: node.children ? node.children.map(cloneNode) : undefined,
73
- attributes: node.attributes ? { ...node.attributes } : undefined,
74
- position: node.position
75
- ? {
76
- start: { ...node.position.start },
77
- end: { ...node.position.end },
78
- }
79
- : undefined,
80
- };
81
- }
@@ -1,39 +0,0 @@
1
- import { ASTNode } from '../types';
2
- /**
3
- * Cache manager for parsed markdown AST
4
- */
5
- export declare class CacheManager {
6
- private cache;
7
- private maxSize;
8
- private ttl;
9
- constructor(maxSize?: number, ttl?: number);
10
- /**
11
- * Generate cache key from markdown content
12
- */
13
- generateKey(markdown: string): string;
14
- /**
15
- * Get AST from cache if valid
16
- */
17
- get(key: string): ASTNode | null;
18
- /**
19
- * Store AST in cache with size limit
20
- */
21
- set(key: string, ast: ASTNode): void;
22
- /**
23
- * Check if key exists in cache
24
- */
25
- has(key: string): boolean;
26
- /**
27
- * Clear all cache entries
28
- */
29
- clear(): void;
30
- /**
31
- * Get current cache size
32
- */
33
- size(): number;
34
- /**
35
- * Remove expired entries
36
- */
37
- prune(): number;
38
- }
39
- //# sourceMappingURL=cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/utils/cache.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAc,MAAM,UAAU,CAAC;AAG/C;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,GAAG,CAAS;gBAER,OAAO,GAAE,MAAa,EAAE,GAAG,GAAE,MAAa;IAMtD;;OAEG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIrC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAgBhC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI;IAapC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,IAAI,IAAI,MAAM;IAId;;OAEG;IACH,KAAK,IAAI,MAAM;CAchB"}
@@ -1,94 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.CacheManager = void 0;
11
- const crypto_1 = require("crypto");
12
- /**
13
- * Cache manager for parsed markdown AST
14
- */
15
- class CacheManager {
16
- cache;
17
- maxSize;
18
- ttl; // Time to live in seconds
19
- constructor(maxSize = 1000, ttl = 3600) {
20
- this.cache = new Map();
21
- this.maxSize = maxSize;
22
- this.ttl = ttl;
23
- }
24
- /**
25
- * Generate cache key from markdown content
26
- */
27
- generateKey(markdown) {
28
- return (0, crypto_1.createHash)('sha256').update(markdown).digest('hex').substring(0, 16);
29
- }
30
- /**
31
- * Get AST from cache if valid
32
- */
33
- get(key) {
34
- const entry = this.cache.get(key);
35
- if (!entry) {
36
- return null;
37
- }
38
- // Check TTL
39
- const age = (Date.now() - entry.timestamp) / 1000;
40
- if (age > this.ttl) {
41
- this.cache.delete(key);
42
- return null;
43
- }
44
- return entry.ast;
45
- }
46
- /**
47
- * Store AST in cache with size limit
48
- */
49
- set(key, ast) {
50
- // Enforce max size (FIFO eviction)
51
- if (this.cache.size >= this.maxSize) {
52
- const oldestKey = this.cache.keys().next().value;
53
- this.cache.delete(oldestKey);
54
- }
55
- this.cache.set(key, {
56
- ast,
57
- timestamp: Date.now(),
58
- });
59
- }
60
- /**
61
- * Check if key exists in cache
62
- */
63
- has(key) {
64
- return this.get(key) !== null;
65
- }
66
- /**
67
- * Clear all cache entries
68
- */
69
- clear() {
70
- this.cache.clear();
71
- }
72
- /**
73
- * Get current cache size
74
- */
75
- size() {
76
- return this.cache.size;
77
- }
78
- /**
79
- * Remove expired entries
80
- */
81
- prune() {
82
- const now = Date.now();
83
- let removed = 0;
84
- for (const [key, entry] of this.cache.entries()) {
85
- const age = (now - entry.timestamp) / 1000;
86
- if (age > this.ttl) {
87
- this.cache.delete(key);
88
- removed++;
89
- }
90
- }
91
- return removed;
92
- }
93
- }
94
- exports.CacheManager = CacheManager;