svelte-streamdown 2.4.5 → 2.5.1

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 (46) hide show
  1. package/README.md +98 -4
  2. package/dist/Block.svelte +4 -4
  3. package/dist/Block.svelte.d.ts +0 -1
  4. package/dist/Elements/Alert.svelte +4 -1
  5. package/dist/Elements/Alert.svelte.d.ts +1 -0
  6. package/dist/Elements/Citation.svelte +260 -0
  7. package/dist/Elements/Citation.svelte.d.ts +7 -0
  8. package/dist/Elements/Code.svelte +13 -41
  9. package/dist/Elements/Code.svelte.d.ts +1 -0
  10. package/dist/Elements/Element.svelte +65 -33
  11. package/dist/Elements/FootnoteRef.svelte +41 -89
  12. package/dist/Elements/Image.svelte +5 -1
  13. package/dist/Elements/Image.svelte.d.ts +1 -0
  14. package/dist/Elements/Link.svelte +5 -1
  15. package/dist/Elements/Link.svelte.d.ts +1 -0
  16. package/dist/Elements/Math.svelte +10 -2
  17. package/dist/Elements/Math.svelte.d.ts +1 -0
  18. package/dist/Elements/Mermaid.svelte +87 -175
  19. package/dist/Elements/Mermaid.svelte.d.ts +1 -0
  20. package/dist/Elements/TableDownload.svelte +216 -0
  21. package/dist/Elements/TableDownload.svelte.d.ts +8 -0
  22. package/dist/Elements/icons.d.ts +9 -0
  23. package/dist/Elements/icons.js +175 -0
  24. package/dist/Elements/popover.svelte.d.ts +8 -0
  25. package/dist/Elements/popover.svelte.js +40 -0
  26. package/dist/Elements/stepperState.svelte.d.ts +35 -0
  27. package/dist/Elements/stepperState.svelte.js +98 -0
  28. package/dist/Streamdown.svelte +13 -4
  29. package/dist/Streamdown.svelte.d.ts +23 -2
  30. package/dist/context.svelte.d.ts +28 -11
  31. package/dist/context.svelte.js +14 -6
  32. package/dist/marked/index.d.ts +4 -2
  33. package/dist/marked/index.js +4 -2
  34. package/dist/marked/marked-align.d.ts +10 -0
  35. package/dist/marked/marked-align.js +36 -0
  36. package/dist/marked/marked-citations.d.ts +8 -0
  37. package/dist/marked/marked-citations.js +49 -0
  38. package/dist/marked/marked-table.js +36 -13
  39. package/dist/theme.d.ts +66 -21
  40. package/dist/theme.js +47 -17
  41. package/dist/utils/get.d.ts +1 -0
  42. package/dist/utils/get.js +25 -0
  43. package/dist/utils/panzoom.svelte.d.ts +1 -2
  44. package/dist/utils/panzoom.svelte.js +87 -43
  45. package/dist/utils/parse-incomplete-markdown.js +70 -1
  46. package/package.json +1 -1
@@ -106,6 +106,8 @@ class IncompleteMarkdownParser {
106
106
  const lines = text.split('\n');
107
107
  let inCodeBlock = false;
108
108
  let inMathBlock = false;
109
+ let inCenterBlock = false;
110
+ let inRightBlock = false;
109
111
  // Track which lines are in which contexts for state management
110
112
  const lineContexts = [];
111
113
  for (let i = 0; i < lines.length; i++) {
@@ -117,7 +119,24 @@ class IncompleteMarkdownParser {
117
119
  if (line.trim().startsWith('$$') && !line.trim().includes('$$', 2)) {
118
120
  inMathBlock = !inMathBlock;
119
121
  }
120
- lineContexts[i] = { code: inCodeBlock, math: inMathBlock };
122
+ if (line.trim() === '[center]') {
123
+ inCenterBlock = true;
124
+ }
125
+ if (line.trim() === '[/center]') {
126
+ inCenterBlock = false;
127
+ }
128
+ if (line.trim() === '[right]') {
129
+ inRightBlock = true;
130
+ }
131
+ if (line.trim() === '[/right]') {
132
+ inRightBlock = false;
133
+ }
134
+ lineContexts[i] = {
135
+ code: inCodeBlock,
136
+ math: inMathBlock,
137
+ center: inCenterBlock,
138
+ right: inRightBlock
139
+ };
121
140
  }
122
141
  // Set the final blocking contexts (for postprocessing)
123
142
  const finalContexts = new Set();
@@ -125,6 +144,10 @@ class IncompleteMarkdownParser {
125
144
  finalContexts.add('code');
126
145
  if (inMathBlock)
127
146
  finalContexts.add('math');
147
+ if (inCenterBlock)
148
+ finalContexts.add('center');
149
+ if (inRightBlock)
150
+ finalContexts.add('right');
128
151
  // Return both the text and the updated state
129
152
  return {
130
153
  text: text, // Don't modify text in preprocess
@@ -142,6 +165,12 @@ class IncompleteMarkdownParser {
142
165
  if (state.blockingContexts.has('math')) {
143
166
  return text + '\n$$';
144
167
  }
168
+ if (state.blockingContexts.has('center')) {
169
+ return text + '\n[/center]';
170
+ }
171
+ if (state.blockingContexts.has('right')) {
172
+ return text + '\n[/right]';
173
+ }
145
174
  return text;
146
175
  }
147
176
  },
@@ -406,6 +435,31 @@ class IncompleteMarkdownParser {
406
435
  return line;
407
436
  }
408
437
  },
438
+ {
439
+ name: 'inlineCitation',
440
+ pattern: /\[/,
441
+ skipInBlockTypes: ['code', 'math'],
442
+ handler: ({ line }) => {
443
+ // Count unescaped opening brackets without matching closing brackets
444
+ let unclosedBrackets = 0;
445
+ for (let i = 0; i < line.length; i++) {
446
+ if (line[i] === '[' && (i === 0 || line[i - 1] !== '\\')) {
447
+ // Check if this bracket has a matching closing bracket later in the line
448
+ const restOfLine = line.substring(i + 1);
449
+ const closingIndex = restOfLine.indexOf(']');
450
+ if (closingIndex === -1) {
451
+ unclosedBrackets++;
452
+ }
453
+ }
454
+ }
455
+ // If there's an odd number of unclosed brackets, add closing bracket
456
+ if (unclosedBrackets % 2 === 1) {
457
+ const endOfCellOrLine = findEndOfCellOrLineContaining(line, line.length - 1);
458
+ return line.substring(0, endOfCellOrLine) + ']' + line.substring(endOfCellOrLine);
459
+ }
460
+ return line;
461
+ }
462
+ },
409
463
  {
410
464
  name: 'footnoteRef',
411
465
  pattern: /\[\^[^\]\s,]*/,
@@ -601,6 +655,21 @@ class IncompleteMarkdownParser {
601
655
  }
602
656
  return line;
603
657
  }
658
+ },
659
+ {
660
+ name: 'alignmentBlocks',
661
+ pattern: /^(\s*\[(center|right)\])$/,
662
+ skipInBlockTypes: ['code', 'math'],
663
+ handler: ({ line, state }) => {
664
+ // Check if this is an opening alignment tag without content or closing tag
665
+ const alignMatch = line.match(/^(\s*\[(center|right)\])$/);
666
+ if (alignMatch) {
667
+ const indent = alignMatch[1].length - alignMatch[1].trim().length;
668
+ const alignType = alignMatch[2];
669
+ return line + '\n' + ' '.repeat(indent) + '[/' + alignType + ']';
670
+ }
671
+ return line;
672
+ }
604
673
  }
605
674
  ];
606
675
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-streamdown",
3
- "version": "2.4.5",
3
+ "version": "2.5.1",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",