stream-markdown-parser 0.0.25 → 0.0.27
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/dist/index.js +278 -203
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -250,6 +250,76 @@ function applyFixLinkInline(md) {
|
|
|
250
250
|
|
|
251
251
|
//#endregion
|
|
252
252
|
//#region src/plugins/fixLinkTokens.ts
|
|
253
|
+
function textToken(content) {
|
|
254
|
+
return {
|
|
255
|
+
type: "text",
|
|
256
|
+
content,
|
|
257
|
+
raw: content
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function pushEmOpen(arr, type) {
|
|
261
|
+
if (type === 1) arr.push({
|
|
262
|
+
type: "em_open",
|
|
263
|
+
tag: "em",
|
|
264
|
+
nesting: 1
|
|
265
|
+
});
|
|
266
|
+
else if (type === 2) arr.push({
|
|
267
|
+
type: "strong_open",
|
|
268
|
+
tag: "strong",
|
|
269
|
+
nesting: 1
|
|
270
|
+
});
|
|
271
|
+
else if (type === 3) {
|
|
272
|
+
arr.push({
|
|
273
|
+
type: "strong_open",
|
|
274
|
+
tag: "strong",
|
|
275
|
+
nesting: 1
|
|
276
|
+
});
|
|
277
|
+
arr.push({
|
|
278
|
+
type: "em_open",
|
|
279
|
+
tag: "em",
|
|
280
|
+
nesting: 1
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function pushEmClose(arr, type) {
|
|
285
|
+
if (type === 1) arr.push({
|
|
286
|
+
type: "em_close",
|
|
287
|
+
tag: "em",
|
|
288
|
+
nesting: -1
|
|
289
|
+
});
|
|
290
|
+
else if (type === 2) arr.push({
|
|
291
|
+
type: "strong_close",
|
|
292
|
+
tag: "strong",
|
|
293
|
+
nesting: -1
|
|
294
|
+
});
|
|
295
|
+
else if (type === 3) {
|
|
296
|
+
arr.push({
|
|
297
|
+
type: "em_close",
|
|
298
|
+
tag: "em",
|
|
299
|
+
nesting: -1
|
|
300
|
+
});
|
|
301
|
+
arr.push({
|
|
302
|
+
type: "strong_close",
|
|
303
|
+
tag: "strong",
|
|
304
|
+
nesting: -1
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function createLinkToken(text, href, loading) {
|
|
309
|
+
return {
|
|
310
|
+
type: "link",
|
|
311
|
+
loading,
|
|
312
|
+
href,
|
|
313
|
+
title: "",
|
|
314
|
+
text,
|
|
315
|
+
children: [{
|
|
316
|
+
type: "text",
|
|
317
|
+
content: text,
|
|
318
|
+
raw: text
|
|
319
|
+
}],
|
|
320
|
+
raw: String(`[${text}](${href})`)
|
|
321
|
+
};
|
|
322
|
+
}
|
|
253
323
|
function applyFixLinkTokens(md) {
|
|
254
324
|
md.core.ruler.after("inline", "fix_link_tokens", (state) => {
|
|
255
325
|
const toks = state.tokens ?? [];
|
|
@@ -266,7 +336,15 @@ function applyFixLinkTokens(md) {
|
|
|
266
336
|
function fixLinkToken(tokens) {
|
|
267
337
|
if (tokens.length < 4) return tokens;
|
|
268
338
|
for (let i = 0; i <= tokens.length - 1; i++) {
|
|
339
|
+
if (i < 0) i = 0;
|
|
269
340
|
if (!tokens[i]) break;
|
|
341
|
+
if (tokens[i]?.type === "em_open" && tokens[i - 1]?.type === "text" && tokens[i - 1].content?.endsWith("*")) {
|
|
342
|
+
const beforeText = tokens[i - 1].content?.replace(/(\*+)$/, "") || "";
|
|
343
|
+
tokens[i - 1].content = beforeText;
|
|
344
|
+
tokens[i].type = "strong_open";
|
|
345
|
+
tokens[i].tag = "strong";
|
|
346
|
+
tokens[i].markup = "**";
|
|
347
|
+
}
|
|
270
348
|
if (tokens[i]?.type === "text" && tokens[i].content?.endsWith("(") && tokens[i + 1]?.type === "link_open") {
|
|
271
349
|
const match = tokens[i].content.match(/\[([^\]]+)\]/);
|
|
272
350
|
if (match) {
|
|
@@ -275,116 +353,55 @@ function fixLinkToken(tokens) {
|
|
|
275
353
|
const replacerTokens = [];
|
|
276
354
|
if (emphasisMatch) {
|
|
277
355
|
beforeText = beforeText.slice(0, emphasisMatch.index);
|
|
278
|
-
if (beforeText) replacerTokens.push(
|
|
279
|
-
type: "text",
|
|
280
|
-
content: beforeText,
|
|
281
|
-
raw: beforeText
|
|
282
|
-
});
|
|
356
|
+
if (beforeText) replacerTokens.push(textToken(beforeText));
|
|
283
357
|
const text = match[1];
|
|
284
358
|
const type = emphasisMatch[1].length;
|
|
285
|
-
|
|
286
|
-
type: "em_open",
|
|
287
|
-
tag: "em",
|
|
288
|
-
nesting: 1
|
|
289
|
-
});
|
|
290
|
-
else if (type === 2) replacerTokens.push({
|
|
291
|
-
type: "strong_open",
|
|
292
|
-
tag: "strong",
|
|
293
|
-
nesting: 1
|
|
294
|
-
});
|
|
295
|
-
else if (type === 3) {
|
|
296
|
-
replacerTokens.push({
|
|
297
|
-
type: "strong_open",
|
|
298
|
-
tag: "strong",
|
|
299
|
-
nesting: 1
|
|
300
|
-
});
|
|
301
|
-
replacerTokens.push({
|
|
302
|
-
type: "em_open",
|
|
303
|
-
tag: "em",
|
|
304
|
-
nesting: 1
|
|
305
|
-
});
|
|
306
|
-
}
|
|
359
|
+
pushEmOpen(replacerTokens, type);
|
|
307
360
|
let href = tokens[i + 2]?.content || "";
|
|
308
361
|
if (tokens[i + 4]?.type === "text" && !tokens[i + 4].content?.startsWith(")")) {
|
|
309
362
|
href += tokens[i + 4]?.content || "";
|
|
310
363
|
tokens[i + 4].content = "";
|
|
311
364
|
}
|
|
312
|
-
replacerTokens.push(
|
|
313
|
-
|
|
314
|
-
loading: !tokens[i + 4]?.content?.startsWith(")"),
|
|
315
|
-
href,
|
|
316
|
-
title: "",
|
|
317
|
-
text,
|
|
318
|
-
children: [{
|
|
319
|
-
type: "text",
|
|
320
|
-
content: text,
|
|
321
|
-
raw: text
|
|
322
|
-
}],
|
|
323
|
-
raw: String(`[${text}](${href})`)
|
|
324
|
-
});
|
|
325
|
-
if (type === 1) replacerTokens.push({
|
|
326
|
-
type: "em_close",
|
|
327
|
-
tag: "em",
|
|
328
|
-
nesting: -1
|
|
329
|
-
});
|
|
330
|
-
else if (type === 2) replacerTokens.push({
|
|
331
|
-
type: "strong_close",
|
|
332
|
-
tag: "strong",
|
|
333
|
-
nesting: -1
|
|
334
|
-
});
|
|
335
|
-
else if (type === 3) {
|
|
336
|
-
replacerTokens.push({
|
|
337
|
-
type: "em_close",
|
|
338
|
-
tag: "em",
|
|
339
|
-
nesting: -1
|
|
340
|
-
});
|
|
341
|
-
replacerTokens.push({
|
|
342
|
-
type: "strong_close",
|
|
343
|
-
tag: "strong",
|
|
344
|
-
nesting: -1
|
|
345
|
-
});
|
|
346
|
-
}
|
|
365
|
+
replacerTokens.push(createLinkToken(text, href, !tokens[i + 4]?.content?.startsWith(")")));
|
|
366
|
+
pushEmClose(replacerTokens, type);
|
|
347
367
|
if (tokens[i + 4]?.type === "text") {
|
|
348
368
|
const afterText = tokens[i + 4].content?.replace(/^\)\**/, "");
|
|
349
|
-
if (afterText) replacerTokens.push(
|
|
350
|
-
type: "text",
|
|
351
|
-
content: afterText,
|
|
352
|
-
raw: afterText
|
|
353
|
-
});
|
|
369
|
+
if (afterText) replacerTokens.push(textToken(afterText));
|
|
354
370
|
tokens.splice(i, 5, ...replacerTokens);
|
|
355
371
|
} else tokens.splice(i, 4, ...replacerTokens);
|
|
356
372
|
} else {
|
|
357
|
-
if (beforeText) replacerTokens.push(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
373
|
+
if (beforeText) replacerTokens.push(textToken(beforeText));
|
|
374
|
+
let text = match[1];
|
|
375
|
+
const emphasisMatch$1 = text.match(/^\*+/);
|
|
376
|
+
if (emphasisMatch$1) {
|
|
377
|
+
const type = emphasisMatch$1[0].length;
|
|
378
|
+
text = text.replace(/^\*+/, "").replace(/\*+$/, "");
|
|
379
|
+
let href$1 = tokens[i + 2]?.content || "";
|
|
380
|
+
if (tokens[i + 4]?.type === "text" && !tokens[i + 4].content?.startsWith(")")) {
|
|
381
|
+
href$1 += tokens[i + 4]?.content || "";
|
|
382
|
+
tokens[i + 4].content = "";
|
|
383
|
+
}
|
|
384
|
+
pushEmOpen(replacerTokens, type);
|
|
385
|
+
replacerTokens.push(createLinkToken(text, href$1, !tokens[i + 4]?.content?.startsWith(")")));
|
|
386
|
+
pushEmClose(replacerTokens, type);
|
|
387
|
+
if (tokens[i + 4]?.type === "text") {
|
|
388
|
+
const afterText = tokens[i + 4].content?.replace(/^\)/, "");
|
|
389
|
+
if (afterText) replacerTokens.push(textToken(afterText));
|
|
390
|
+
tokens.splice(i, 5, ...replacerTokens);
|
|
391
|
+
} else tokens.splice(i, 4, ...replacerTokens);
|
|
392
|
+
if (i === 0) i = replacerTokens.length - 1;
|
|
393
|
+
else i -= replacerTokens.length - 1;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
363
396
|
let href = tokens[i + 2]?.content || "";
|
|
364
397
|
if (tokens[i + 4]?.type === "text" && !tokens[i + 4].content?.startsWith(")")) {
|
|
365
398
|
href += tokens[i + 4]?.content || "";
|
|
366
399
|
tokens[i + 4].content = "";
|
|
367
400
|
}
|
|
368
|
-
replacerTokens.push(
|
|
369
|
-
type: "link",
|
|
370
|
-
loading: !tokens[i + 4]?.content?.startsWith(")"),
|
|
371
|
-
href,
|
|
372
|
-
title: "",
|
|
373
|
-
text,
|
|
374
|
-
children: [{
|
|
375
|
-
type: "text",
|
|
376
|
-
content: text,
|
|
377
|
-
raw: text
|
|
378
|
-
}],
|
|
379
|
-
raw: String(`[${text}](${href})`)
|
|
380
|
-
}]);
|
|
401
|
+
replacerTokens.push(createLinkToken(text, href, !tokens[i + 4]?.content?.startsWith(")")));
|
|
381
402
|
if (tokens[i + 4]?.type === "text") {
|
|
382
403
|
const afterText = tokens[i + 4].content?.replace(/^\)/, "");
|
|
383
|
-
if (afterText) replacerTokens.push(
|
|
384
|
-
type: "text",
|
|
385
|
-
content: afterText,
|
|
386
|
-
raw: afterText
|
|
387
|
-
});
|
|
404
|
+
if (afterText) replacerTokens.push(textToken(afterText));
|
|
388
405
|
tokens.splice(i, 5, ...replacerTokens);
|
|
389
406
|
} else tokens.splice(i, 4, ...replacerTokens);
|
|
390
407
|
}
|
|
@@ -403,25 +420,9 @@ function fixLinkToken(tokens) {
|
|
|
403
420
|
href += tokens[i + 3]?.content?.slice(0, m) || "";
|
|
404
421
|
tokens[i + 3].content = "";
|
|
405
422
|
}
|
|
406
|
-
replacerTokens.push(
|
|
407
|
-
type: "link",
|
|
408
|
-
loading,
|
|
409
|
-
href,
|
|
410
|
-
title: "",
|
|
411
|
-
text,
|
|
412
|
-
children: [{
|
|
413
|
-
type: "text",
|
|
414
|
-
content: text,
|
|
415
|
-
raw: text
|
|
416
|
-
}],
|
|
417
|
-
raw: String(`[${text}](${href})`)
|
|
418
|
-
});
|
|
423
|
+
replacerTokens.push(createLinkToken(text, href, loading));
|
|
419
424
|
const afterText = tokens[i + 3].content?.replace(/^\)\**/, "");
|
|
420
|
-
if (afterText) replacerTokens.push(
|
|
421
|
-
type: "text",
|
|
422
|
-
content: afterText,
|
|
423
|
-
raw: afterText
|
|
424
|
-
});
|
|
425
|
+
if (afterText) replacerTokens.push(textToken(afterText));
|
|
425
426
|
tokens.splice(i - 4, 8, ...replacerTokens);
|
|
426
427
|
} else {
|
|
427
428
|
replacerTokens.push({
|
|
@@ -440,24 +441,67 @@ function fixLinkToken(tokens) {
|
|
|
440
441
|
tokens.splice(i - 4, 7, ...replacerTokens);
|
|
441
442
|
}
|
|
442
443
|
continue;
|
|
444
|
+
} else if (tokens[i - 1].content === "](" && tokens[i - 3]?.type === "text" && tokens[i - 3].content?.endsWith(")")) if (tokens[i - 2]?.type === "strong_open") {
|
|
445
|
+
const [beforeText, linText] = tokens[i - 3].content?.split("[**") || [];
|
|
446
|
+
tokens[i + 1].content = linText || "";
|
|
447
|
+
tokens[i - 3].content = beforeText || "";
|
|
448
|
+
tokens[i - 1].content = "";
|
|
449
|
+
} else if (tokens[i - 2]?.type === "em_open") {
|
|
450
|
+
const [beforeText, linText] = tokens[i - 3].content?.split("[*") || [];
|
|
451
|
+
tokens[i + 1].content = linText || "";
|
|
452
|
+
tokens[i - 3].content = beforeText || "";
|
|
453
|
+
tokens[i - 1].content = "";
|
|
454
|
+
} else {
|
|
455
|
+
const [beforeText, linText] = tokens[i - 3].content?.split("[") || [];
|
|
456
|
+
tokens[i + 1].content = linText || "";
|
|
457
|
+
tokens[i - 3].content = beforeText || "";
|
|
458
|
+
tokens[i - 1].content = "";
|
|
443
459
|
}
|
|
444
460
|
}
|
|
445
|
-
if (tokens[i].type === "link_close" && tokens[i].nesting === -1 && tokens[i + 1]?.type === "text" && tokens[i - 1]?.type === "text"
|
|
446
|
-
|
|
461
|
+
if (tokens[i].type === "link_close" && tokens[i].nesting === -1 && tokens[i + 1]?.type === "text" && tokens[i - 1]?.type === "text") {
|
|
462
|
+
let loading = true;
|
|
447
463
|
const text = tokens[i - 1].content || "";
|
|
448
464
|
let href = tokens[i - 2].attrs?.[0]?.[1] || "";
|
|
449
465
|
let count = 3;
|
|
466
|
+
let deleteCount = 2;
|
|
467
|
+
const emphasisMatch = (tokens[i - 3]?.content || "").match(/^(\*+)$/);
|
|
468
|
+
const replacerTokens = [];
|
|
469
|
+
if (emphasisMatch) {
|
|
470
|
+
deleteCount += 1;
|
|
471
|
+
const type = emphasisMatch[1].length;
|
|
472
|
+
pushEmOpen(replacerTokens, type);
|
|
473
|
+
}
|
|
474
|
+
if (tokens[i].markup === "" || tokens[i + 1].type === "text" && (tokens[i + 1].content === "." || tokens[i + 1].content === "?")) loading = false;
|
|
450
475
|
if (tokens[i].markup === "linkify" && tokens[i + 1]?.type === "text" && !tokens[i + 1]?.content?.startsWith(" ")) {
|
|
451
476
|
const m = (tokens[i + 1]?.content ?? "").indexOf(")");
|
|
452
477
|
if (m === -1) {
|
|
453
478
|
href += tokens[i + 1]?.content?.slice(0, m) || "";
|
|
454
479
|
tokens[i + 1].content = "";
|
|
455
|
-
}
|
|
480
|
+
} else loading = false;
|
|
481
|
+
count += 1;
|
|
482
|
+
} else if (tokens[i + 1].type === "text" && tokens[i + 1]?.content?.startsWith("](")) {
|
|
456
483
|
count += 1;
|
|
484
|
+
for (let j = i + 1; j < tokens.length; j++) {
|
|
485
|
+
const type = emphasisMatch ? emphasisMatch[1].length : tokens[i - 3].markup.length;
|
|
486
|
+
const t = tokens[j];
|
|
487
|
+
if (type === 1 && t.type === "em_close") {
|
|
488
|
+
loading = false;
|
|
489
|
+
break;
|
|
490
|
+
} else if (type === 2 && t.type === "strong_close") {
|
|
491
|
+
loading = false;
|
|
492
|
+
break;
|
|
493
|
+
} else if (type === 3) {
|
|
494
|
+
if (t.type === "em_close" || t.type === "strong_close") {
|
|
495
|
+
loading = false;
|
|
496
|
+
break;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
count += 1;
|
|
500
|
+
}
|
|
457
501
|
}
|
|
458
|
-
|
|
502
|
+
replacerTokens.push({
|
|
459
503
|
type: "link",
|
|
460
|
-
loading
|
|
504
|
+
loading,
|
|
461
505
|
href,
|
|
462
506
|
title: "",
|
|
463
507
|
text,
|
|
@@ -468,37 +512,19 @@ function fixLinkToken(tokens) {
|
|
|
468
512
|
}],
|
|
469
513
|
raw: String(`[${text}](${href})`)
|
|
470
514
|
});
|
|
471
|
-
|
|
515
|
+
if (emphasisMatch) {
|
|
516
|
+
const type = emphasisMatch[1].length;
|
|
517
|
+
pushEmClose(replacerTokens, type);
|
|
518
|
+
}
|
|
519
|
+
tokens.splice(i - deleteCount, count, ...replacerTokens);
|
|
520
|
+
i -= replacerTokens.length - 1;
|
|
521
|
+
continue;
|
|
522
|
+
} else if (tokens[i].content?.startsWith("](") && tokens[i - 1].markup?.includes("*") && tokens[i - 4]?.type === "text" && tokens[i - 4].content?.endsWith("[")) {
|
|
472
523
|
const type = tokens[i - 1].markup.length;
|
|
473
524
|
const replacerTokens = [];
|
|
474
|
-
const beforeText = tokens[i - 4].content.slice(0, tokens[i - 4].content.length -
|
|
475
|
-
if (beforeText) replacerTokens.push(
|
|
476
|
-
|
|
477
|
-
content: beforeText,
|
|
478
|
-
raw: beforeText
|
|
479
|
-
});
|
|
480
|
-
if (type === 1) replacerTokens.push({
|
|
481
|
-
type: "em_open",
|
|
482
|
-
tag: "em",
|
|
483
|
-
nesting: 1
|
|
484
|
-
});
|
|
485
|
-
else if (type === 2) replacerTokens.push({
|
|
486
|
-
type: "strong_open",
|
|
487
|
-
tag: "strong",
|
|
488
|
-
nesting: 1
|
|
489
|
-
});
|
|
490
|
-
else if (type === 3) {
|
|
491
|
-
replacerTokens.push({
|
|
492
|
-
type: "strong_open",
|
|
493
|
-
tag: "strong",
|
|
494
|
-
nesting: 1
|
|
495
|
-
});
|
|
496
|
-
replacerTokens.push({
|
|
497
|
-
type: "em_open",
|
|
498
|
-
tag: "em",
|
|
499
|
-
nesting: 1
|
|
500
|
-
});
|
|
501
|
-
}
|
|
525
|
+
const beforeText = tokens[i - 4].content.slice(0, tokens[i - 4].content.length - type);
|
|
526
|
+
if (beforeText) replacerTokens.push(textToken(beforeText));
|
|
527
|
+
pushEmOpen(replacerTokens, type);
|
|
502
528
|
const text = tokens[i - 2].content || "";
|
|
503
529
|
let href = tokens[i].content.slice(2);
|
|
504
530
|
let loading = true;
|
|
@@ -510,48 +536,11 @@ function fixLinkToken(tokens) {
|
|
|
510
536
|
tokens[i + 1].content = "";
|
|
511
537
|
}
|
|
512
538
|
}
|
|
513
|
-
replacerTokens.push(
|
|
514
|
-
|
|
515
|
-
loading,
|
|
516
|
-
href,
|
|
517
|
-
title: "",
|
|
518
|
-
text,
|
|
519
|
-
children: [{
|
|
520
|
-
type: "text",
|
|
521
|
-
content: text,
|
|
522
|
-
raw: text
|
|
523
|
-
}],
|
|
524
|
-
raw: String(`[${text}](${href})`)
|
|
525
|
-
});
|
|
526
|
-
if (type === 1) replacerTokens.push({
|
|
527
|
-
type: "em_close",
|
|
528
|
-
tag: "em",
|
|
529
|
-
nesting: -1
|
|
530
|
-
});
|
|
531
|
-
else if (type === 2) replacerTokens.push({
|
|
532
|
-
type: "strong_close",
|
|
533
|
-
tag: "strong",
|
|
534
|
-
nesting: -1
|
|
535
|
-
});
|
|
536
|
-
else if (type === 3) {
|
|
537
|
-
replacerTokens.push({
|
|
538
|
-
type: "em_close",
|
|
539
|
-
tag: "em",
|
|
540
|
-
nesting: -1
|
|
541
|
-
});
|
|
542
|
-
replacerTokens.push({
|
|
543
|
-
type: "strong_close",
|
|
544
|
-
tag: "strong",
|
|
545
|
-
nesting: -1
|
|
546
|
-
});
|
|
547
|
-
}
|
|
539
|
+
replacerTokens.push(createLinkToken(text, href, loading));
|
|
540
|
+
pushEmClose(replacerTokens, type);
|
|
548
541
|
if (tokens[i + 1]?.type === "text") {
|
|
549
542
|
const afterText = tokens[i + 1].content?.replace(/^\)\**/, "");
|
|
550
|
-
if (afterText) replacerTokens.push(
|
|
551
|
-
type: "text",
|
|
552
|
-
content: afterText,
|
|
553
|
-
raw: afterText
|
|
554
|
-
});
|
|
543
|
+
if (afterText) replacerTokens.push(textToken(afterText));
|
|
555
544
|
tokens.splice(i - 4, 8, ...replacerTokens);
|
|
556
545
|
} else if (tokens[i + 1]?.type === "link_open") tokens.splice(i - 4, 10, ...replacerTokens);
|
|
557
546
|
else tokens.splice(i - 4, 7, ...replacerTokens);
|
|
@@ -1062,7 +1051,7 @@ function applyMath(md, mathOpts) {
|
|
|
1062
1051
|
const s = state;
|
|
1063
1052
|
if (/^\*[^*]+/.test(s.src)) return false;
|
|
1064
1053
|
const delimiters = [
|
|
1065
|
-
["
|
|
1054
|
+
["$", "$"],
|
|
1066
1055
|
["\\(", "\\)"],
|
|
1067
1056
|
["(", ")"]
|
|
1068
1057
|
];
|
|
@@ -1167,8 +1156,8 @@ function applyMath(md, mathOpts) {
|
|
|
1167
1156
|
pushText(toPushBefore.slice(0, _match.index));
|
|
1168
1157
|
const strongToken = s.push("strong_open", "", 0);
|
|
1169
1158
|
strongToken.markup = _match[0];
|
|
1170
|
-
const textToken = s.push("text", "", 0);
|
|
1171
|
-
textToken.content = after;
|
|
1159
|
+
const textToken$1 = s.push("text", "", 0);
|
|
1160
|
+
textToken$1.content = after;
|
|
1172
1161
|
s.push("strong_close", "", 0);
|
|
1173
1162
|
} else pushText(toPushBefore);
|
|
1174
1163
|
}
|
|
@@ -1226,21 +1215,33 @@ function applyMath(md, mathOpts) {
|
|
|
1226
1215
|
let matched = false;
|
|
1227
1216
|
let openDelim = "";
|
|
1228
1217
|
let closeDelim = "";
|
|
1229
|
-
for (const [open, close] of delimiters)
|
|
1230
|
-
|
|
1231
|
-
|
|
1218
|
+
for (const [open, close] of delimiters) {
|
|
1219
|
+
const m = lineText.indexOf(open);
|
|
1220
|
+
if (m !== -1) {
|
|
1221
|
+
const beforeText = lineText.slice(0, m);
|
|
1222
|
+
if (beforeText) {
|
|
1223
|
+
const inline = s.push("inline", "", 0);
|
|
1224
|
+
inline.content = beforeText;
|
|
1225
|
+
inline.map = [startLine, startLine];
|
|
1226
|
+
inline.children = [];
|
|
1227
|
+
}
|
|
1228
|
+
if (open.includes("[")) {
|
|
1229
|
+
if (lineText.replace("\\", "") === "[") {
|
|
1230
|
+
if (startLine + 1 < endLine) {
|
|
1231
|
+
matched = true;
|
|
1232
|
+
openDelim = open;
|
|
1233
|
+
closeDelim = close;
|
|
1234
|
+
break;
|
|
1235
|
+
}
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
} else {
|
|
1232
1239
|
matched = true;
|
|
1233
1240
|
openDelim = open;
|
|
1234
1241
|
closeDelim = close;
|
|
1235
1242
|
break;
|
|
1236
1243
|
}
|
|
1237
|
-
continue;
|
|
1238
1244
|
}
|
|
1239
|
-
} else {
|
|
1240
|
-
matched = true;
|
|
1241
|
-
openDelim = open;
|
|
1242
|
-
closeDelim = close;
|
|
1243
|
-
break;
|
|
1244
1245
|
}
|
|
1245
1246
|
if (!matched) return false;
|
|
1246
1247
|
if (silent) return true;
|
|
@@ -1390,7 +1391,7 @@ function parseEmphasisToken(tokens, startIndex) {
|
|
|
1390
1391
|
let i = startIndex + 1;
|
|
1391
1392
|
const innerTokens = [];
|
|
1392
1393
|
while (i < tokens.length && tokens[i].type !== "em_close") {
|
|
1393
|
-
emText += String(tokens[i].content ?? "");
|
|
1394
|
+
emText += String(tokens[i].content ?? tokens[i]?.text ?? "");
|
|
1394
1395
|
innerTokens.push(tokens[i]);
|
|
1395
1396
|
i++;
|
|
1396
1397
|
}
|
|
@@ -2237,18 +2238,18 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2237
2238
|
if (!nextToken && /[^\]]\s*\(\s*$/.test(content)) content = content.replace(/\(\s*$/, "");
|
|
2238
2239
|
if (handleCheckboxLike(content)) return;
|
|
2239
2240
|
const preToken = tokens[i - 1];
|
|
2240
|
-
if (content === "[" && !nextToken?.markup?.includes("*") || content === "]" && !preToken
|
|
2241
|
+
if (content === "[" && !nextToken?.markup?.includes("*") || content === "]" && !preToken?.markup?.includes("*")) {
|
|
2241
2242
|
i++;
|
|
2242
2243
|
return;
|
|
2243
2244
|
}
|
|
2244
2245
|
if (handleInlineCodeContent(content, token)) return;
|
|
2245
|
-
if (handleEmphasisAndStrikethrough(content, token)) return;
|
|
2246
2246
|
if (handleInlineImageContent(content, token)) return;
|
|
2247
|
+
if (handleInlineLinkContent(content, token)) return;
|
|
2248
|
+
if (handleEmphasisAndStrikethrough(content, token)) return;
|
|
2247
2249
|
const textNode = parseTextToken({
|
|
2248
2250
|
...token,
|
|
2249
2251
|
content
|
|
2250
2252
|
});
|
|
2251
|
-
if (handleInlineLinkContent(content, token)) return;
|
|
2252
2253
|
if (currentTextNode) {
|
|
2253
2254
|
currentTextNode.content += textNode.content.replace(/(\*+|\(|\\)$/, "");
|
|
2254
2255
|
currentTextNode.raw += textNode.raw;
|
|
@@ -2360,7 +2361,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2360
2361
|
let textNodeContent = content.slice(0, linkStart);
|
|
2361
2362
|
const linkEnd = content.indexOf("](", linkStart);
|
|
2362
2363
|
if (linkEnd !== -1) {
|
|
2363
|
-
const textToken = tokens[i + 2];
|
|
2364
|
+
const textToken$1 = tokens[i + 2];
|
|
2364
2365
|
let text = content.slice(linkStart + 1, linkEnd);
|
|
2365
2366
|
if (text.includes("[")) {
|
|
2366
2367
|
const secondLinkStart = text.indexOf("[");
|
|
@@ -2369,7 +2370,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2369
2370
|
text = content.slice(newLinkStart + 1, linkEnd);
|
|
2370
2371
|
}
|
|
2371
2372
|
const nextToken = tokens[i + 1];
|
|
2372
|
-
if (content.endsWith("](") && nextToken?.type === "link_open" && textToken) {
|
|
2373
|
+
if (content.endsWith("](") && nextToken?.type === "link_open" && textToken$1) {
|
|
2373
2374
|
const last = tokens[i + 4];
|
|
2374
2375
|
let index = 4;
|
|
2375
2376
|
let loading$1 = true;
|
|
@@ -2380,7 +2381,7 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2380
2381
|
if (textNodeContent) pushText(textNodeContent, textNodeContent);
|
|
2381
2382
|
pushParsed({
|
|
2382
2383
|
type: "link",
|
|
2383
|
-
href: String(textToken.content ?? ""),
|
|
2384
|
+
href: String(textToken$1.content ?? ""),
|
|
2384
2385
|
title: null,
|
|
2385
2386
|
text,
|
|
2386
2387
|
children: [{
|
|
@@ -2396,8 +2397,82 @@ function parseInlineTokens(tokens, raw, pPreToken) {
|
|
|
2396
2397
|
const linkContentEnd = content.indexOf(")", linkEnd);
|
|
2397
2398
|
const href = linkContentEnd !== -1 ? content.slice(linkEnd + 2, linkContentEnd) : "";
|
|
2398
2399
|
const loading = linkContentEnd === -1;
|
|
2400
|
+
let emphasisMatch = textNodeContent.match(/\*+$/);
|
|
2401
|
+
if (emphasisMatch) textNodeContent = textNodeContent.replace(/\*+$/, "");
|
|
2399
2402
|
if (textNodeContent) pushText(textNodeContent, textNodeContent);
|
|
2400
|
-
|
|
2403
|
+
if (!emphasisMatch) emphasisMatch = text.match(/^\*+/);
|
|
2404
|
+
if (emphasisMatch) {
|
|
2405
|
+
const type = emphasisMatch[0].length;
|
|
2406
|
+
text = text.replace(/^\*+/, "").replace(/\*+$/, "");
|
|
2407
|
+
const newTokens = [];
|
|
2408
|
+
if (type === 1) newTokens.push({
|
|
2409
|
+
type: "em_open",
|
|
2410
|
+
tag: "em",
|
|
2411
|
+
nesting: 1
|
|
2412
|
+
});
|
|
2413
|
+
else if (type === 2) newTokens.push({
|
|
2414
|
+
type: "strong_open",
|
|
2415
|
+
tag: "strong",
|
|
2416
|
+
nesting: 1
|
|
2417
|
+
});
|
|
2418
|
+
else if (type === 3) {
|
|
2419
|
+
newTokens.push({
|
|
2420
|
+
type: "strong_open",
|
|
2421
|
+
tag: "strong",
|
|
2422
|
+
nesting: 1
|
|
2423
|
+
});
|
|
2424
|
+
newTokens.push({
|
|
2425
|
+
type: "em_open",
|
|
2426
|
+
tag: "em",
|
|
2427
|
+
nesting: 1
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
newTokens.push({
|
|
2431
|
+
type: "link",
|
|
2432
|
+
href,
|
|
2433
|
+
title: null,
|
|
2434
|
+
text,
|
|
2435
|
+
children: [{
|
|
2436
|
+
type: "text",
|
|
2437
|
+
content: text,
|
|
2438
|
+
raw: text
|
|
2439
|
+
}],
|
|
2440
|
+
loading
|
|
2441
|
+
});
|
|
2442
|
+
if (type === 1) {
|
|
2443
|
+
newTokens.push({
|
|
2444
|
+
type: "em_close",
|
|
2445
|
+
tag: "em",
|
|
2446
|
+
nesting: -1
|
|
2447
|
+
});
|
|
2448
|
+
const { node } = parseEmphasisToken(newTokens, 0);
|
|
2449
|
+
pushNode(node);
|
|
2450
|
+
} else if (type === 2) {
|
|
2451
|
+
newTokens.push({
|
|
2452
|
+
type: "strong_close",
|
|
2453
|
+
tag: "strong",
|
|
2454
|
+
nesting: -1
|
|
2455
|
+
});
|
|
2456
|
+
const { node } = parseStrongToken(newTokens, 0);
|
|
2457
|
+
pushNode(node);
|
|
2458
|
+
} else if (type === 3) {
|
|
2459
|
+
newTokens.push({
|
|
2460
|
+
type: "em_close",
|
|
2461
|
+
tag: "em",
|
|
2462
|
+
nesting: -1
|
|
2463
|
+
});
|
|
2464
|
+
newTokens.push({
|
|
2465
|
+
type: "strong_close",
|
|
2466
|
+
tag: "strong",
|
|
2467
|
+
nesting: -1
|
|
2468
|
+
});
|
|
2469
|
+
const { node } = parseStrongToken(newTokens, 0);
|
|
2470
|
+
pushNode(node);
|
|
2471
|
+
} else {
|
|
2472
|
+
const { node } = parseEmphasisToken(newTokens, 0);
|
|
2473
|
+
pushNode(node);
|
|
2474
|
+
}
|
|
2475
|
+
} else pushParsed({
|
|
2401
2476
|
type: "link",
|
|
2402
2477
|
href,
|
|
2403
2478
|
title: null,
|