@svadmin/ai-elements 0.7.4 → 0.8.0
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/README.md +20 -4
- package/THIRD_PARTY_NOTICES.md +67 -6
- package/dist/ai.css +1 -5
- package/dist/ai.theme.css +1 -0
- package/dist/class-properties.generated.d.ts +1 -0
- package/dist/class-properties.generated.js +2 -0
- package/dist/classnames.d.ts +8 -0
- package/dist/classnames.js +26 -0
- package/dist/components/Response.svelte +2 -2
- package/dist/components/Response.svelte.d.ts +1 -1
- package/dist/components/code/index.d.ts +9 -18
- package/dist/components/code/index.js +8 -11
- package/dist/components/code-block/highlight.js +1 -1
- package/dist/utilities.css +3172 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +36 -11
- package/vendor/streamdown/AnimatedText.svelte +93 -0
- package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
- package/vendor/streamdown/Block.svelte +96 -0
- package/vendor/streamdown/Block.svelte.d.ts +11 -0
- package/vendor/streamdown/Elements/Alert.svelte +69 -0
- package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Citation.svelte +260 -0
- package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Code.svelte +226 -0
- package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Element.svelte +574 -0
- package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
- package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Image.svelte +200 -0
- package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Link.svelte +220 -0
- package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
- package/vendor/streamdown/Elements/Math.svelte +100 -0
- package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
- package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/Slot.svelte +23 -0
- package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Table.svelte +195 -0
- package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
- package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
- package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
- package/vendor/streamdown/Elements/icons.d.ts +31 -0
- package/vendor/streamdown/Elements/icons.js +200 -0
- package/vendor/streamdown/Elements/index.d.ts +8 -0
- package/vendor/streamdown/Elements/index.js +8 -0
- package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/popover.svelte.js +45 -0
- package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
- package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
- package/vendor/streamdown/IconProvider.svelte +11 -0
- package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/LICENSE +202 -0
- package/vendor/streamdown/PluginProvider.svelte +11 -0
- package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/README.svadmin.md +5 -0
- package/vendor/streamdown/Streamdown.svelte +447 -0
- package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
- package/vendor/streamdown/block/BlockTokens.svelte +45 -0
- package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
- package/vendor/streamdown/block/html.d.ts +14 -0
- package/vendor/streamdown/block/html.js +27 -0
- package/vendor/streamdown/block/text.d.ts +10 -0
- package/vendor/streamdown/block/text.js +31 -0
- package/vendor/streamdown/context-key.d.ts +1 -0
- package/vendor/streamdown/context-key.js +1 -0
- package/vendor/streamdown/context.svelte.d.ts +24 -0
- package/vendor/streamdown/context.svelte.js +75 -0
- package/vendor/streamdown/contracts/plugins.d.ts +26 -0
- package/vendor/streamdown/contracts/plugins.js +1 -0
- package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
- package/vendor/streamdown/contracts/streamdown.js +29 -0
- package/vendor/streamdown/detect-direction.d.ts +1 -0
- package/vendor/streamdown/detect-direction.js +1 -0
- package/vendor/streamdown/icon-context.d.ts +36 -0
- package/vendor/streamdown/icon-context.js +52 -0
- package/vendor/streamdown/incomplete-code.d.ts +6 -0
- package/vendor/streamdown/incomplete-code.js +23 -0
- package/vendor/streamdown/index.d.ts +22 -0
- package/vendor/streamdown/index.js +20 -0
- package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
- package/vendor/streamdown/markdown-parse-cache.js +109 -0
- package/vendor/streamdown/markdown.d.ts +21 -0
- package/vendor/streamdown/markdown.js +214 -0
- package/vendor/streamdown/marked/index.d.ts +44 -0
- package/vendor/streamdown/marked/index.js +228 -0
- package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
- package/vendor/streamdown/marked/marked-alert.js +47 -0
- package/vendor/streamdown/marked/marked-align.d.ts +10 -0
- package/vendor/streamdown/marked/marked-align.js +45 -0
- package/vendor/streamdown/marked/marked-br.d.ts +6 -0
- package/vendor/streamdown/marked/marked-br.js +15 -0
- package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
- package/vendor/streamdown/marked/marked-citations.js +53 -0
- package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
- package/vendor/streamdown/marked/marked-cjk.js +165 -0
- package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
- package/vendor/streamdown/marked/marked-dl.js +44 -0
- package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
- package/vendor/streamdown/marked/marked-footnotes.js +101 -0
- package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
- package/vendor/streamdown/marked/marked-hr.js +18 -0
- package/vendor/streamdown/marked/marked-list.d.ts +31 -0
- package/vendor/streamdown/marked/marked-list.js +330 -0
- package/vendor/streamdown/marked/marked-math.d.ts +13 -0
- package/vendor/streamdown/marked/marked-math.js +129 -0
- package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
- package/vendor/streamdown/marked/marked-mdx.js +124 -0
- package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
- package/vendor/streamdown/marked/marked-subsup.js +40 -0
- package/vendor/streamdown/marked/marked-table.d.ts +80 -0
- package/vendor/streamdown/marked/marked-table.js +527 -0
- package/vendor/streamdown/plugin-context.d.ts +19 -0
- package/vendor/streamdown/plugin-context.js +40 -0
- package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
- package/vendor/streamdown/plugins/cjk-shared.js +1 -0
- package/vendor/streamdown/plugins.d.ts +19 -0
- package/vendor/streamdown/plugins.js +107 -0
- package/vendor/streamdown/provenance.json +229 -0
- package/vendor/streamdown/remend.d.ts +2 -0
- package/vendor/streamdown/remend.js +1 -0
- package/vendor/streamdown/security/html.d.ts +19 -0
- package/vendor/streamdown/security/html.js +329 -0
- package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
- package/vendor/streamdown/security/types.d.ts +1 -0
- package/vendor/streamdown/security/types.js +1 -0
- package/vendor/streamdown/site/SiteHeader.svelte +94 -0
- package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/HomePage.svelte +293 -0
- package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/content.d.ts +69 -0
- package/vendor/streamdown/site/home/content.js +144 -0
- package/vendor/streamdown/site/metadata.d.ts +4 -0
- package/vendor/streamdown/site/metadata.js +4 -0
- package/vendor/streamdown/site/navigation.d.ts +6 -0
- package/vendor/streamdown/site/navigation.js +22 -0
- package/vendor/streamdown/streamdown/config.d.ts +41 -0
- package/vendor/streamdown/streamdown/config.js +125 -0
- package/vendor/streamdown/streamdown/context.d.ts +12 -0
- package/vendor/streamdown/streamdown/context.js +2 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
- package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
- package/vendor/streamdown/streamdown/pipeline.js +138 -0
- package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
- package/vendor/streamdown/streamdown/runtime.js +112 -0
- package/vendor/streamdown/streaming.d.ts +5 -0
- package/vendor/streamdown/streaming.js +5 -0
- package/vendor/streamdown/theme.d.ts +486 -0
- package/vendor/streamdown/theme.js +370 -0
- package/vendor/streamdown/translations.d.ts +43 -0
- package/vendor/streamdown/translations.js +54 -0
- package/vendor/streamdown/url-policy.d.ts +1 -0
- package/vendor/streamdown/url-policy.js +1 -0
- package/vendor/streamdown/utils/bind.d.ts +8 -0
- package/vendor/streamdown/utils/bind.js +26 -0
- package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
- package/vendor/streamdown/utils/bundledLanguages.js +1 -0
- package/vendor/streamdown/utils/code-block.d.ts +8 -0
- package/vendor/streamdown/utils/code-block.js +38 -0
- package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
- package/vendor/streamdown/utils/copy.svelte.js +38 -0
- package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
- package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
- package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
- package/vendor/streamdown/utils/detectDirection.js +19 -0
- package/vendor/streamdown/utils/get.d.ts +1 -0
- package/vendor/streamdown/utils/get.js +25 -0
- package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
- package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
- package/vendor/streamdown/utils/index.d.ts +3 -0
- package/vendor/streamdown/utils/index.js +3 -0
- package/vendor/streamdown/utils/mermaid.d.ts +13 -0
- package/vendor/streamdown/utils/mermaid.js +49 -0
- package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
- package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
- package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
- package/vendor/streamdown/utils/runtime-env.js +13 -0
- package/vendor/streamdown/utils/save.d.ts +1 -0
- package/vendor/streamdown/utils/save.js +14 -0
- package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
- package/vendor/streamdown/utils/scroll-lock.js +35 -0
- package/vendor/streamdown/utils/table.d.ts +8 -0
- package/vendor/streamdown/utils/table.js +176 -0
- package/vendor/streamdown/utils/url.d.ts +22 -0
- package/vendor/streamdown/utils/url.js +98 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
export function letterToInt(letter) {
|
|
2
|
+
return letter.toLowerCase().charCodeAt(0) - 96;
|
|
3
|
+
}
|
|
4
|
+
const romanMap = {
|
|
5
|
+
I: 1,
|
|
6
|
+
V: 5,
|
|
7
|
+
X: 10,
|
|
8
|
+
L: 50,
|
|
9
|
+
C: 100,
|
|
10
|
+
D: 500,
|
|
11
|
+
M: 1000
|
|
12
|
+
};
|
|
13
|
+
export function romanToInt(roman) {
|
|
14
|
+
roman = roman.toUpperCase();
|
|
15
|
+
let total = 0;
|
|
16
|
+
for (let i = 0; i < roman.length; i++) {
|
|
17
|
+
const current = romanMap[roman[i]];
|
|
18
|
+
const next = romanMap[roman[i + 1]];
|
|
19
|
+
total += next && current < next ? -current : current;
|
|
20
|
+
}
|
|
21
|
+
return total;
|
|
22
|
+
}
|
|
23
|
+
// Regular expression patterns for list detection
|
|
24
|
+
export const romanUpper = '(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))';
|
|
25
|
+
export const romanLower = '(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3}))';
|
|
26
|
+
// Fixed regex pattern - carefully balanced parentheses
|
|
27
|
+
export const bulletPattern = `(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|${romanUpper}|${romanLower})[.)])`;
|
|
28
|
+
export const rule = `^( {0,3}${bulletPattern})([ \\t][^\\n]*|[ \\t])?(?:\\n|$)`;
|
|
29
|
+
function finalizeList(list, lexer) {
|
|
30
|
+
if (list.tokens.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
// Trim trailing newline from last item
|
|
33
|
+
const lastItem = list.tokens[list.tokens.length - 1];
|
|
34
|
+
lastItem.raw = lastItem.raw.trimEnd();
|
|
35
|
+
lastItem.text = lastItem.text.trimEnd();
|
|
36
|
+
list.raw = list.raw.trimEnd();
|
|
37
|
+
// Handle child tokens
|
|
38
|
+
for (const item of list.tokens) {
|
|
39
|
+
lexer.state.top = false;
|
|
40
|
+
item.tokens = lexer.blockTokens(item.text, []);
|
|
41
|
+
if (!list.loose) {
|
|
42
|
+
const hasLooseParagraphSpacing = item.tokens.some((token) => token.type === 'space' && /\n.*\n/.test(token.raw));
|
|
43
|
+
if (hasLooseParagraphSpacing) {
|
|
44
|
+
list.loose = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Mark list as loose if needed
|
|
49
|
+
if (list.loose) {
|
|
50
|
+
for (const item of list.tokens) {
|
|
51
|
+
item.loose = true;
|
|
52
|
+
item.tokens = normalizeLooseListItemTokens(item.tokens);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function escapeForRegex(s) {
|
|
57
|
+
return s.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
|
|
58
|
+
}
|
|
59
|
+
function paragraphFromTextTokens(tokens) {
|
|
60
|
+
const firstToken = tokens[0];
|
|
61
|
+
if (tokens.length === 1) {
|
|
62
|
+
return {
|
|
63
|
+
type: 'paragraph',
|
|
64
|
+
raw: firstToken.raw,
|
|
65
|
+
text: firstToken.text ?? firstToken.raw,
|
|
66
|
+
tokens: firstToken.tokens ?? [
|
|
67
|
+
{
|
|
68
|
+
type: 'text',
|
|
69
|
+
raw: firstToken.raw,
|
|
70
|
+
text: firstToken.text ?? firstToken.raw,
|
|
71
|
+
escaped: false
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const inlineTokens = [];
|
|
77
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
78
|
+
const token = tokens[index];
|
|
79
|
+
if (index > 0) {
|
|
80
|
+
inlineTokens.push({
|
|
81
|
+
type: 'text',
|
|
82
|
+
raw: '\n',
|
|
83
|
+
text: '\n',
|
|
84
|
+
escaped: false
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (token.tokens && token.tokens.length > 0) {
|
|
88
|
+
inlineTokens.push(...token.tokens);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
inlineTokens.push({
|
|
92
|
+
type: 'text',
|
|
93
|
+
raw: token.raw,
|
|
94
|
+
text: token.text ?? token.raw,
|
|
95
|
+
escaped: false
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
type: 'paragraph',
|
|
101
|
+
raw: tokens.map((token) => token.raw).join('\n'),
|
|
102
|
+
text: tokens.map((token) => token.text ?? token.raw).join('\n'),
|
|
103
|
+
tokens: inlineTokens
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function normalizeLooseListItemTokens(tokens) {
|
|
107
|
+
const hasTextTokens = tokens.some((token) => token.type === 'text');
|
|
108
|
+
const hasParagraphSeparators = tokens.some((token) => token.type === 'space');
|
|
109
|
+
const hasMixedBlockContent = hasTextTokens && tokens.some((token) => token.type !== 'text' && token.type !== 'space');
|
|
110
|
+
// Keep plain single-run text items stable so streaming updates do not remount
|
|
111
|
+
// already-rendered spans when a neighboring list group makes the parent list loose.
|
|
112
|
+
if (!hasParagraphSeparators && !hasMixedBlockContent) {
|
|
113
|
+
return tokens;
|
|
114
|
+
}
|
|
115
|
+
const normalized = [];
|
|
116
|
+
let textTokens = [];
|
|
117
|
+
const flushTextTokens = () => {
|
|
118
|
+
if (textTokens.length === 0) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
normalized.push(paragraphFromTextTokens(textTokens));
|
|
122
|
+
textTokens = [];
|
|
123
|
+
};
|
|
124
|
+
for (const token of tokens) {
|
|
125
|
+
if (token.type === 'space') {
|
|
126
|
+
flushTextTokens();
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (token.type === 'text') {
|
|
130
|
+
textTokens.push(token);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
flushTextTokens();
|
|
134
|
+
normalized.push(token);
|
|
135
|
+
}
|
|
136
|
+
flushTextTokens();
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
export const markedList = {
|
|
140
|
+
name: 'list',
|
|
141
|
+
level: 'block',
|
|
142
|
+
tokenizer(src) {
|
|
143
|
+
let cap = new RegExp(rule).exec(src);
|
|
144
|
+
if (!cap)
|
|
145
|
+
return undefined;
|
|
146
|
+
const bullet = cap[1].trim();
|
|
147
|
+
const isOrdered = bullet !== '*' && bullet !== '-' && bullet !== '+';
|
|
148
|
+
let bull;
|
|
149
|
+
let type = '';
|
|
150
|
+
let expectedValue = null;
|
|
151
|
+
// Detect list type (Roman, alphabetic, numeric)
|
|
152
|
+
if (isOrdered) {
|
|
153
|
+
if (bullet.match(new RegExp(`^${romanUpper}[.)]$`))) {
|
|
154
|
+
type = 'upper-roman';
|
|
155
|
+
bull = `${romanUpper}\\${bullet.slice(-1)}`;
|
|
156
|
+
}
|
|
157
|
+
else if (bullet.match(new RegExp(`^${romanLower}[.)]$`))) {
|
|
158
|
+
type = 'lower-roman';
|
|
159
|
+
bull = `${romanLower}\\${bullet.slice(-1)}`;
|
|
160
|
+
}
|
|
161
|
+
else if (bullet.match(/^[a-z][.)]$/)) {
|
|
162
|
+
type = 'lower-alpha';
|
|
163
|
+
bull = `[a-z]\\${bullet.slice(-1)}`;
|
|
164
|
+
}
|
|
165
|
+
else if (bullet.match(/^[A-Z][.)]$/)) {
|
|
166
|
+
type = 'upper-alpha';
|
|
167
|
+
bull = `[A-Z]\\${bullet.slice(-1)}`;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
type = 'decimal';
|
|
171
|
+
bull = `\\d{1,9}\\${bullet.slice(-1)}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
bull = this.lexer.options.pedantic ? bullet : '[*+-]';
|
|
176
|
+
bull = this.lexer.options.pedantic ? escapeForRegex(bullet) : '[*+-]';
|
|
177
|
+
}
|
|
178
|
+
const list = {
|
|
179
|
+
type: 'list',
|
|
180
|
+
raw: '',
|
|
181
|
+
ordered: isOrdered,
|
|
182
|
+
listType: isOrdered ? type : null,
|
|
183
|
+
loose: false,
|
|
184
|
+
start: undefined, // Will be set when first item is processed
|
|
185
|
+
tokens: []
|
|
186
|
+
};
|
|
187
|
+
// Get next list item
|
|
188
|
+
// Updated regex to properly handle empty list items (space after bullet, then newline)
|
|
189
|
+
const itemRegex = new RegExp(`^( {0,3}${bull})([\t ][^\\n]*|[\t ])?(?:\\n|$)`);
|
|
190
|
+
let endsWithBlankLine = false;
|
|
191
|
+
// Check if current bullet point can start a new List Item
|
|
192
|
+
while (src) {
|
|
193
|
+
let raw = '';
|
|
194
|
+
let itemContents = '';
|
|
195
|
+
let endEarly = false;
|
|
196
|
+
if (!(cap = itemRegex.exec(src)))
|
|
197
|
+
break;
|
|
198
|
+
raw = cap[0];
|
|
199
|
+
const bullet = cap[1].trim();
|
|
200
|
+
src = src.substring(raw.length);
|
|
201
|
+
const line = cap[2]
|
|
202
|
+
? cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(4 * t.length))
|
|
203
|
+
: '';
|
|
204
|
+
const nextLine = src.split('\n', 1)[0];
|
|
205
|
+
const blankLine = !line.trim();
|
|
206
|
+
let indent = 0;
|
|
207
|
+
if (this.lexer.options.pedantic) {
|
|
208
|
+
indent = 2;
|
|
209
|
+
itemContents = line.trimStart();
|
|
210
|
+
}
|
|
211
|
+
else if (blankLine) {
|
|
212
|
+
indent = cap[1].length + 1;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
|
216
|
+
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
|
217
|
+
itemContents = line.slice(indent);
|
|
218
|
+
indent += cap[1].length;
|
|
219
|
+
}
|
|
220
|
+
if (blankLine && /^[ \t]*$/.test(nextLine)) {
|
|
221
|
+
// Items begin with at most one blank line
|
|
222
|
+
raw += nextLine + '\n';
|
|
223
|
+
src = src.substring(nextLine.length + 1);
|
|
224
|
+
endEarly = true;
|
|
225
|
+
}
|
|
226
|
+
if (!endEarly) {
|
|
227
|
+
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|${romanUpper}|${romanLower})[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
|
|
228
|
+
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
|
|
229
|
+
const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
|
|
230
|
+
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
|
|
231
|
+
const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<[a-z].*>`, 'i');
|
|
232
|
+
const footnoteBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}\\[\\^[^\\]\\n]+\\]:(?:[ \\t]+|$)`);
|
|
233
|
+
let previousLineWasBlank = blankLine;
|
|
234
|
+
// Check if following lines should be included in List Item
|
|
235
|
+
while (src) {
|
|
236
|
+
const rawLine = src.split('\n', 1)[0];
|
|
237
|
+
const nextLineWithoutTabs = rawLine.replace(/\t/g, ' ');
|
|
238
|
+
const nextLineIndent = nextLineWithoutTabs.search(/[^ ]/);
|
|
239
|
+
const isBlankLine = nextLineIndent === -1;
|
|
240
|
+
if (fencesBeginRegex.test(nextLineWithoutTabs) ||
|
|
241
|
+
headingBeginRegex.test(nextLineWithoutTabs) ||
|
|
242
|
+
htmlBeginRegex.test(nextLineWithoutTabs) ||
|
|
243
|
+
footnoteBeginRegex.test(nextLineWithoutTabs) ||
|
|
244
|
+
nextBulletRegex.test(nextLineWithoutTabs) ||
|
|
245
|
+
hrRegex.test(nextLineWithoutTabs))
|
|
246
|
+
break;
|
|
247
|
+
// A blank-line break closes the list item before dedented prose resumes at top level.
|
|
248
|
+
if (previousLineWasBlank && !isBlankLine && nextLineIndent < indent)
|
|
249
|
+
break;
|
|
250
|
+
if (nextLineIndent >= indent || isBlankLine) {
|
|
251
|
+
itemContents += '\n' + (isBlankLine ? '' : nextLineWithoutTabs.slice(indent));
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
itemContents += '\n' + nextLineWithoutTabs;
|
|
255
|
+
}
|
|
256
|
+
previousLineWasBlank = isBlankLine;
|
|
257
|
+
raw += rawLine + '\n';
|
|
258
|
+
src = src.substring(rawLine.length + 1);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (!list.loose) {
|
|
262
|
+
// If the previous item ended with a blank line, the list is loose
|
|
263
|
+
if (endsWithBlankLine) {
|
|
264
|
+
list.loose = true;
|
|
265
|
+
}
|
|
266
|
+
else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
|
|
267
|
+
endsWithBlankLine = true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
let isTask = null;
|
|
271
|
+
let isChecked = false;
|
|
272
|
+
// Check for task list items
|
|
273
|
+
if (this.lexer.options.gfm) {
|
|
274
|
+
isTask = /^\[[ xX]] /.exec(itemContents);
|
|
275
|
+
if (isTask) {
|
|
276
|
+
isChecked = isTask[0] !== '[ ] ';
|
|
277
|
+
itemContents = itemContents.replace(/^\[[ xX]] +/, '');
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
let value = null;
|
|
281
|
+
if (!isOrdered) {
|
|
282
|
+
// Do nothing for unordered lists
|
|
283
|
+
}
|
|
284
|
+
else if (type === 'decimal') {
|
|
285
|
+
value = parseInt(bullet.slice(0, -1), 10);
|
|
286
|
+
}
|
|
287
|
+
else if (type === 'lower-alpha' || type === 'upper-alpha') {
|
|
288
|
+
value = letterToInt(bullet.slice(0, -1));
|
|
289
|
+
}
|
|
290
|
+
else if (type === 'lower-roman' || type === 'upper-roman') {
|
|
291
|
+
value = romanToInt(bullet.slice(0, -1));
|
|
292
|
+
}
|
|
293
|
+
// Handle expectedValue initialization and validation
|
|
294
|
+
let skipped = false;
|
|
295
|
+
if (isOrdered) {
|
|
296
|
+
if (expectedValue === null) {
|
|
297
|
+
// First item: set expectedValue to this item's value (or 1 if parsing failed)
|
|
298
|
+
expectedValue = value ?? 1;
|
|
299
|
+
// Set the start property for ordered lists
|
|
300
|
+
list.start = expectedValue;
|
|
301
|
+
// Subsequent ordered items should advance from the first marker.
|
|
302
|
+
expectedValue += 1;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// Subsequent items: check if value matches expected
|
|
306
|
+
skipped = value !== null && value !== expectedValue;
|
|
307
|
+
// Increment expectedValue for next item
|
|
308
|
+
expectedValue += 1;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
list.tokens.push({
|
|
312
|
+
type: 'list_item',
|
|
313
|
+
raw,
|
|
314
|
+
task: !!isTask,
|
|
315
|
+
checked: isChecked,
|
|
316
|
+
loose: false,
|
|
317
|
+
text: itemContents,
|
|
318
|
+
value,
|
|
319
|
+
skipped,
|
|
320
|
+
tokens: []
|
|
321
|
+
});
|
|
322
|
+
list.raw += raw;
|
|
323
|
+
}
|
|
324
|
+
if (list.tokens.length === 0)
|
|
325
|
+
return undefined;
|
|
326
|
+
// Finalize the list
|
|
327
|
+
finalizeList(list, this.lexer);
|
|
328
|
+
return list;
|
|
329
|
+
}
|
|
330
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
|
+
export type MarkedMathOptions = {
|
|
3
|
+
singleDollarTextMath?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const createMarkedMathExtensions: (options?: MarkedMathOptions) => Extension[];
|
|
6
|
+
export declare const markedMath: Extension[];
|
|
7
|
+
export type MathToken = {
|
|
8
|
+
type: 'math';
|
|
9
|
+
raw: string;
|
|
10
|
+
text: string;
|
|
11
|
+
isInline: boolean;
|
|
12
|
+
displayMode: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Math parsing rules
|
|
2
|
+
// Block math: supports both newline format ($$\nmath\n$$) and single-line format ($$math$$)
|
|
3
|
+
const blockRule = /^(\$\$)(?:\n((?:\\[\s\S]|[^\\]|\\(?=\n))*?)(?:\n\1|\1)(?:\n|$)|([^$\n]*?)\1(?=\s|$|$))/;
|
|
4
|
+
// Inline math: handles both single ($) and double ($$) dollar delimiters
|
|
5
|
+
// Avoids matching currency by checking context and requiring proper content
|
|
6
|
+
const inlineRule = /^(\${1,2})(?!\$)((?:[^$\n]|\\\$)*?)\1(?!\d)/;
|
|
7
|
+
// Enhanced currency detection patterns
|
|
8
|
+
const currencyPatterns = {
|
|
9
|
+
// Simple price patterns: $123, $123.45, $1,234.56
|
|
10
|
+
simplePrice: /^\d{1,3}(?:,\d{3})*(?:\.\d{2})?$/,
|
|
11
|
+
// Multiple prices or numbers: "123, 456", "123.45, 678.90", "123 or 456"
|
|
12
|
+
multipleNumbers: /^\d+(?:[.,]\d+)*(?:\s*[,;]\s*\d+(?:[.,]\d+)*)+$/,
|
|
13
|
+
// Price ranges: "123-456", "123 - 456", "123 to 456"
|
|
14
|
+
priceRange: /^\d+(?:\.\d{2})?\s*(?:-|to|or)\s*\d+(?:\.\d{2})?$/i,
|
|
15
|
+
// Common currency words nearby (check surrounding context)
|
|
16
|
+
currencyContext: /(?:price|cost|dollar|euro|pound|yen|currency|pay|buy|sell|expensive|cheap)/i
|
|
17
|
+
};
|
|
18
|
+
export const createMarkedMathExtensions = (options = {}) => {
|
|
19
|
+
const singleDollarTextMath = options.singleDollarTextMath ?? false;
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
name: 'math',
|
|
23
|
+
level: 'block',
|
|
24
|
+
tokenizer(src) {
|
|
25
|
+
const match = src.match(blockRule);
|
|
26
|
+
if (match) {
|
|
27
|
+
// match[2] is multiline format, match[3] is single-line format
|
|
28
|
+
const content = (match[2] ?? match[3] ?? '').trim();
|
|
29
|
+
return {
|
|
30
|
+
type: 'math',
|
|
31
|
+
isInline: false,
|
|
32
|
+
displayMode: true,
|
|
33
|
+
raw: match[0],
|
|
34
|
+
text: content
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'math',
|
|
41
|
+
level: 'inline',
|
|
42
|
+
start(src) {
|
|
43
|
+
let index = 0;
|
|
44
|
+
let searchSrc = src;
|
|
45
|
+
while (searchSrc) {
|
|
46
|
+
const dollarIndex = searchSrc.indexOf('$');
|
|
47
|
+
if (dollarIndex === -1) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const currentIndex = index + dollarIndex;
|
|
51
|
+
const possibleMath = src.substring(currentIndex);
|
|
52
|
+
if (possibleMath.match(inlineRule)) {
|
|
53
|
+
const match = possibleMath.match(inlineRule);
|
|
54
|
+
if (match) {
|
|
55
|
+
const content = match[2];
|
|
56
|
+
const dollarCount = match[1];
|
|
57
|
+
if (dollarCount === '$' && !singleDollarTextMath) {
|
|
58
|
+
index += dollarIndex + 1;
|
|
59
|
+
searchSrc = src.substring(index);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (dollarCount === '$' && isCurrencyPattern(content, src, currentIndex)) {
|
|
63
|
+
index += dollarIndex + 1;
|
|
64
|
+
searchSrc = src.substring(index);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
return currentIndex;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
index += dollarIndex + 1;
|
|
71
|
+
searchSrc = src.substring(index);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
tokenizer(src) {
|
|
75
|
+
const match = src.match(inlineRule);
|
|
76
|
+
if (match) {
|
|
77
|
+
const content = match[2];
|
|
78
|
+
const dollarCount = match[1];
|
|
79
|
+
const isDisplayMode = dollarCount === '$$';
|
|
80
|
+
if (dollarCount === '$' && !singleDollarTextMath) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (dollarCount === '$' && isCurrencyPattern(content, src, 0)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
type: 'math',
|
|
88
|
+
isInline: true,
|
|
89
|
+
displayMode: isDisplayMode,
|
|
90
|
+
raw: match[0],
|
|
91
|
+
text: content.trim()
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
};
|
|
98
|
+
export const markedMath = createMarkedMathExtensions();
|
|
99
|
+
// Helper function to detect currency patterns
|
|
100
|
+
function isCurrencyPattern(content, fullSrc, dollarIndex) {
|
|
101
|
+
const trimmedContent = content.trim();
|
|
102
|
+
// Check for simple price patterns
|
|
103
|
+
if (currencyPatterns.simplePrice.test(trimmedContent)) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
// Check for multiple numbers/prices pattern (like "199, 199")
|
|
107
|
+
if (currencyPatterns.multipleNumbers.test(trimmedContent)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
// Check for price ranges
|
|
111
|
+
if (currencyPatterns.priceRange.test(trimmedContent)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
// Check surrounding context for currency-related words
|
|
115
|
+
const contextStart = Math.max(0, dollarIndex - 50);
|
|
116
|
+
const contextEnd = Math.min(fullSrc.length, dollarIndex + content.length + 50);
|
|
117
|
+
const context = fullSrc.substring(contextStart, contextEnd);
|
|
118
|
+
if (currencyPatterns.currencyContext.test(context)) {
|
|
119
|
+
// If currency context is found and content is purely numeric, likely currency
|
|
120
|
+
if (/^\d+(?:[.,]\d+)*$/.test(trimmedContent)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Additional check: if content is just numbers with common currency formatting
|
|
125
|
+
if (/^\d{1,3}(?:,\d{3})*(?:\.\d{1,2})?$/.test(trimmedContent)) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
|
+
import type { Token } from 'marked';
|
|
3
|
+
export type MdxToken = {
|
|
4
|
+
type: 'mdx';
|
|
5
|
+
raw: string;
|
|
6
|
+
tagName: string;
|
|
7
|
+
attributes: Record<string, any>;
|
|
8
|
+
selfClosing: boolean;
|
|
9
|
+
tokens?: Token[];
|
|
10
|
+
text?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const markedMdx: Extension;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Lexer } from 'marked';
|
|
2
|
+
const defaultLexer = new Lexer({ gfm: true });
|
|
3
|
+
const defaultTokenizer = defaultLexer.options.tokenizer;
|
|
4
|
+
/**
|
|
5
|
+
* Parse attributes from MDX component tag
|
|
6
|
+
* Supports: attribute="string", attribute={number}, attribute={boolean}, attribute={expression}
|
|
7
|
+
*/
|
|
8
|
+
function parseAttributes(attributeString) {
|
|
9
|
+
const attributes = {};
|
|
10
|
+
// Pattern: attr="value" or attr={value}
|
|
11
|
+
const attrPattern = /(\w+)=(?:"([^"]*)"|{([^}]*)})/g;
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = attrPattern.exec(attributeString)) !== null) {
|
|
14
|
+
const [, name, stringValue, expressionValue] = match;
|
|
15
|
+
if (stringValue !== undefined) {
|
|
16
|
+
// String attribute: attr="value"
|
|
17
|
+
attributes[name] = stringValue;
|
|
18
|
+
}
|
|
19
|
+
else if (expressionValue !== undefined) {
|
|
20
|
+
// Expression attribute: attr={value}
|
|
21
|
+
const trimmed = expressionValue.trim();
|
|
22
|
+
// Try to parse as number
|
|
23
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
|
|
24
|
+
attributes[name] = parseFloat(trimmed);
|
|
25
|
+
}
|
|
26
|
+
// Parse boolean
|
|
27
|
+
else if (trimmed === 'true') {
|
|
28
|
+
attributes[name] = true;
|
|
29
|
+
}
|
|
30
|
+
else if (trimmed === 'false') {
|
|
31
|
+
attributes[name] = false;
|
|
32
|
+
}
|
|
33
|
+
// Otherwise keep as string (could be variable reference, etc.)
|
|
34
|
+
else {
|
|
35
|
+
attributes[name] = trimmed;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return attributes;
|
|
40
|
+
}
|
|
41
|
+
export const markedMdx = {
|
|
42
|
+
name: 'mdx',
|
|
43
|
+
level: 'block',
|
|
44
|
+
applyInBlockParsing: true,
|
|
45
|
+
tokenizer(src) {
|
|
46
|
+
// Match MDX component tags (must start with capital letter)
|
|
47
|
+
// Self-closing: <Component attr="value" />
|
|
48
|
+
// With children: <Component attr="value">content</Component>
|
|
49
|
+
// First try self-closing tag
|
|
50
|
+
const selfClosingMatch = src.match(/^<([A-Z][a-zA-Z0-9]*)((?:\s+\w+=(?:"[^"]*"|{[^}]*}))*)\s*\/>/);
|
|
51
|
+
if (selfClosingMatch) {
|
|
52
|
+
const [raw, tagName, attributeString] = selfClosingMatch;
|
|
53
|
+
const attributes = parseAttributes(attributeString);
|
|
54
|
+
return {
|
|
55
|
+
type: 'mdx',
|
|
56
|
+
raw,
|
|
57
|
+
tagName,
|
|
58
|
+
attributes,
|
|
59
|
+
selfClosing: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Try paired tag with children
|
|
63
|
+
const openTagMatch = src.match(/^<([A-Z][a-zA-Z0-9]*)((?:\s+\w+=(?:"[^"]*"|{[^}]*}))*)\s*>/);
|
|
64
|
+
if (openTagMatch) {
|
|
65
|
+
const [openTag, tagName, attributeString] = openTagMatch;
|
|
66
|
+
const attributes = parseAttributes(attributeString);
|
|
67
|
+
// Find matching closing tag with nesting support
|
|
68
|
+
const closingTag = `</${tagName}>`;
|
|
69
|
+
// Escape special regex characters in tagName to prevent ReDoS
|
|
70
|
+
const escapedTagName = tagName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
71
|
+
const openTagPattern = new RegExp(`<${escapedTagName}(?:\\s|>)`, 'g');
|
|
72
|
+
const closeTagPattern = new RegExp(`</${escapedTagName}>`, 'g');
|
|
73
|
+
let depth = 1;
|
|
74
|
+
let searchPos = openTag.length;
|
|
75
|
+
let closingIndex = -1;
|
|
76
|
+
while (depth > 0 && searchPos < src.length) {
|
|
77
|
+
openTagPattern.lastIndex = searchPos;
|
|
78
|
+
closeTagPattern.lastIndex = searchPos;
|
|
79
|
+
const nextOpen = openTagPattern.exec(src);
|
|
80
|
+
const nextClose = closeTagPattern.exec(src);
|
|
81
|
+
if (!nextClose)
|
|
82
|
+
break;
|
|
83
|
+
if (nextOpen && nextOpen.index < nextClose.index) {
|
|
84
|
+
// Verify this is not a self-closing tag by finding the full tag and checking for />
|
|
85
|
+
const tagStart = nextOpen.index;
|
|
86
|
+
const tagEndPos = src.indexOf('>', tagStart);
|
|
87
|
+
if (tagEndPos !== -1) {
|
|
88
|
+
const fullTag = src.substring(tagStart, tagEndPos + 1);
|
|
89
|
+
const isSelfClosing = fullTag.trimEnd().endsWith('/>');
|
|
90
|
+
if (!isSelfClosing) {
|
|
91
|
+
depth++;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
searchPos = openTagPattern.lastIndex;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
depth--;
|
|
98
|
+
if (depth === 0) {
|
|
99
|
+
closingIndex = nextClose.index;
|
|
100
|
+
}
|
|
101
|
+
searchPos = closeTagPattern.lastIndex;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (closingIndex !== -1) {
|
|
105
|
+
// Extract content between tags
|
|
106
|
+
const contentStart = openTag.length;
|
|
107
|
+
const content = src.substring(contentStart, closingIndex);
|
|
108
|
+
const raw = src.substring(0, closingIndex + closingTag.length);
|
|
109
|
+
// Parse children as markdown
|
|
110
|
+
const tokens = content.trim() ? this.lexer.blockTokens(content.trim(), []) : [];
|
|
111
|
+
return {
|
|
112
|
+
type: 'mdx',
|
|
113
|
+
raw,
|
|
114
|
+
tagName,
|
|
115
|
+
attributes,
|
|
116
|
+
selfClosing: false,
|
|
117
|
+
tokens,
|
|
118
|
+
text: content
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
|
+
export declare const markedSub: Extension;
|
|
3
|
+
export declare const markedSup: Extension;
|
|
4
|
+
/**
|
|
5
|
+
* Represents a subscript token.
|
|
6
|
+
*/
|
|
7
|
+
export type SubToken = {
|
|
8
|
+
type: 'sub';
|
|
9
|
+
raw: string;
|
|
10
|
+
text: string;
|
|
11
|
+
tokens: any[];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents a superscript token.
|
|
15
|
+
*/
|
|
16
|
+
export type SupToken = {
|
|
17
|
+
type: 'sup';
|
|
18
|
+
raw: string;
|
|
19
|
+
text: string;
|
|
20
|
+
tokens: any[];
|
|
21
|
+
};
|
|
22
|
+
export type SubSupToken = SubToken | SupToken;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const subRule = /^~([^~\s](?:[^~]*[^~\s])?)~/; // ~text~
|
|
2
|
+
const supRule = /^\^([^\^\s](?:[^\^]*[^\^\s])?)\^/; // ^text^
|
|
3
|
+
export const markedSub = {
|
|
4
|
+
name: 'sub',
|
|
5
|
+
level: 'inline',
|
|
6
|
+
start(src) {
|
|
7
|
+
const i = src.indexOf('~');
|
|
8
|
+
return i === -1 ? undefined : i;
|
|
9
|
+
},
|
|
10
|
+
tokenizer(src) {
|
|
11
|
+
const match = src.match(subRule);
|
|
12
|
+
if (match) {
|
|
13
|
+
return {
|
|
14
|
+
type: 'sub',
|
|
15
|
+
raw: match[0],
|
|
16
|
+
text: match[1],
|
|
17
|
+
tokens: this.lexer.inlineTokens(match[1])
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const markedSup = {
|
|
23
|
+
name: 'sup',
|
|
24
|
+
level: 'inline',
|
|
25
|
+
start(src) {
|
|
26
|
+
const i = src.indexOf('^');
|
|
27
|
+
return i === -1 ? undefined : i;
|
|
28
|
+
},
|
|
29
|
+
tokenizer(src) {
|
|
30
|
+
const match = src.match(supRule);
|
|
31
|
+
if (match) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'sup',
|
|
34
|
+
raw: match[0],
|
|
35
|
+
text: match[1],
|
|
36
|
+
tokens: this.lexer.inlineTokens(match[1])
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|