svelte-streamdown 2.3.1 → 2.3.3
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 +108 -82
- package/dist/Block.svelte +1 -1
- package/dist/Elements/Element.svelte +36 -2
- package/dist/Elements/index.d.ts +0 -1
- package/dist/Elements/index.js +0 -1
- package/dist/Streamdown.svelte +9 -1
- package/dist/context.svelte.d.ts +12 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/marked/index.d.ts +17 -4
- package/dist/marked/index.js +22 -33
- package/dist/marked/marked-alert.d.ts +2 -8
- package/dist/marked/marked-alert.js +14 -20
- package/dist/marked/marked-br.d.ts +2 -8
- package/dist/marked/marked-br.js +15 -21
- package/dist/marked/marked-dl.d.ts +24 -0
- package/dist/marked/marked-dl.js +45 -0
- package/dist/marked/marked-footnotes.d.ts +2 -9
- package/dist/marked/marked-footnotes.js +55 -58
- package/dist/marked/marked-hr.d.ts +2 -8
- package/dist/marked/marked-hr.js +18 -24
- package/dist/marked/marked-list.d.ts +3 -9
- package/dist/marked/marked-list.js +176 -182
- package/dist/marked/marked-math.d.ts +2 -9
- package/dist/marked/marked-math.js +65 -69
- package/dist/marked/marked-subsup.d.ts +3 -9
- package/dist/marked/marked-subsup.js +38 -43
- package/dist/marked/marked-table.d.ts +2 -9
- package/dist/marked/marked-table.js +114 -123
- package/dist/theme.d.ts +36 -0
- package/dist/theme.js +25 -1
- package/package.json +1 -2
|
@@ -49,190 +49,184 @@ function finalizeList(list, lexer) {
|
|
|
49
49
|
function escapeForRegex(s) {
|
|
50
50
|
return s.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
|
|
51
51
|
}
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
52
|
+
export const markedList = {
|
|
53
|
+
name: 'list',
|
|
54
|
+
level: 'block',
|
|
55
|
+
tokenizer(src) {
|
|
56
|
+
let cap = new RegExp(rule).exec(src);
|
|
57
|
+
if (!cap)
|
|
58
|
+
return undefined;
|
|
59
|
+
const bullet = cap[1].trim();
|
|
60
|
+
const isOrdered = bullet !== '*' && bullet !== '-' && bullet !== '+';
|
|
61
|
+
let bull;
|
|
62
|
+
let type = '';
|
|
63
|
+
let expectedValue = null;
|
|
64
|
+
// Detect list type (Roman, alphabetic, numeric)
|
|
65
|
+
if (isOrdered) {
|
|
66
|
+
if (bullet.match(new RegExp(`^${romanUpper}[.)]$`))) {
|
|
67
|
+
type = 'upper-roman';
|
|
68
|
+
bull = `${romanUpper}\\${bullet.slice(-1)}`;
|
|
69
|
+
}
|
|
70
|
+
else if (bullet.match(new RegExp(`^${romanLower}[.)]$`))) {
|
|
71
|
+
type = 'lower-roman';
|
|
72
|
+
bull = `${romanLower}\\${bullet.slice(-1)}`;
|
|
73
|
+
}
|
|
74
|
+
else if (bullet.match(/^[a-z][.)]$/)) {
|
|
75
|
+
type = 'lower-alpha';
|
|
76
|
+
bull = `[a-z]\\${bullet.slice(-1)}`;
|
|
77
|
+
}
|
|
78
|
+
else if (bullet.match(/^[A-Z][.)]$/)) {
|
|
79
|
+
type = 'upper-alpha';
|
|
80
|
+
bull = `[A-Z]\\${bullet.slice(-1)}`;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
type = 'decimal';
|
|
84
|
+
bull = `\\d{1,9}\\${bullet.slice(-1)}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
bull = this.lexer.options.pedantic ? bullet : '[*+-]';
|
|
89
|
+
bull = this.lexer.options.pedantic ? escapeForRegex(bullet) : '[*+-]';
|
|
90
|
+
}
|
|
91
|
+
const list = {
|
|
92
|
+
type: 'list',
|
|
93
|
+
raw: '',
|
|
94
|
+
ordered: isOrdered,
|
|
95
|
+
listType: isOrdered ? type : null,
|
|
96
|
+
loose: false,
|
|
97
|
+
start: undefined, // Will be set when first item is processed
|
|
98
|
+
tokens: []
|
|
99
|
+
};
|
|
100
|
+
// Get next list item
|
|
101
|
+
// Updated regex to properly handle empty list items (space after bullet, then newline)
|
|
102
|
+
const itemRegex = new RegExp(`^( {0,3}${bull})([\t ][^\\n]*|[\t ])?(?:\\n|$)`);
|
|
103
|
+
let endsWithBlankLine = false;
|
|
104
|
+
// Check if current bullet point can start a new List Item
|
|
105
|
+
while (src) {
|
|
106
|
+
let raw = '';
|
|
107
|
+
let itemContents = '';
|
|
108
|
+
let endEarly = false;
|
|
109
|
+
if (!(cap = itemRegex.exec(src)))
|
|
110
|
+
break;
|
|
111
|
+
raw = cap[0];
|
|
112
|
+
const bullet = cap[1].trim();
|
|
113
|
+
src = src.substring(raw.length);
|
|
114
|
+
const line = cap[2]
|
|
115
|
+
? cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(4 * t.length))
|
|
116
|
+
: '';
|
|
117
|
+
const nextLine = src.split('\n', 1)[0];
|
|
118
|
+
const blankLine = !line.trim();
|
|
119
|
+
let indent = 0;
|
|
120
|
+
if (this.lexer.options.pedantic) {
|
|
121
|
+
indent = 2;
|
|
122
|
+
itemContents = line.trimStart();
|
|
123
|
+
}
|
|
124
|
+
else if (blankLine) {
|
|
125
|
+
indent = cap[1].length + 1;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
|
129
|
+
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
|
130
|
+
itemContents = line.slice(indent);
|
|
131
|
+
indent += cap[1].length;
|
|
132
|
+
}
|
|
133
|
+
if (blankLine && /^[ \t]*$/.test(nextLine)) {
|
|
134
|
+
// Items begin with at most one blank line
|
|
135
|
+
raw += nextLine + '\n';
|
|
136
|
+
src = src.substring(nextLine.length + 1);
|
|
137
|
+
endEarly = true;
|
|
138
|
+
}
|
|
139
|
+
if (!endEarly) {
|
|
140
|
+
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|${romanUpper}|${romanLower})[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
|
|
141
|
+
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
|
|
142
|
+
const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
|
|
143
|
+
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
|
|
144
|
+
const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<[a-z].*>`, 'i');
|
|
145
|
+
// Check if following lines should be included in List Item
|
|
146
|
+
while (src) {
|
|
147
|
+
const rawLine = src.split('\n', 1)[0];
|
|
148
|
+
const nextLineWithoutTabs = rawLine.replace(/\t/g, ' ');
|
|
149
|
+
if (fencesBeginRegex.test(nextLineWithoutTabs) ||
|
|
150
|
+
headingBeginRegex.test(nextLineWithoutTabs) ||
|
|
151
|
+
htmlBeginRegex.test(nextLineWithoutTabs) ||
|
|
152
|
+
nextBulletRegex.test(nextLineWithoutTabs) ||
|
|
153
|
+
hrRegex.test(nextLineWithoutTabs))
|
|
154
|
+
break;
|
|
155
|
+
if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLineWithoutTabs.trim()) {
|
|
156
|
+
itemContents += '\n' + nextLineWithoutTabs.slice(indent);
|
|
89
157
|
}
|
|
90
158
|
else {
|
|
91
|
-
|
|
92
|
-
bull = this.lexer.options.pedantic ? escapeForRegex(bullet) : '[*+-]';
|
|
159
|
+
itemContents += '\n' + nextLineWithoutTabs;
|
|
93
160
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
raw: '',
|
|
97
|
-
ordered: isOrdered,
|
|
98
|
-
listType: isOrdered ? type : null,
|
|
99
|
-
loose: false,
|
|
100
|
-
start: undefined, // Will be set when first item is processed
|
|
101
|
-
tokens: []
|
|
102
|
-
};
|
|
103
|
-
// Get next list item
|
|
104
|
-
// Updated regex to properly handle empty list items (space after bullet, then newline)
|
|
105
|
-
const itemRegex = new RegExp(`^( {0,3}${bull})([\t ][^\\n]*|[\t ])?(?:\\n|$)`);
|
|
106
|
-
let endsWithBlankLine = false;
|
|
107
|
-
// Check if current bullet point can start a new List Item
|
|
108
|
-
while (src) {
|
|
109
|
-
let raw = '';
|
|
110
|
-
let itemContents = '';
|
|
111
|
-
let endEarly = false;
|
|
112
|
-
if (!(cap = itemRegex.exec(src)))
|
|
113
|
-
break;
|
|
114
|
-
raw = cap[0];
|
|
115
|
-
const bullet = cap[1].trim();
|
|
116
|
-
src = src.substring(raw.length);
|
|
117
|
-
const line = cap[2]
|
|
118
|
-
? cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length))
|
|
119
|
-
: '';
|
|
120
|
-
const nextLine = src.split('\n', 1)[0];
|
|
121
|
-
const blankLine = !line.trim();
|
|
122
|
-
let indent = 0;
|
|
123
|
-
if (this.lexer.options.pedantic) {
|
|
124
|
-
indent = 2;
|
|
125
|
-
itemContents = line.trimStart();
|
|
126
|
-
}
|
|
127
|
-
else if (blankLine) {
|
|
128
|
-
indent = cap[1].length + 1;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
indent = cap[2].search(/[^ ]/); // Find first non-space char
|
|
132
|
-
indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
|
|
133
|
-
itemContents = line.slice(indent);
|
|
134
|
-
indent += cap[1].length;
|
|
135
|
-
}
|
|
136
|
-
if (blankLine && /^[ \t]*$/.test(nextLine)) {
|
|
137
|
-
// Items begin with at most one blank line
|
|
138
|
-
raw += nextLine + '\n';
|
|
139
|
-
src = src.substring(nextLine.length + 1);
|
|
140
|
-
endEarly = true;
|
|
141
|
-
}
|
|
142
|
-
if (!endEarly) {
|
|
143
|
-
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|${romanUpper}|${romanLower})[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
|
|
144
|
-
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
|
|
145
|
-
const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
|
|
146
|
-
const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
|
|
147
|
-
const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<[a-z].*>`, 'i');
|
|
148
|
-
// Check if following lines should be included in List Item
|
|
149
|
-
while (src) {
|
|
150
|
-
const rawLine = src.split('\n', 1)[0];
|
|
151
|
-
const nextLineWithoutTabs = rawLine.replace(/\t/g, ' ');
|
|
152
|
-
if (fencesBeginRegex.test(nextLineWithoutTabs) ||
|
|
153
|
-
headingBeginRegex.test(nextLineWithoutTabs) ||
|
|
154
|
-
htmlBeginRegex.test(nextLineWithoutTabs) ||
|
|
155
|
-
nextBulletRegex.test(nextLineWithoutTabs) ||
|
|
156
|
-
hrRegex.test(nextLineWithoutTabs))
|
|
157
|
-
break;
|
|
158
|
-
if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLineWithoutTabs.trim()) {
|
|
159
|
-
itemContents += '\n' + nextLineWithoutTabs.slice(indent);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
itemContents += '\n' + nextLineWithoutTabs;
|
|
163
|
-
}
|
|
164
|
-
raw += rawLine + '\n';
|
|
165
|
-
src = src.substring(rawLine.length + 1);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (!list.loose) {
|
|
169
|
-
// If the previous item ended with a blank line, the list is loose
|
|
170
|
-
if (endsWithBlankLine) {
|
|
171
|
-
list.loose = true;
|
|
172
|
-
}
|
|
173
|
-
else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
|
|
174
|
-
endsWithBlankLine = true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
let isTask = null;
|
|
178
|
-
let isChecked = false;
|
|
179
|
-
// Check for task list items
|
|
180
|
-
if (this.lexer.options.gfm) {
|
|
181
|
-
isTask = /^\[[ xX]] /.exec(itemContents);
|
|
182
|
-
if (isTask) {
|
|
183
|
-
isChecked = isTask[0] !== '[ ] ';
|
|
184
|
-
itemContents = itemContents.replace(/^\[[ xX]] +/, '');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
let value = null;
|
|
188
|
-
if (!isOrdered) {
|
|
189
|
-
// Do nothing for unordered lists
|
|
190
|
-
}
|
|
191
|
-
else if (type === 'decimal') {
|
|
192
|
-
value = parseInt(bullet.slice(0, -1), 10);
|
|
193
|
-
}
|
|
194
|
-
else if (type === 'lower-alpha' || type === 'upper-alpha') {
|
|
195
|
-
value = letterToInt(bullet.slice(0, -1));
|
|
196
|
-
}
|
|
197
|
-
else if (type === 'lower-roman' || type === 'upper-roman') {
|
|
198
|
-
value = romanToInt(bullet.slice(0, -1));
|
|
199
|
-
}
|
|
200
|
-
// Handle expectedValue initialization and validation
|
|
201
|
-
let skipped = false;
|
|
202
|
-
if (isOrdered) {
|
|
203
|
-
if (expectedValue === null) {
|
|
204
|
-
// First item: set expectedValue to this item's value (or 1 if parsing failed)
|
|
205
|
-
expectedValue = value ?? 1;
|
|
206
|
-
// Set the start property for ordered lists
|
|
207
|
-
list.start = expectedValue;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
// Subsequent items: check if value matches expected
|
|
211
|
-
skipped = value !== null && value !== expectedValue;
|
|
212
|
-
// Increment expectedValue for next item
|
|
213
|
-
expectedValue += 1;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
list.tokens.push({
|
|
217
|
-
type: 'list_item',
|
|
218
|
-
raw,
|
|
219
|
-
task: !!isTask,
|
|
220
|
-
checked: isChecked,
|
|
221
|
-
loose: false,
|
|
222
|
-
text: itemContents,
|
|
223
|
-
value,
|
|
224
|
-
skipped,
|
|
225
|
-
tokens: []
|
|
226
|
-
});
|
|
227
|
-
list.raw += raw;
|
|
228
|
-
}
|
|
229
|
-
if (list.tokens.length === 0)
|
|
230
|
-
return null;
|
|
231
|
-
// Finalize the list
|
|
232
|
-
finalizeList(list, this.lexer);
|
|
233
|
-
return list;
|
|
161
|
+
raw += rawLine + '\n';
|
|
162
|
+
src = src.substring(rawLine.length + 1);
|
|
234
163
|
}
|
|
235
164
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
165
|
+
if (!list.loose) {
|
|
166
|
+
// If the previous item ended with a blank line, the list is loose
|
|
167
|
+
if (endsWithBlankLine) {
|
|
168
|
+
list.loose = true;
|
|
169
|
+
}
|
|
170
|
+
else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
|
|
171
|
+
endsWithBlankLine = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
let isTask = null;
|
|
175
|
+
let isChecked = false;
|
|
176
|
+
// Check for task list items
|
|
177
|
+
if (this.lexer.options.gfm) {
|
|
178
|
+
isTask = /^\[[ xX]] /.exec(itemContents);
|
|
179
|
+
if (isTask) {
|
|
180
|
+
isChecked = isTask[0] !== '[ ] ';
|
|
181
|
+
itemContents = itemContents.replace(/^\[[ xX]] +/, '');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let value = null;
|
|
185
|
+
if (!isOrdered) {
|
|
186
|
+
// Do nothing for unordered lists
|
|
187
|
+
}
|
|
188
|
+
else if (type === 'decimal') {
|
|
189
|
+
value = parseInt(bullet.slice(0, -1), 10);
|
|
190
|
+
}
|
|
191
|
+
else if (type === 'lower-alpha' || type === 'upper-alpha') {
|
|
192
|
+
value = letterToInt(bullet.slice(0, -1));
|
|
193
|
+
}
|
|
194
|
+
else if (type === 'lower-roman' || type === 'upper-roman') {
|
|
195
|
+
value = romanToInt(bullet.slice(0, -1));
|
|
196
|
+
}
|
|
197
|
+
// Handle expectedValue initialization and validation
|
|
198
|
+
let skipped = false;
|
|
199
|
+
if (isOrdered) {
|
|
200
|
+
if (expectedValue === null) {
|
|
201
|
+
// First item: set expectedValue to this item's value (or 1 if parsing failed)
|
|
202
|
+
expectedValue = value ?? 1;
|
|
203
|
+
// Set the start property for ordered lists
|
|
204
|
+
list.start = expectedValue;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Subsequent items: check if value matches expected
|
|
208
|
+
skipped = value !== null && value !== expectedValue;
|
|
209
|
+
// Increment expectedValue for next item
|
|
210
|
+
expectedValue += 1;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
list.tokens.push({
|
|
214
|
+
type: 'list_item',
|
|
215
|
+
raw,
|
|
216
|
+
task: !!isTask,
|
|
217
|
+
checked: isChecked,
|
|
218
|
+
loose: false,
|
|
219
|
+
text: itemContents,
|
|
220
|
+
value,
|
|
221
|
+
skipped,
|
|
222
|
+
tokens: []
|
|
223
|
+
});
|
|
224
|
+
list.raw += raw;
|
|
225
|
+
}
|
|
226
|
+
if (list.tokens.length === 0)
|
|
227
|
+
return undefined;
|
|
228
|
+
// Finalize the list
|
|
229
|
+
finalizeList(list, this.lexer);
|
|
230
|
+
return list;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
3
|
-
extensions: Array<{
|
|
4
|
-
name: string;
|
|
5
|
-
level: 'block' | 'inline';
|
|
6
|
-
tokenizer: TokenizerExtensionFunction;
|
|
7
|
-
start?: TokenizerStartFunction;
|
|
8
|
-
}>;
|
|
9
|
-
};
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
|
+
export declare const markedMath: Extension[];
|
|
10
3
|
export type MathToken = {
|
|
11
4
|
type: 'math';
|
|
12
5
|
raw: string;
|
|
@@ -15,86 +15,82 @@ const currencyPatterns = {
|
|
|
15
15
|
// Common currency words nearby (check surrounding context)
|
|
16
16
|
currencyContext: /(?:price|cost|dollar|euro|pound|yen|currency|pay|buy|sell|expensive|cheap)/i
|
|
17
17
|
};
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
export const markedMath = [
|
|
19
|
+
{
|
|
20
|
+
name: 'math',
|
|
21
|
+
level: 'block',
|
|
22
|
+
tokenizer(src) {
|
|
23
|
+
const match = src.match(blockRule);
|
|
24
|
+
if (match) {
|
|
25
|
+
// match[2] is multiline format, match[3] is single-line format
|
|
26
|
+
const content = (match[2] || match[3]).trim();
|
|
27
|
+
return {
|
|
28
|
+
type: 'math',
|
|
29
|
+
isInline: false,
|
|
30
|
+
displayMode: true,
|
|
31
|
+
raw: match[0],
|
|
32
|
+
text: content
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'math',
|
|
39
|
+
level: 'inline',
|
|
40
|
+
start(src) {
|
|
41
|
+
let index = 0;
|
|
42
|
+
let searchSrc = src;
|
|
43
|
+
while (searchSrc) {
|
|
44
|
+
const dollarIndex = searchSrc.indexOf('$');
|
|
45
|
+
if (dollarIndex === -1) {
|
|
46
|
+
return;
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
// Check if this could be math (not currency)
|
|
53
|
-
if (possibleMath.match(inlineRule)) {
|
|
54
|
-
const match = possibleMath.match(inlineRule);
|
|
55
|
-
if (match) {
|
|
56
|
-
const content = match[2];
|
|
57
|
-
const dollarCount = match[1]; // '$' or '$$'
|
|
58
|
-
// Only apply currency detection to single dollars
|
|
59
|
-
// Double dollars ($$) indicate explicit math intent
|
|
60
|
-
if (dollarCount === '$' && isCurrencyPattern(content, src, currentIndex)) {
|
|
61
|
-
// This looks like currency with single dollars, skip it
|
|
62
|
-
index += dollarIndex + 1;
|
|
63
|
-
searchSrc = src.substring(index);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
return currentIndex;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
index += dollarIndex + 1;
|
|
70
|
-
searchSrc = src.substring(index);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
tokenizer(src) {
|
|
74
|
-
const match = src.match(inlineRule);
|
|
48
|
+
const currentIndex = index + dollarIndex;
|
|
49
|
+
const possibleMath = src.substring(currentIndex);
|
|
50
|
+
// Check if this could be math (not currency)
|
|
51
|
+
if (possibleMath.match(inlineRule)) {
|
|
52
|
+
const match = possibleMath.match(inlineRule);
|
|
75
53
|
if (match) {
|
|
76
54
|
const content = match[2];
|
|
77
55
|
const dollarCount = match[1]; // '$' or '$$'
|
|
78
|
-
const isDisplayMode = dollarCount === '$$';
|
|
79
56
|
// Only apply currency detection to single dollars
|
|
80
57
|
// Double dollars ($$) indicate explicit math intent
|
|
81
|
-
if (dollarCount === '$' && isCurrencyPattern(content, src,
|
|
58
|
+
if (dollarCount === '$' && isCurrencyPattern(content, src, currentIndex)) {
|
|
82
59
|
// This looks like currency with single dollars, skip it
|
|
83
|
-
|
|
60
|
+
index += dollarIndex + 1;
|
|
61
|
+
searchSrc = src.substring(index);
|
|
62
|
+
continue;
|
|
84
63
|
}
|
|
85
|
-
return
|
|
86
|
-
type: 'math',
|
|
87
|
-
isInline: true, // Inline tokenizer always produces inline math
|
|
88
|
-
displayMode: isDisplayMode, // $$ = display mode styling, $ = inline styling
|
|
89
|
-
raw: match[0],
|
|
90
|
-
text: content.trim()
|
|
91
|
-
};
|
|
64
|
+
return currentIndex;
|
|
92
65
|
}
|
|
93
66
|
}
|
|
67
|
+
index += dollarIndex + 1;
|
|
68
|
+
searchSrc = src.substring(index);
|
|
94
69
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
70
|
+
},
|
|
71
|
+
tokenizer(src) {
|
|
72
|
+
const match = src.match(inlineRule);
|
|
73
|
+
if (match) {
|
|
74
|
+
const content = match[2];
|
|
75
|
+
const dollarCount = match[1]; // '$' or '$$'
|
|
76
|
+
const isDisplayMode = dollarCount === '$$';
|
|
77
|
+
// Only apply currency detection to single dollars
|
|
78
|
+
// Double dollars ($$) indicate explicit math intent
|
|
79
|
+
if (dollarCount === '$' && isCurrencyPattern(content, src, 0)) {
|
|
80
|
+
// This looks like currency with single dollars, skip it
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
type: 'math',
|
|
85
|
+
isInline: true, // Inline tokenizer always produces inline math
|
|
86
|
+
displayMode: isDisplayMode, // $$ = display mode styling, $ = inline styling
|
|
87
|
+
raw: match[0],
|
|
88
|
+
text: content.trim()
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
];
|
|
98
94
|
// Helper function to detect currency patterns
|
|
99
95
|
function isCurrencyPattern(content, fullSrc, dollarIndex) {
|
|
100
96
|
const trimmedContent = content.trim();
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
level: 'inline';
|
|
6
|
-
tokenizer: TokenizerExtensionFunction;
|
|
7
|
-
start?: TokenizerStartFunction;
|
|
8
|
-
}[];
|
|
9
|
-
};
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
|
+
export declare const markedSub: Extension;
|
|
3
|
+
export declare const markedSup: Extension;
|
|
10
4
|
/**
|
|
11
5
|
* Represents a subscript token.
|
|
12
6
|
*/
|
|
@@ -1,45 +1,40 @@
|
|
|
1
1
|
const subRule = /^~([^~\s](?:[^~]*[^~\s])?)~/; // ~text~
|
|
2
2
|
const supRule = /^\^([^\^\s](?:[^\^]*[^\^\s])?)\^/; // ^text^
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
};
|
|
45
|
-
}
|
|
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
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Extension } from './index.js';
|
|
2
2
|
export interface SpanTableOptions {
|
|
3
3
|
useTheadTbody?: boolean;
|
|
4
4
|
useTfoot?: boolean;
|
|
@@ -56,12 +56,5 @@ type WorkingRow = WorkingCell[];
|
|
|
56
56
|
export declare const DEFAULT_OPTIONS: Required<SpanTableOptions>;
|
|
57
57
|
export declare const getTableCell: (text: string, cell: BaseCell, type: "th" | "td", align: string | null) => string;
|
|
58
58
|
export declare const splitCells: (tableRow: string, count: number | null, prevRow?: WorkingRow | null, maxColspan?: number | null) => WorkingRow;
|
|
59
|
-
export declare
|
|
60
|
-
extensions: {
|
|
61
|
-
name: string;
|
|
62
|
-
level: 'block' | 'inline';
|
|
63
|
-
start: TokenizerStartFunction;
|
|
64
|
-
tokenizer: TokenizerExtensionFunction;
|
|
65
|
-
}[];
|
|
66
|
-
};
|
|
59
|
+
export declare const markedTable: Extension;
|
|
67
60
|
export {};
|