svelte-streamdown 1.0.6 → 1.0.8

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 (90) hide show
  1. package/dist/Block.svelte +64 -20
  2. package/dist/Elements/A.svelte +17 -14
  3. package/dist/Elements/A.svelte.d.ts +7 -2
  4. package/dist/Elements/Alert.svelte +12 -28
  5. package/dist/Elements/Alert.svelte.d.ts +7 -2
  6. package/dist/Elements/Blockquote.svelte +11 -9
  7. package/dist/Elements/Blockquote.svelte.d.ts +7 -2
  8. package/dist/Elements/Code.svelte +13 -11
  9. package/dist/Elements/Code.svelte.d.ts +7 -2
  10. package/dist/Elements/Del.svelte +11 -7
  11. package/dist/Elements/Del.svelte.d.ts +7 -2
  12. package/dist/Elements/Element.svelte +50 -99
  13. package/dist/Elements/Element.svelte.d.ts +2 -5
  14. package/dist/Elements/Em.svelte +11 -6
  15. package/dist/Elements/Em.svelte.d.ts +7 -2
  16. package/dist/Elements/Heading.svelte +25 -0
  17. package/dist/Elements/Heading.svelte.d.ts +9 -0
  18. package/dist/Elements/Hr.svelte +12 -6
  19. package/dist/Elements/Hr.svelte.d.ts +7 -2
  20. package/dist/Elements/Image.svelte +17 -17
  21. package/dist/Elements/Image.svelte.d.ts +7 -2
  22. package/dist/Elements/InlineCode.svelte +12 -7
  23. package/dist/Elements/InlineCode.svelte.d.ts +7 -2
  24. package/dist/Elements/Li.svelte +11 -6
  25. package/dist/Elements/Li.svelte.d.ts +7 -2
  26. package/dist/Elements/Math.svelte +19 -9
  27. package/dist/Elements/Math.svelte.d.ts +7 -2
  28. package/dist/Elements/Mermaid.svelte +13 -9
  29. package/dist/Elements/Mermaid.svelte.d.ts +7 -2
  30. package/dist/Elements/Ol.svelte +13 -6
  31. package/dist/Elements/Ol.svelte.d.ts +7 -2
  32. package/dist/Elements/P.svelte +11 -6
  33. package/dist/Elements/P.svelte.d.ts +7 -2
  34. package/dist/Elements/Strong.svelte +11 -6
  35. package/dist/Elements/Strong.svelte.d.ts +7 -2
  36. package/dist/Elements/Sub.svelte +10 -6
  37. package/dist/Elements/Sub.svelte.d.ts +6 -2
  38. package/dist/Elements/Sup.svelte +10 -5
  39. package/dist/Elements/Sup.svelte.d.ts +6 -2
  40. package/dist/Elements/Table.svelte +12 -7
  41. package/dist/Elements/Table.svelte.d.ts +7 -2
  42. package/dist/Elements/Tbody.svelte +8 -7
  43. package/dist/Elements/Tbody.svelte.d.ts +5 -2
  44. package/dist/Elements/Td.svelte +12 -7
  45. package/dist/Elements/Td.svelte.d.ts +7 -2
  46. package/dist/Elements/Th.svelte +11 -6
  47. package/dist/Elements/Th.svelte.d.ts +7 -2
  48. package/dist/Elements/Thead.svelte +13 -9
  49. package/dist/Elements/Thead.svelte.d.ts +7 -2
  50. package/dist/Elements/Tr.svelte +13 -9
  51. package/dist/Elements/Tr.svelte.d.ts +7 -2
  52. package/dist/Elements/Ul.svelte +11 -6
  53. package/dist/Elements/Ul.svelte.d.ts +7 -2
  54. package/dist/Elements/index.d.ts +1 -7
  55. package/dist/Elements/index.js +1 -7
  56. package/dist/Streamdown.d.ts +16 -24
  57. package/dist/Streamdown.svelte +7 -39
  58. package/dist/Streamdown.svelte.d.ts +1 -1
  59. package/dist/hightlighter.svelte.js +0 -1
  60. package/dist/marked/index.d.ts +16 -0
  61. package/dist/marked/index.js +34 -0
  62. package/dist/marked/marked-alert.d.ts +19 -0
  63. package/dist/marked/marked-alert.js +54 -0
  64. package/dist/marked/marked-footnotes.d.ts +28 -0
  65. package/dist/marked/marked-footnotes.js +75 -0
  66. package/dist/marked/marked-math.d.ts +10 -0
  67. package/dist/marked/marked-math.js +60 -0
  68. package/dist/theme.d.ts +3 -3
  69. package/dist/theme.js +5 -5
  70. package/package.json +2 -14
  71. package/dist/Elements/H1.svelte +0 -23
  72. package/dist/Elements/H1.svelte.d.ts +0 -4
  73. package/dist/Elements/H2.svelte +0 -23
  74. package/dist/Elements/H2.svelte.d.ts +0 -4
  75. package/dist/Elements/H3.svelte +0 -23
  76. package/dist/Elements/H3.svelte.d.ts +0 -4
  77. package/dist/Elements/H4.svelte +0 -23
  78. package/dist/Elements/H4.svelte.d.ts +0 -4
  79. package/dist/Elements/H5.svelte +0 -23
  80. package/dist/Elements/H5.svelte.d.ts +0 -4
  81. package/dist/Elements/H6.svelte +0 -23
  82. package/dist/Elements/H6.svelte.d.ts +0 -4
  83. package/dist/Elements/element.d.ts +0 -8
  84. package/dist/Elements/element.js +0 -1
  85. package/dist/utils/alerts.d.ts +0 -12
  86. package/dist/utils/alerts.js +0 -207
  87. package/dist/utils/parse-blocks.d.ts +0 -1
  88. package/dist/utils/parse-blocks.js +0 -40
  89. package/dist/utils/parse.d.ts +0 -3
  90. package/dist/utils/parse.js +0 -131
@@ -1,40 +0,0 @@
1
- import { marked } from 'marked';
2
- export const parseMarkdownIntoBlocks = (markdown) => {
3
- const tokens = marked.use({ gfm: true }).lexer(markdown);
4
- const blocks = tokens.map((token) => token.raw);
5
- // Post-process to merge consecutive blocks that are part of the same math block
6
- const mergedBlocks = [];
7
- for (let i = 0; i < blocks.length; i++) {
8
- const currentBlock = blocks[i];
9
- // Check if this is a standalone $$ that might be a closing delimiter
10
- if (currentBlock.trim() === '$$' && mergedBlocks.length > 0) {
11
- const previousBlock = mergedBlocks.at(-1);
12
- // Check if the previous block starts with $$ but doesn't end with $$
13
- const prevStartsWith$$ = previousBlock?.trimStart().startsWith('$$');
14
- const prevDollarCount = (previousBlock?.match(/\$\$/g) || []).length;
15
- // If previous block has odd number of $$ and starts with $$, merge them
16
- if (prevStartsWith$$ && prevDollarCount % 2 === 1) {
17
- mergedBlocks[mergedBlocks.length - 1] = previousBlock + currentBlock;
18
- continue;
19
- }
20
- }
21
- // Check if current block ends with $$ and previous block started with $$ but didn't close
22
- if (mergedBlocks.length > 0 && currentBlock.trimEnd().endsWith('$$')) {
23
- const previousBlock = mergedBlocks.at(-1);
24
- const prevStartsWith$$ = previousBlock?.trimStart().startsWith('$$');
25
- const prevDollarCount = (previousBlock?.match(/\$\$/g) || []).length;
26
- const currDollarCount = (currentBlock.match(/\$\$/g) || []).length;
27
- // If previous block has unclosed math (odd $$) and current block ends with $$
28
- // AND current block doesn't start with $$, it's likely a continuation
29
- if (prevStartsWith$$ &&
30
- prevDollarCount % 2 === 1 &&
31
- !currentBlock.trimStart().startsWith('$$') &&
32
- currDollarCount === 1) {
33
- mergedBlocks[mergedBlocks.length - 1] = previousBlock + currentBlock;
34
- continue;
35
- }
36
- }
37
- mergedBlocks.push(currentBlock);
38
- }
39
- return mergedBlocks;
40
- };
@@ -1,3 +0,0 @@
1
- import type { StreamdownContext } from '../Streamdown.svelte';
2
- import type { Root } from 'hast';
3
- export declare function parseMarkdown(context: StreamdownContext, content: string): Root;
@@ -1,131 +0,0 @@
1
- import { urlAttributes } from 'html-url-attributes';
2
- import remarkParse from 'remark-parse';
3
- import remarkRehype, {} from 'remark-rehype';
4
- import { unified } from 'unified';
5
- import { visit } from 'unist-util-visit';
6
- import remarkGfm from 'remark-gfm';
7
- import remarkMath from 'remark-math';
8
- import { rehypeGithubAlerts } from './alerts.js';
9
- const emptyPlugins = [];
10
- const emptyRemarkRehypeOptions = { allowDangerousHtml: true };
11
- const safeProtocol = /^(https?|ircs?|mailto|xmpp)$/i;
12
- export function parseMarkdown(context, content) {
13
- const rehypePlugins = context.rehypePlugins || emptyPlugins;
14
- const remarkPlugins = context.remarkPlugins || emptyPlugins;
15
- const remarkRehypeOptions = context.remarkRehypeOptions
16
- ? { ...context.remarkRehypeOptions, ...emptyRemarkRehypeOptions }
17
- : emptyRemarkRehypeOptions;
18
- const processor = unified()
19
- .use(remarkParse)
20
- .use(remarkPlugins)
21
- .use(remarkMath)
22
- .use(remarkGfm)
23
- .use(remarkRehype, remarkRehypeOptions)
24
- .use(rehypePlugins)
25
- .use([rehypeGithubAlerts]);
26
- const tree = processor.runSync(processor.parse(content));
27
- return post(tree, {
28
- allowElement: context.allowElement,
29
- allowedElements: context.allowedElements,
30
- disallowedElements: context.disallowedElements,
31
- skipHtml: context.skipHtml,
32
- unwrapDisallowed: context.unwrapDisallowed,
33
- urlTransform: context.urlTransform
34
- });
35
- }
36
- /**
37
- * Process the HAST tree with filtering and transformations
38
- */
39
- function post(tree, options) {
40
- const allowedElements = options.allowedElements;
41
- const allowElement = options.allowElement;
42
- const disallowedElements = options.disallowedElements;
43
- const skipHtml = options.skipHtml;
44
- const unwrapDisallowed = options.unwrapDisallowed;
45
- const urlTransform = options.urlTransform || defaultUrlTransform;
46
- if (allowedElements && disallowedElements) {
47
- throw new Error('Unexpected combined `allowedElements` and `disallowedElements`, expected one or the other');
48
- }
49
- visit(tree, transform);
50
- return tree;
51
- /** @type {import('unist-util-visit').BuildVisitor<Root>} */
52
- function transform(node, index, parent) {
53
- if (node.type === 'raw' && parent && typeof index === 'number') {
54
- if (skipHtml) {
55
- parent.children.splice(index, 1);
56
- }
57
- else {
58
- parent.children[index] = { type: 'text', value: node.value };
59
- }
60
- return index;
61
- }
62
- if (node.type === 'element') {
63
- const element = node;
64
- // Transform URLs
65
- for (const key in urlAttributes) {
66
- if (Object.hasOwn(urlAttributes, key) && Object.hasOwn(element.properties, key)) {
67
- const value = element.properties[key];
68
- const test = urlAttributes[key];
69
- if (test === null || test.includes(element.tagName)) {
70
- element.properties[key] = urlTransform(String(value || ''), key, element);
71
- }
72
- }
73
- }
74
- const className = node.properties.className;
75
- if (node.tagName === 'code') {
76
- const LANGUAGE_REGEX = /language-([^\s]+)/;
77
- const match = (Array.isArray(className) ? className : [className])?.reduce((acc, c) => {
78
- const match = String(c).match(LANGUAGE_REGEX);
79
- const lang = match?.[1];
80
- if (lang) {
81
- acc = lang;
82
- }
83
- return acc;
84
- }, '');
85
- const language = (match ?? 'plaintext');
86
- node.properties.language = language;
87
- }
88
- }
89
- if (node.type === 'element') {
90
- const element = node;
91
- let remove = allowedElements
92
- ? !allowedElements.includes(element.tagName)
93
- : disallowedElements
94
- ? disallowedElements.includes(element.tagName)
95
- : false;
96
- if (!remove && allowElement && typeof index === 'number') {
97
- remove = !allowElement(element, index, parent);
98
- }
99
- if (remove && parent && typeof index === 'number') {
100
- if (unwrapDisallowed && element.children) {
101
- parent.children.splice(index, 1, ...element.children);
102
- }
103
- else {
104
- parent.children.splice(index, 1);
105
- }
106
- return index;
107
- }
108
- }
109
- }
110
- }
111
- /**
112
- * Make a URL safe (GitHub-style)
113
- */
114
- function defaultUrlTransform(value) {
115
- const colon = value.indexOf(':');
116
- const questionMark = value.indexOf('?');
117
- const numberSign = value.indexOf('#');
118
- const slash = value.indexOf('/');
119
- if (
120
- // If there is no protocol, it's relative
121
- colon === -1 ||
122
- // If the first colon is after a `?`, `#`, or `/`, it's not a protocol
123
- (slash !== -1 && colon > slash) ||
124
- (questionMark !== -1 && colon > questionMark) ||
125
- (numberSign !== -1 && colon > numberSign) ||
126
- // It is a protocol, it should be allowed
127
- safeProtocol.test(value.slice(0, colon))) {
128
- return value;
129
- }
130
- return '';
131
- }