quikdown 1.1.1 → 1.2.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.
Files changed (58) hide show
  1. package/README.md +35 -3
  2. package/dist/quikdown.cjs +5 -5
  3. package/dist/quikdown.dark.css +1 -1
  4. package/dist/quikdown.esm.js +5 -5
  5. package/dist/quikdown.esm.min.js +2 -2
  6. package/dist/quikdown.esm.min.js.map +1 -1
  7. package/dist/quikdown.light.css +1 -1
  8. package/dist/quikdown.umd.js +5 -5
  9. package/dist/quikdown.umd.min.js +2 -2
  10. package/dist/quikdown.umd.min.js.map +1 -1
  11. package/dist/quikdown_ast.cjs +513 -0
  12. package/dist/quikdown_ast.d.ts +227 -0
  13. package/dist/quikdown_ast.esm.js +511 -0
  14. package/dist/quikdown_ast.esm.min.js +8 -0
  15. package/dist/quikdown_ast.esm.min.js.map +1 -0
  16. package/dist/quikdown_ast.umd.js +519 -0
  17. package/dist/quikdown_ast.umd.min.js +8 -0
  18. package/dist/quikdown_ast.umd.min.js.map +1 -0
  19. package/dist/quikdown_ast_html.cjs +1058 -0
  20. package/dist/quikdown_ast_html.d.ts +68 -0
  21. package/dist/quikdown_ast_html.esm.js +1056 -0
  22. package/dist/quikdown_ast_html.esm.min.js +8 -0
  23. package/dist/quikdown_ast_html.esm.min.js.map +1 -0
  24. package/dist/quikdown_ast_html.umd.js +1064 -0
  25. package/dist/quikdown_ast_html.umd.min.js +8 -0
  26. package/dist/quikdown_ast_html.umd.min.js.map +1 -0
  27. package/dist/quikdown_bd.cjs +12 -12
  28. package/dist/quikdown_bd.esm.js +12 -12
  29. package/dist/quikdown_bd.esm.min.js +2 -2
  30. package/dist/quikdown_bd.esm.min.js.map +1 -1
  31. package/dist/quikdown_bd.umd.js +12 -12
  32. package/dist/quikdown_bd.umd.min.js +2 -2
  33. package/dist/quikdown_bd.umd.min.js.map +1 -1
  34. package/dist/quikdown_edit.cjs +434 -58
  35. package/dist/quikdown_edit.d.ts +110 -132
  36. package/dist/quikdown_edit.esm.js +434 -58
  37. package/dist/quikdown_edit.esm.min.js +3 -3
  38. package/dist/quikdown_edit.esm.min.js.map +1 -1
  39. package/dist/quikdown_edit.umd.js +434 -58
  40. package/dist/quikdown_edit.umd.min.js +3 -3
  41. package/dist/quikdown_edit.umd.min.js.map +1 -1
  42. package/dist/quikdown_json.cjs +556 -0
  43. package/dist/quikdown_json.d.ts +48 -0
  44. package/dist/quikdown_json.esm.js +554 -0
  45. package/dist/quikdown_json.esm.min.js +8 -0
  46. package/dist/quikdown_json.esm.min.js.map +1 -0
  47. package/dist/quikdown_json.umd.js +562 -0
  48. package/dist/quikdown_json.umd.min.js +8 -0
  49. package/dist/quikdown_json.umd.min.js.map +1 -0
  50. package/dist/quikdown_yaml.cjs +717 -0
  51. package/dist/quikdown_yaml.d.ts +51 -0
  52. package/dist/quikdown_yaml.esm.js +715 -0
  53. package/dist/quikdown_yaml.esm.min.js +8 -0
  54. package/dist/quikdown_yaml.esm.min.js.map +1 -0
  55. package/dist/quikdown_yaml.umd.js +723 -0
  56. package/dist/quikdown_yaml.umd.min.js +8 -0
  57. package/dist/quikdown_yaml.umd.min.js.map +1 -0
  58. package/package.json +91 -38
@@ -0,0 +1,519 @@
1
+ /**
2
+ * quikdown_ast - AST Markdown Parser
3
+ * @version 1.2.2
4
+ * @license BSD-2-Clause
5
+ * @copyright DeftIO 2025
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
9
+ typeof define === 'function' && define.amd ? define(factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.quikdown_ast = factory());
11
+ })(this, (function () { 'use strict';
12
+
13
+ /**
14
+ * quikdown_ast - Forgiving markdown to AST parser
15
+ * Converts markdown to a structured Abstract Syntax Tree
16
+ * @param {string} markdown - The markdown source text
17
+ * @param {Object} options - Optional configuration object
18
+ * @returns {Object} - The AST object
19
+ */
20
+
21
+ // Version will be injected at build time
22
+ const quikdownVersion = '1.2.2';
23
+
24
+ // Safety limit to prevent infinite loops in list parsing
25
+ const MAX_LOOP_ITERATIONS = 1000;
26
+
27
+ /**
28
+ * Parse markdown into an AST
29
+ * @param {string} markdown - The markdown source text
30
+ * @param {Object} options - Optional configuration object
31
+ * @returns {Object} - The AST object
32
+ */
33
+ function quikdown_ast(markdown, options = {}) {
34
+ if (!markdown || typeof markdown !== 'string') {
35
+ return { type: 'document', children: [] };
36
+ }
37
+
38
+ // Normalize line endings (handle CRLF, CR, LF uniformly)
39
+ const text = markdown.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
40
+
41
+ const children = parseBlocks(text);
42
+
43
+ return {
44
+ type: 'document',
45
+ children
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Parse block-level elements
51
+ */
52
+ function parseBlocks(text, options) {
53
+ const blocks = [];
54
+ const lines = text.split('\n');
55
+ let i = 0;
56
+
57
+ while (i < lines.length) {
58
+ const line = lines[i];
59
+
60
+ // Empty line - skip
61
+ if (line.trim() === '') {
62
+ i++;
63
+ continue;
64
+ }
65
+
66
+ // Fenced code block (``` or ~~~)
67
+ const fenceMatch = line.match(/^(```|~~~)(.*)$/);
68
+ if (fenceMatch) {
69
+ const [, openFence, langPart] = fenceMatch;
70
+ const lang = langPart.trim();
71
+ const codeLines = [];
72
+ i++;
73
+
74
+ // Find closing fence (forgiving: accept mismatched fences or EOF)
75
+ while (i < lines.length) {
76
+ const closingMatch = lines[i].match(/^(```|~~~)\s*$/);
77
+ if (closingMatch) {
78
+ i++;
79
+ break;
80
+ }
81
+ codeLines.push(lines[i]);
82
+ i++;
83
+ }
84
+
85
+ blocks.push({
86
+ type: 'code_block',
87
+ lang: lang || null,
88
+ content: codeLines.join('\n'),
89
+ fence: openFence
90
+ });
91
+ continue;
92
+ }
93
+
94
+ // Horizontal rule
95
+ if (/^---+\s*$/.test(line) || /^\*\*\*+\s*$/.test(line) || /^___+\s*$/.test(line)) {
96
+ blocks.push({ type: 'hr' });
97
+ i++;
98
+ continue;
99
+ }
100
+
101
+ // Heading (forgiving: accept #heading without space)
102
+ const headingMatch = line.match(/^(#{1,6})\s*(.+?)\s*#*$/);
103
+ if (headingMatch) {
104
+ const [, hashes, content] = headingMatch;
105
+ blocks.push({
106
+ type: 'heading',
107
+ level: hashes.length,
108
+ children: parseInline(content)
109
+ });
110
+ i++;
111
+ continue;
112
+ }
113
+
114
+ // Table (look for separator line)
115
+ if (line.includes('|')) {
116
+ const tableResult = tryParseTable(lines, i);
117
+ if (tableResult) {
118
+ blocks.push(tableResult.node);
119
+ i = tableResult.nextIndex;
120
+ continue;
121
+ }
122
+ }
123
+
124
+ // Blockquote
125
+ if (line.match(/^>\s*/)) {
126
+ const quoteLines = [];
127
+ while (i < lines.length && lines[i].match(/^>\s*/)) {
128
+ quoteLines.push(lines[i].replace(/^>\s*/, ''));
129
+ i++;
130
+ }
131
+ blocks.push({
132
+ type: 'blockquote',
133
+ children: parseBlocks(quoteLines.join('\n'))
134
+ });
135
+ continue;
136
+ }
137
+
138
+ // List (ordered or unordered)
139
+ const listMatch = line.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);
140
+ if (listMatch) {
141
+ const listResult = parseList(lines, i);
142
+ blocks.push(listResult.node);
143
+ i = listResult.nextIndex;
144
+ continue;
145
+ }
146
+
147
+ // Paragraph - collect lines until empty line or block element
148
+ const paragraphLines = [];
149
+ while (i < lines.length) {
150
+ const pLine = lines[i];
151
+
152
+ // Stop on empty line
153
+ if (pLine.trim() === '') break;
154
+
155
+ // Stop on block elements
156
+ if (/^(```|~~~)/.test(pLine)) break;
157
+ if (/^#{1,6}\s/.test(pLine)) break;
158
+ if (/^---+\s*$/.test(pLine) || /^\*\*\*+\s*$/.test(pLine) || /^___+\s*$/.test(pLine)) break;
159
+ if (/^>\s*/.test(pLine)) break;
160
+ if (/^(\s*)([*\-+]|\d+\.)\s+/.test(pLine)) break;
161
+ if (pLine.includes('|') && i + 1 < lines.length && /^\|?[\s\-:|]+\|?$/.test(lines[i + 1])) break;
162
+
163
+ paragraphLines.push(pLine);
164
+ i++;
165
+ }
166
+
167
+ if (paragraphLines.length > 0) {
168
+ blocks.push({
169
+ type: 'paragraph',
170
+ children: parseInline(paragraphLines.join('\n'))
171
+ });
172
+ }
173
+ }
174
+
175
+ return blocks;
176
+ }
177
+
178
+ /**
179
+ * Try to parse a table starting at the given line
180
+ */
181
+ function tryParseTable(lines, startIndex, options) {
182
+ // Need at least 2 lines (header + separator)
183
+ if (startIndex + 1 >= lines.length) return null;
184
+
185
+ const headerLine = lines[startIndex];
186
+ const separatorLine = lines[startIndex + 1];
187
+
188
+ // Check if separator line is valid
189
+ if (!/^\|?[\s\-:|]+\|?$/.test(separatorLine) || !separatorLine.includes('-')) {
190
+ return null;
191
+ }
192
+
193
+ // Parse header
194
+ const headerCells = parseTableRow(headerLine);
195
+ if (headerCells.length === 0) return null;
196
+
197
+ // Parse alignments from separator
198
+ const separatorCells = parseTableRow(separatorLine);
199
+ const alignments = separatorCells.map(cell => {
200
+ const trimmed = cell.trim();
201
+ if (trimmed.startsWith(':') && trimmed.endsWith(':')) return 'center';
202
+ if (trimmed.endsWith(':')) return 'right';
203
+ return 'left';
204
+ });
205
+
206
+ // Parse headers with inline formatting
207
+ const headers = headerCells.map(cell => parseInline(cell.trim()));
208
+
209
+ // Parse body rows
210
+ const rows = [];
211
+ let i = startIndex + 2;
212
+ while (i < lines.length) {
213
+ const rowLine = lines[i];
214
+ if (!rowLine.includes('|') || rowLine.trim() === '') break;
215
+
216
+ const cells = parseTableRow(rowLine);
217
+ rows.push(cells.map(cell => parseInline(cell.trim())));
218
+ i++;
219
+ }
220
+
221
+ return {
222
+ node: {
223
+ type: 'table',
224
+ headers,
225
+ rows,
226
+ alignments
227
+ },
228
+ nextIndex: i
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Parse a table row into cells
234
+ */
235
+ function parseTableRow(line) {
236
+ // Handle pipes at start/end or not
237
+ let trimmed = line.trim();
238
+ if (trimmed.startsWith('|')) trimmed = trimmed.slice(1);
239
+ if (trimmed.endsWith('|')) trimmed = trimmed.slice(0, -1);
240
+ return trimmed.split('|');
241
+ }
242
+
243
+ /**
244
+ * Parse a list starting at the given line
245
+ */
246
+ function parseList(lines, startIndex, options) {
247
+ const items = [];
248
+ let i = startIndex;
249
+ let loopCount = 0;
250
+
251
+ // Determine initial list type
252
+ const firstMatch = lines[i].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);
253
+ const isOrdered = /^\d+\./.test(firstMatch[2]);
254
+ const baseIndent = firstMatch[1].length;
255
+
256
+ while (i < lines.length && loopCount < MAX_LOOP_ITERATIONS) {
257
+ loopCount++;
258
+ const line = lines[i];
259
+ const match = line.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);
260
+
261
+ if (!match) break;
262
+
263
+ const [, indent, marker, content] = match;
264
+ const indentLevel = indent.length;
265
+
266
+ // If less indented than base, stop
267
+ if (indentLevel < baseIndent) break;
268
+
269
+ // If same indentation but different list type, stop
270
+ const itemIsOrdered = /^\d+\./.test(marker);
271
+ if (indentLevel === baseIndent && itemIsOrdered !== isOrdered) break;
272
+
273
+ // If more indented, it's a nested list - handle by collecting sub-lines
274
+ if (indentLevel > baseIndent) {
275
+ // This is a nested list item, collect and parse as sublist
276
+ const subLines = [];
277
+ let subLoopCount = 0;
278
+ while (i < lines.length && subLoopCount < MAX_LOOP_ITERATIONS) {
279
+ subLoopCount++;
280
+ const subLine = lines[i];
281
+ const subMatch = subLine.match(/^(\s*)([*\-+]|\d+\.)\s+/);
282
+ if (!subMatch) break;
283
+ if (subMatch[1].length < baseIndent) break;
284
+ if (subMatch[1].length === baseIndent) break;
285
+ subLines.push(subLine);
286
+ i++;
287
+ }
288
+
289
+ if (subLines.length > 0 && items.length > 0) {
290
+ // Add nested list to last item
291
+ const nestedResult = parseList(subLines, 0);
292
+ const lastItem = items[items.length - 1];
293
+ if (!lastItem.children) {
294
+ lastItem.children = [];
295
+ } else if (!Array.isArray(lastItem.children)) {
296
+ lastItem.children = [{ type: 'paragraph', children: lastItem.children }];
297
+ }
298
+ lastItem.children.push(nestedResult.node);
299
+ }
300
+ continue;
301
+ }
302
+
303
+ // Parse list item
304
+ const itemNode = {
305
+ type: 'list_item',
306
+ checked: null,
307
+ children: null
308
+ };
309
+
310
+ // Check for task list syntax
311
+ const taskMatch = content.match(/^\[([x ])\]\s*(.*)$/i);
312
+ if (taskMatch && !isOrdered) {
313
+ itemNode.checked = taskMatch[1].toLowerCase() === 'x';
314
+ itemNode.children = parseInline(taskMatch[2]);
315
+ } else {
316
+ itemNode.children = parseInline(content);
317
+ }
318
+
319
+ items.push(itemNode);
320
+ i++;
321
+ }
322
+
323
+ return {
324
+ node: {
325
+ type: 'list',
326
+ ordered: isOrdered,
327
+ items
328
+ },
329
+ nextIndex: i
330
+ };
331
+ }
332
+
333
+ /**
334
+ * Parse inline elements
335
+ */
336
+ function parseInline(text, options) {
337
+ if (!text) return [];
338
+
339
+ const nodes = [];
340
+ let remaining = text;
341
+
342
+ while (remaining.length > 0) {
343
+ let matched = false;
344
+
345
+ // Line break (1+ trailing spaces or explicit \n after processing)
346
+ // Handle inline line breaks (two spaces at end of line or backslash before newline)
347
+ const brMatch = remaining.match(/^(.+?)(?: {2}|\\\n|\n)/);
348
+ if (brMatch && remaining.includes('\n')) {
349
+ const beforeBr = remaining.indexOf('\n');
350
+ const beforeText = remaining.slice(0, beforeBr);
351
+ const afterText = remaining.slice(beforeBr + 1);
352
+
353
+ // Check if line break is significant (2+ trailing spaces or backslash)
354
+ if (beforeText.endsWith(' ') || beforeText.endsWith('\\')) {
355
+ const cleanText = beforeText.replace(/\\$/, '').replace(/ +$/, '');
356
+ if (cleanText) {
357
+ nodes.push(...parseInlineContent(cleanText));
358
+ }
359
+ nodes.push({ type: 'br' });
360
+ remaining = afterText;
361
+ matched = true;
362
+ continue;
363
+ }
364
+ }
365
+
366
+ // Images: ![alt](url)
367
+ const imgMatch = remaining.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);
368
+ if (imgMatch) {
369
+ nodes.push({
370
+ type: 'image',
371
+ alt: imgMatch[1],
372
+ url: imgMatch[2].trim() // Forgiving: trim whitespace in URL
373
+ });
374
+ remaining = remaining.slice(imgMatch[0].length);
375
+ matched = true;
376
+ continue;
377
+ }
378
+
379
+ // Links: [text](url)
380
+ const linkMatch = remaining.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);
381
+ if (linkMatch) {
382
+ nodes.push({
383
+ type: 'link',
384
+ url: linkMatch[2].trim(), // Forgiving: trim whitespace in URL
385
+ children: parseInlineContent(linkMatch[1])
386
+ });
387
+ remaining = remaining.slice(linkMatch[0].length);
388
+ matched = true;
389
+ continue;
390
+ }
391
+
392
+ // Inline code: `code`
393
+ const codeMatch = remaining.match(/^`([^`]+)`/);
394
+ if (codeMatch) {
395
+ nodes.push({
396
+ type: 'code',
397
+ value: codeMatch[1]
398
+ });
399
+ remaining = remaining.slice(codeMatch[0].length);
400
+ matched = true;
401
+ continue;
402
+ }
403
+
404
+ // Bold: **text** or __text__
405
+ const boldMatch = remaining.match(/^(\*\*|__)(.+?)\1/);
406
+ if (boldMatch) {
407
+ nodes.push({
408
+ type: 'strong',
409
+ children: parseInlineContent(boldMatch[2])
410
+ });
411
+ remaining = remaining.slice(boldMatch[0].length);
412
+ matched = true;
413
+ continue;
414
+ }
415
+
416
+ // Strikethrough: ~~text~~
417
+ const strikeMatch = remaining.match(/^~~(.+?)~~/);
418
+ if (strikeMatch) {
419
+ nodes.push({
420
+ type: 'del',
421
+ children: parseInlineContent(strikeMatch[1])
422
+ });
423
+ remaining = remaining.slice(strikeMatch[0].length);
424
+ matched = true;
425
+ continue;
426
+ }
427
+
428
+ // Italic: *text* or _text_ (not at word boundary for underscores)
429
+ const emMatch = remaining.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);
430
+ if (emMatch) {
431
+ nodes.push({
432
+ type: 'em',
433
+ children: parseInlineContent(emMatch[2])
434
+ });
435
+ remaining = remaining.slice(emMatch[0].length);
436
+ matched = true;
437
+ continue;
438
+ }
439
+
440
+ // Autolinks: URLs starting with http:// or https://
441
+ const urlMatch = remaining.match(/^(https?:\/\/[^\s<>[\]]+)/);
442
+ if (urlMatch) {
443
+ nodes.push({
444
+ type: 'link',
445
+ url: urlMatch[1],
446
+ children: [{ type: 'text', value: urlMatch[1] }]
447
+ });
448
+ remaining = remaining.slice(urlMatch[0].length);
449
+ matched = true;
450
+ continue;
451
+ }
452
+
453
+ // Plain text - consume until next potential inline element or end
454
+ if (!matched) {
455
+ // Find next potential inline marker
456
+ const nextMarker = remaining.search(/[`*_~![\\n]|https?:\/\//);
457
+ if (nextMarker === -1) {
458
+ // No more markers, consume rest as text
459
+ nodes.push({ type: 'text', value: remaining });
460
+ break;
461
+ } else if (nextMarker === 0) {
462
+ // Current char is a marker but didn't match - consume it as text
463
+ nodes.push({ type: 'text', value: remaining[0] });
464
+ remaining = remaining.slice(1);
465
+ } else {
466
+ // Consume text up to next marker
467
+ nodes.push({ type: 'text', value: remaining.slice(0, nextMarker) });
468
+ remaining = remaining.slice(nextMarker);
469
+ }
470
+ }
471
+ }
472
+
473
+ // Merge adjacent text nodes
474
+ return mergeTextNodes(nodes);
475
+ }
476
+
477
+ /**
478
+ * Parse inline content (recursive helper for nested inline elements)
479
+ */
480
+ function parseInlineContent(text, options) {
481
+ // For simple nested content, use parseInline
482
+ // But handle newlines as spaces for inline content
483
+ const normalized = text.replace(/\n/g, ' ');
484
+ return parseInline(normalized);
485
+ }
486
+
487
+ /**
488
+ * Merge adjacent text nodes
489
+ */
490
+ function mergeTextNodes(nodes) {
491
+ const merged = [];
492
+ for (const node of nodes) {
493
+ if (node.type === 'text' && merged.length > 0 && merged[merged.length - 1].type === 'text') {
494
+ merged[merged.length - 1].value += node.value;
495
+ } else {
496
+ merged.push(node);
497
+ }
498
+ }
499
+ return merged;
500
+ }
501
+
502
+ // Attach version
503
+ quikdown_ast.version = quikdownVersion;
504
+
505
+ // Export for both CommonJS and ES6
506
+ /* istanbul ignore next */
507
+ if (typeof module !== 'undefined' && module.exports) {
508
+ module.exports = quikdown_ast;
509
+ }
510
+
511
+ // For browser global
512
+ /* istanbul ignore next */
513
+ if (typeof window !== 'undefined') {
514
+ window.quikdown_ast = quikdown_ast;
515
+ }
516
+
517
+ return quikdown_ast;
518
+
519
+ }));
@@ -0,0 +1,8 @@
1
+ /**
2
+ * quikdown_ast - AST Markdown Parser
3
+ * @version 1.2.2
4
+ * @license BSD-2-Clause
5
+ * @copyright DeftIO 2025
6
+ */
7
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).quikdown_ast=t()}(this,function(){"use strict";function e(e,n={}){if(!e||"string"!=typeof e)return{type:"document",children:[]};return{type:"document",children:t(e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"))}}function t(e,s){const l=[],r=e.split("\n");let o=0;for(;o<r.length;){const e=r[o];if(""===e.trim()){o++;continue}const s=e.match(/^(```|~~~)(.*)$/);if(s){const[,e,t]=s,n=t.trim(),i=[];for(o++;o<r.length;){if(r[o].match(/^(```|~~~)\s*$/)){o++;break}i.push(r[o]),o++}l.push({type:"code_block",lang:n||null,content:i.join("\n"),fence:e});continue}if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e)){l.push({type:"hr"}),o++;continue}const h=e.match(/^(#{1,6})\s*(.+?)\s*#*$/);if(h){const[,e,t]=h;l.push({type:"heading",level:e.length,children:c(t)}),o++;continue}if(e.includes("|")){const e=n(r,o);if(e){l.push(e.node),o=e.nextIndex;continue}}if(e.match(/^>\s*/)){const e=[];for(;o<r.length&&r[o].match(/^>\s*/);)e.push(r[o].replace(/^>\s*/,"")),o++;l.push({type:"blockquote",children:t(e.join("\n"))});continue}if(e.match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/)){const e=i(r,o);l.push(e.node),o=e.nextIndex;continue}const u=[];for(;o<r.length;){const e=r[o];if(""===e.trim())break;if(/^(```|~~~)/.test(e))break;if(/^#{1,6}\s/.test(e))break;if(/^---+\s*$/.test(e)||/^\*\*\*+\s*$/.test(e)||/^___+\s*$/.test(e))break;if(/^>\s*/.test(e))break;if(/^(\s*)([*\-+]|\d+\.)\s+/.test(e))break;if(e.includes("|")&&o+1<r.length&&/^\|?[\s\-:|]+\|?$/.test(r[o+1]))break;u.push(e),o++}u.length>0&&l.push({type:"paragraph",children:c(u.join("\n"))})}return l}function n(e,t,n){if(t+1>=e.length)return null;const i=e[t],l=e[t+1];if(!/^\|?[\s\-:|]+\|?$/.test(l)||!l.includes("-"))return null;const r=s(i);if(0===r.length)return null;const o=s(l).map(e=>{const t=e.trim();return t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left"}),h=r.map(e=>c(e.trim())),u=[];let f=t+2;for(;f<e.length;){const t=e[f];if(!t.includes("|")||""===t.trim())break;const n=s(t);u.push(n.map(e=>c(e.trim()))),f++}return{node:{type:"table",headers:h,rows:u,alignments:o},nextIndex:f}}function s(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function i(e,t,n){const s=[];let l=t,r=0;const o=e[l].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/),h=/^\d+\./.test(o[2]),u=o[1].length;for(;l<e.length&&r<1e3;){r++;const t=e[l].match(/^(\s*)([*\-+]|\d+\.)\s+(.*)$/);if(!t)break;const[,n,o,f]=t,p=n.length;if(p<u)break;const d=/^\d+\./.test(o);if(p===u&&d!==h)break;if(p>u){const t=[];let n=0;for(;l<e.length&&n<1e3;){n++;const s=e[l],i=s.match(/^(\s*)([*\-+]|\d+\.)\s+/);if(!i)break;if(i[1].length<u)break;if(i[1].length===u)break;t.push(s),l++}if(t.length>0&&s.length>0){const e=i(t,0),n=s[s.length-1];n.children?Array.isArray(n.children)||(n.children=[{type:"paragraph",children:n.children}]):n.children=[],n.children.push(e.node)}continue}const a={type:"list_item",checked:null,children:null},g=f.match(/^\[([x ])\]\s*(.*)$/i);g&&!h?(a.checked="x"===g[1].toLowerCase(),a.children=c(g[2])):a.children=c(f),s.push(a),l++}return{node:{type:"list",ordered:h,items:s},nextIndex:l}}function c(e,t){if(!e)return[];const n=[];let s=e;for(;s.length>0;){let e=!1;if(s.match(/^(.+?)(?: {2}|\\\n|\n)/)&&s.includes("\n")){const t=s.indexOf("\n"),i=s.slice(0,t),c=s.slice(t+1);if(i.endsWith(" ")||i.endsWith("\\")){const t=i.replace(/\\$/,"").replace(/ +$/,"");t&&n.push(...l(t)),n.push({type:"br"}),s=c,e=!0;continue}}const t=s.match(/^!\[([^\]]*)\]\(\s*([^)\s]+)\s*\)/);if(t){n.push({type:"image",alt:t[1],url:t[2].trim()}),s=s.slice(t[0].length),e=!0;continue}const i=s.match(/^\[([^\]]+)\]\(\s*([^)\s]+)\s*\)/);if(i){n.push({type:"link",url:i[2].trim(),children:l(i[1])}),s=s.slice(i[0].length),e=!0;continue}const c=s.match(/^`([^`]+)`/);if(c){n.push({type:"code",value:c[1]}),s=s.slice(c[0].length),e=!0;continue}const r=s.match(/^(\*\*|__)(.+?)\1/);if(r){n.push({type:"strong",children:l(r[2])}),s=s.slice(r[0].length),e=!0;continue}const o=s.match(/^~~(.+?)~~/);if(o){n.push({type:"del",children:l(o[1])}),s=s.slice(o[0].length),e=!0;continue}const h=s.match(/^(\*|_)(?!\1)(.+?)(?<!\1)\1(?!\1)/);if(h){n.push({type:"em",children:l(h[2])}),s=s.slice(h[0].length),e=!0;continue}const u=s.match(/^(https?:\/\/[^\s<>[\]]+)/);if(u)n.push({type:"link",url:u[1],children:[{type:"text",value:u[1]}]}),s=s.slice(u[0].length),e=!0;else if(!e){const e=s.search(/[`*_~![\\n]|https?:\/\//);if(-1===e){n.push({type:"text",value:s});break}0===e?(n.push({type:"text",value:s[0]}),s=s.slice(1)):(n.push({type:"text",value:s.slice(0,e)}),s=s.slice(e))}}return function(e){const t=[];for(const n of e)"text"===n.type&&t.length>0&&"text"===t[t.length-1].type?t[t.length-1].value+=n.value:t.push(n);return t}(n)}function l(e,t){return c(e.replace(/\n/g," "))}return e.version="1.2.2","undefined"!=typeof module&&module.exports&&(module.exports=e),"undefined"!=typeof window&&(window.quikdown_ast=e),e});
8
+ //# sourceMappingURL=quikdown_ast.umd.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quikdown_ast.umd.min.js","sources":["../src/quikdown_ast.js"],"sourcesContent":["/**\n * quikdown_ast - Forgiving markdown to AST parser\n * Converts markdown to a structured Abstract Syntax Tree\n * @param {string} markdown - The markdown source text\n * @param {Object} options - Optional configuration object\n * @returns {Object} - The AST object\n */\n\n// Version will be injected at build time\nconst quikdownVersion = '__QUIKDOWN_VERSION__';\n\n// Safety limit to prevent infinite loops in list parsing\nconst MAX_LOOP_ITERATIONS = 1000;\n\n/**\n * Parse markdown into an AST\n * @param {string} markdown - The markdown source text\n * @param {Object} options - Optional configuration object\n * @returns {Object} - The AST object\n */\nfunction quikdown_ast(markdown, options = {}) {\n if (!markdown || typeof markdown !== 'string') {\n return { type: 'document', children: [] };\n }\n\n // Normalize line endings (handle CRLF, CR, LF uniformly)\n const text = markdown.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n');\n\n const children = parseBlocks(text, options);\n\n return {\n type: 'document',\n children\n };\n}\n\n/**\n * Parse block-level elements\n */\nfunction parseBlocks(text, options) {\n const blocks = [];\n const lines = text.split('\\n');\n let i = 0;\n\n while (i < lines.length) {\n const line = lines[i];\n\n // Empty line - skip\n if (line.trim() === '') {\n i++;\n continue;\n }\n\n // Fenced code block (``` or ~~~)\n const fenceMatch = line.match(/^(```|~~~)(.*)$/);\n if (fenceMatch) {\n const [, openFence, langPart] = fenceMatch;\n const lang = langPart.trim();\n const codeLines = [];\n i++;\n\n // Find closing fence (forgiving: accept mismatched fences or EOF)\n while (i < lines.length) {\n const closingMatch = lines[i].match(/^(```|~~~)\\s*$/);\n if (closingMatch) {\n i++;\n break;\n }\n codeLines.push(lines[i]);\n i++;\n }\n\n blocks.push({\n type: 'code_block',\n lang: lang || null,\n content: codeLines.join('\\n'),\n fence: openFence\n });\n continue;\n }\n\n // Horizontal rule\n if (/^---+\\s*$/.test(line) || /^\\*\\*\\*+\\s*$/.test(line) || /^___+\\s*$/.test(line)) {\n blocks.push({ type: 'hr' });\n i++;\n continue;\n }\n\n // Heading (forgiving: accept #heading without space)\n const headingMatch = line.match(/^(#{1,6})\\s*(.+?)\\s*#*$/);\n if (headingMatch) {\n const [, hashes, content] = headingMatch;\n blocks.push({\n type: 'heading',\n level: hashes.length,\n children: parseInline(content, options)\n });\n i++;\n continue;\n }\n\n // Table (look for separator line)\n if (line.includes('|')) {\n const tableResult = tryParseTable(lines, i, options);\n if (tableResult) {\n blocks.push(tableResult.node);\n i = tableResult.nextIndex;\n continue;\n }\n }\n\n // Blockquote\n if (line.match(/^>\\s*/)) {\n const quoteLines = [];\n while (i < lines.length && lines[i].match(/^>\\s*/)) {\n quoteLines.push(lines[i].replace(/^>\\s*/, ''));\n i++;\n }\n blocks.push({\n type: 'blockquote',\n children: parseBlocks(quoteLines.join('\\n'), options)\n });\n continue;\n }\n\n // List (ordered or unordered)\n const listMatch = line.match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+(.*)$/);\n if (listMatch) {\n const listResult = parseList(lines, i, options);\n blocks.push(listResult.node);\n i = listResult.nextIndex;\n continue;\n }\n\n // Paragraph - collect lines until empty line or block element\n const paragraphLines = [];\n while (i < lines.length) {\n const pLine = lines[i];\n\n // Stop on empty line\n if (pLine.trim() === '') break;\n\n // Stop on block elements\n if (/^(```|~~~)/.test(pLine)) break;\n if (/^#{1,6}\\s/.test(pLine)) break;\n if (/^---+\\s*$/.test(pLine) || /^\\*\\*\\*+\\s*$/.test(pLine) || /^___+\\s*$/.test(pLine)) break;\n if (/^>\\s*/.test(pLine)) break;\n if (/^(\\s*)([*\\-+]|\\d+\\.)\\s+/.test(pLine)) break;\n if (pLine.includes('|') && i + 1 < lines.length && /^\\|?[\\s\\-:|]+\\|?$/.test(lines[i + 1])) break;\n\n paragraphLines.push(pLine);\n i++;\n }\n\n if (paragraphLines.length > 0) {\n blocks.push({\n type: 'paragraph',\n children: parseInline(paragraphLines.join('\\n'), options)\n });\n }\n }\n\n return blocks;\n}\n\n/**\n * Try to parse a table starting at the given line\n */\nfunction tryParseTable(lines, startIndex, options) {\n // Need at least 2 lines (header + separator)\n if (startIndex + 1 >= lines.length) return null;\n\n const headerLine = lines[startIndex];\n const separatorLine = lines[startIndex + 1];\n\n // Check if separator line is valid\n if (!/^\\|?[\\s\\-:|]+\\|?$/.test(separatorLine) || !separatorLine.includes('-')) {\n return null;\n }\n\n // Parse header\n const headerCells = parseTableRow(headerLine);\n if (headerCells.length === 0) return null;\n\n // Parse alignments from separator\n const separatorCells = parseTableRow(separatorLine);\n const alignments = separatorCells.map(cell => {\n const trimmed = cell.trim();\n if (trimmed.startsWith(':') && trimmed.endsWith(':')) return 'center';\n if (trimmed.endsWith(':')) return 'right';\n return 'left';\n });\n\n // Parse headers with inline formatting\n const headers = headerCells.map(cell => parseInline(cell.trim(), options));\n\n // Parse body rows\n const rows = [];\n let i = startIndex + 2;\n while (i < lines.length) {\n const rowLine = lines[i];\n if (!rowLine.includes('|') || rowLine.trim() === '') break;\n\n const cells = parseTableRow(rowLine);\n rows.push(cells.map(cell => parseInline(cell.trim(), options)));\n i++;\n }\n\n return {\n node: {\n type: 'table',\n headers,\n rows,\n alignments\n },\n nextIndex: i\n };\n}\n\n/**\n * Parse a table row into cells\n */\nfunction parseTableRow(line) {\n // Handle pipes at start/end or not\n let trimmed = line.trim();\n if (trimmed.startsWith('|')) trimmed = trimmed.slice(1);\n if (trimmed.endsWith('|')) trimmed = trimmed.slice(0, -1);\n return trimmed.split('|');\n}\n\n/**\n * Parse a list starting at the given line\n */\nfunction parseList(lines, startIndex, options) {\n const items = [];\n let i = startIndex;\n let loopCount = 0;\n\n // Determine initial list type\n const firstMatch = lines[i].match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+(.*)$/);\n const isOrdered = /^\\d+\\./.test(firstMatch[2]);\n const baseIndent = firstMatch[1].length;\n\n while (i < lines.length && loopCount < MAX_LOOP_ITERATIONS) {\n loopCount++;\n const line = lines[i];\n const match = line.match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+(.*)$/);\n\n if (!match) break;\n\n const [, indent, marker, content] = match;\n const indentLevel = indent.length;\n\n // If less indented than base, stop\n if (indentLevel < baseIndent) break;\n\n // If same indentation but different list type, stop\n const itemIsOrdered = /^\\d+\\./.test(marker);\n if (indentLevel === baseIndent && itemIsOrdered !== isOrdered) break;\n\n // If more indented, it's a nested list - handle by collecting sub-lines\n if (indentLevel > baseIndent) {\n // This is a nested list item, collect and parse as sublist\n const subLines = [];\n let subLoopCount = 0;\n while (i < lines.length && subLoopCount < MAX_LOOP_ITERATIONS) {\n subLoopCount++;\n const subLine = lines[i];\n const subMatch = subLine.match(/^(\\s*)([*\\-+]|\\d+\\.)\\s+/);\n if (!subMatch) break;\n if (subMatch[1].length < baseIndent) break;\n if (subMatch[1].length === baseIndent) break;\n subLines.push(subLine);\n i++;\n }\n\n if (subLines.length > 0 && items.length > 0) {\n // Add nested list to last item\n const nestedResult = parseList(subLines, 0, options);\n const lastItem = items[items.length - 1];\n if (!lastItem.children) {\n lastItem.children = [];\n } else if (!Array.isArray(lastItem.children)) {\n lastItem.children = [{ type: 'paragraph', children: lastItem.children }];\n }\n lastItem.children.push(nestedResult.node);\n }\n continue;\n }\n\n // Parse list item\n const itemNode = {\n type: 'list_item',\n checked: null,\n children: null\n };\n\n // Check for task list syntax\n const taskMatch = content.match(/^\\[([x ])\\]\\s*(.*)$/i);\n if (taskMatch && !isOrdered) {\n itemNode.checked = taskMatch[1].toLowerCase() === 'x';\n itemNode.children = parseInline(taskMatch[2], options);\n } else {\n itemNode.children = parseInline(content, options);\n }\n\n items.push(itemNode);\n i++;\n }\n\n return {\n node: {\n type: 'list',\n ordered: isOrdered,\n items\n },\n nextIndex: i\n };\n}\n\n/**\n * Parse inline elements\n */\nfunction parseInline(text, options) {\n if (!text) return [];\n\n const nodes = [];\n let remaining = text;\n\n while (remaining.length > 0) {\n let matched = false;\n\n // Line break (1+ trailing spaces or explicit \\n after processing)\n // Handle inline line breaks (two spaces at end of line or backslash before newline)\n const brMatch = remaining.match(/^(.+?)(?: {2}|\\\\\\n|\\n)/);\n if (brMatch && remaining.includes('\\n')) {\n const beforeBr = remaining.indexOf('\\n');\n const beforeText = remaining.slice(0, beforeBr);\n const afterText = remaining.slice(beforeBr + 1);\n\n // Check if line break is significant (2+ trailing spaces or backslash)\n if (beforeText.endsWith(' ') || beforeText.endsWith('\\\\')) {\n const cleanText = beforeText.replace(/\\\\$/, '').replace(/ +$/, '');\n if (cleanText) {\n nodes.push(...parseInlineContent(cleanText, options));\n }\n nodes.push({ type: 'br' });\n remaining = afterText;\n matched = true;\n continue;\n }\n }\n\n // Images: ![alt](url)\n const imgMatch = remaining.match(/^!\\[([^\\]]*)\\]\\(\\s*([^)\\s]+)\\s*\\)/);\n if (imgMatch) {\n nodes.push({\n type: 'image',\n alt: imgMatch[1],\n url: imgMatch[2].trim() // Forgiving: trim whitespace in URL\n });\n remaining = remaining.slice(imgMatch[0].length);\n matched = true;\n continue;\n }\n\n // Links: [text](url)\n const linkMatch = remaining.match(/^\\[([^\\]]+)\\]\\(\\s*([^)\\s]+)\\s*\\)/);\n if (linkMatch) {\n nodes.push({\n type: 'link',\n url: linkMatch[2].trim(), // Forgiving: trim whitespace in URL\n children: parseInlineContent(linkMatch[1], options)\n });\n remaining = remaining.slice(linkMatch[0].length);\n matched = true;\n continue;\n }\n\n // Inline code: `code`\n const codeMatch = remaining.match(/^`([^`]+)`/);\n if (codeMatch) {\n nodes.push({\n type: 'code',\n value: codeMatch[1]\n });\n remaining = remaining.slice(codeMatch[0].length);\n matched = true;\n continue;\n }\n\n // Bold: **text** or __text__\n const boldMatch = remaining.match(/^(\\*\\*|__)(.+?)\\1/);\n if (boldMatch) {\n nodes.push({\n type: 'strong',\n children: parseInlineContent(boldMatch[2], options)\n });\n remaining = remaining.slice(boldMatch[0].length);\n matched = true;\n continue;\n }\n\n // Strikethrough: ~~text~~\n const strikeMatch = remaining.match(/^~~(.+?)~~/);\n if (strikeMatch) {\n nodes.push({\n type: 'del',\n children: parseInlineContent(strikeMatch[1], options)\n });\n remaining = remaining.slice(strikeMatch[0].length);\n matched = true;\n continue;\n }\n\n // Italic: *text* or _text_ (not at word boundary for underscores)\n const emMatch = remaining.match(/^(\\*|_)(?!\\1)(.+?)(?<!\\1)\\1(?!\\1)/);\n if (emMatch) {\n nodes.push({\n type: 'em',\n children: parseInlineContent(emMatch[2], options)\n });\n remaining = remaining.slice(emMatch[0].length);\n matched = true;\n continue;\n }\n\n // Autolinks: URLs starting with http:// or https://\n const urlMatch = remaining.match(/^(https?:\\/\\/[^\\s<>[\\]]+)/);\n if (urlMatch) {\n nodes.push({\n type: 'link',\n url: urlMatch[1],\n children: [{ type: 'text', value: urlMatch[1] }]\n });\n remaining = remaining.slice(urlMatch[0].length);\n matched = true;\n continue;\n }\n\n // Plain text - consume until next potential inline element or end\n if (!matched) {\n // Find next potential inline marker\n const nextMarker = remaining.search(/[`*_~![\\\\n]|https?:\\/\\//);\n if (nextMarker === -1) {\n // No more markers, consume rest as text\n nodes.push({ type: 'text', value: remaining });\n break;\n } else if (nextMarker === 0) {\n // Current char is a marker but didn't match - consume it as text\n nodes.push({ type: 'text', value: remaining[0] });\n remaining = remaining.slice(1);\n } else {\n // Consume text up to next marker\n nodes.push({ type: 'text', value: remaining.slice(0, nextMarker) });\n remaining = remaining.slice(nextMarker);\n }\n }\n }\n\n // Merge adjacent text nodes\n return mergeTextNodes(nodes);\n}\n\n/**\n * Parse inline content (recursive helper for nested inline elements)\n */\nfunction parseInlineContent(text, options) {\n // For simple nested content, use parseInline\n // But handle newlines as spaces for inline content\n const normalized = text.replace(/\\n/g, ' ');\n return parseInline(normalized, options);\n}\n\n/**\n * Merge adjacent text nodes\n */\nfunction mergeTextNodes(nodes) {\n const merged = [];\n for (const node of nodes) {\n if (node.type === 'text' && merged.length > 0 && merged[merged.length - 1].type === 'text') {\n merged[merged.length - 1].value += node.value;\n } else {\n merged.push(node);\n }\n }\n return merged;\n}\n\n// Attach version\nquikdown_ast.version = quikdownVersion;\n\n// Export for both CommonJS and ES6\n/* istanbul ignore next */\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = quikdown_ast;\n}\n\n// For browser global\n/* istanbul ignore next */\nif (typeof window !== 'undefined') {\n window.quikdown_ast = quikdown_ast;\n}\n\nexport default quikdown_ast;\n"],"names":["quikdown_ast","markdown","options","type","children","parseBlocks","replace","text","blocks","lines","split","i","length","line","trim","fenceMatch","match","openFence","langPart","lang","codeLines","push","content","join","fence","test","headingMatch","hashes","level","parseInline","includes","tableResult","tryParseTable","node","nextIndex","quoteLines","listResult","parseList","paragraphLines","pLine","startIndex","headerLine","separatorLine","headerCells","parseTableRow","alignments","map","cell","trimmed","startsWith","endsWith","headers","rows","rowLine","cells","slice","items","loopCount","firstMatch","isOrdered","baseIndent","indent","marker","indentLevel","itemIsOrdered","subLines","subLoopCount","subLine","subMatch","nestedResult","lastItem","Array","isArray","itemNode","checked","taskMatch","toLowerCase","ordered","nodes","remaining","matched","beforeBr","indexOf","beforeText","afterText","cleanText","parseInlineContent","imgMatch","alt","url","linkMatch","codeMatch","value","boldMatch","strikeMatch","emMatch","urlMatch","nextMarker","search","merged","mergeTextNodes","version","module","exports","window"],"mappings":";;;;;;4OAoBA,SAASA,EAAaC,EAAUC,EAAU,IACtC,IAAKD,GAAgC,iBAAbA,EACpB,MAAO,CAAEE,KAAM,WAAYC,SAAU,IAQzC,MAAO,CACHD,KAAM,WACNC,SAJaC,EAFJJ,EAASK,QAAQ,QAAS,MAAMA,QAAQ,MAAO,OAQhE,CAKA,SA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