vue-stream-markdown 0.2.2 → 0.3.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 +5 -1
- package/dist/{blockquote-CVFraiyL.js → blockquote-DTo6zg12.js} +6 -2
- package/dist/{break-CzrM3nW0.js → break-DoDPjOA0.js} +4 -0
- package/dist/button-1EHxh8s2.js +6 -0
- package/dist/{button-CWSGNZmd.js → button-B7H9jKmU.js} +2 -2
- package/dist/{code-DwwmPoup.js → code-DC7KVCvB.js} +14 -10
- package/dist/{code-block-XfHjZodV.js → code-block-DPC1FZT3.js} +26 -13
- package/dist/code-block-DYrPMONb.js +10 -0
- package/dist/{composables-BMXMKLLj.js → composables-BvaSMf02.js} +17 -2
- package/dist/{delete-BRwEUU72.js → delete-xkkM7TML.js} +6 -2
- package/dist/dropdown-Cv_yW4GS.js +6 -0
- package/dist/{emphasis-DblyP-Vp.js → emphasis-BmM30dZi.js} +6 -2
- package/dist/error-component-1U-JNS6o.js +5 -0
- package/dist/{error-component-CckClFee.js → error-component-DFBWdaYB.js} +2 -2
- package/dist/{footnote-definition-BvZNKSLa.js → footnote-definition-6cTbdg-J.js} +9 -5
- package/dist/{footnote-reference-DvAxMjRZ.js → footnote-reference-CxJUg8wT.js} +5 -1
- package/dist/{heading-g87txbB0.js → heading-DQ4lofbm.js} +6 -2
- package/dist/{html-BG83dEZJ.js → html-Be_6ezK6.js} +4 -0
- package/dist/{html-D7bGx0Cz.js → html-DfTs9nEm.js} +4 -0
- package/dist/{icon-CpKYt1dR.js → icon-BJa4ovUe.js} +1 -1
- package/dist/icon-CvIgAOPh.js +4 -0
- package/dist/{image-Dwe5A7RP.js → image-DXu2WF2r.js} +13 -10
- package/dist/image-Dm5xIWs7.js +9 -0
- package/dist/{image-CR28eDok.js → image-e0E51Nc3.js} +21 -12
- package/dist/index.css +130 -144
- package/dist/index.d.ts +211 -148
- package/dist/index.js +452 -247
- package/dist/{inline-code-E5uGvmnx.js → inline-code-B5lfHACE.js} +4 -0
- package/dist/{inline-math-BHDNxQ5R.js → inline-math-BuO_dWPX.js} +7 -3
- package/dist/{link-BiA46FMM.js → link-DyD59DzG.js} +8 -4
- package/dist/{list-D7QyoGUy.js → list-De0KPajx.js} +6 -2
- package/dist/{list-item-Cv8l3Ufd.js → list-item-CuUgvXRC.js} +6 -2
- package/dist/{math-BzuYH4PG.js → math-DnFOOLdz.js} +7 -3
- package/dist/{mermaid-BoiSJ4fF.js → mermaid-ZCQPlRUa.js} +22 -8
- package/dist/modal-B5jFKJL4.js +4 -0
- package/dist/{modal-DHGxvCt5.js → modal-Bhe0iSs6.js} +8 -5
- package/dist/{node-list-D6zJX92N.js → node-list-CWy--Gin.js} +7 -78
- package/dist/node-list-Doh9Z-4p.js +4 -0
- package/dist/{paragraph-YTqe84Bm.js → paragraph-D3H1qprZ.js} +6 -2
- package/dist/previewers-DB2HHDGb.js +10 -0
- package/dist/{segmented-DDQZGL7l.js → segmented-B-kjIOkd.js} +1 -1
- package/dist/segmented-fbmq_xK1.js +7 -0
- package/dist/{shiki-DDfRFzy0.js → shiki-DAu2_FTG.js} +7 -3
- package/dist/{strong-nPwCJEKq.js → strong-BlCQoXCR.js} +6 -2
- package/dist/{table-Dtpd-MnT.js → table-Co_MpK6m.js} +17 -8
- package/dist/{text-CfRWiRE0.js → text-DbHMEN3P.js} +4 -0
- package/dist/{thematic-break-DgOD2KmY.js → thematic-break-CdlhHAEZ.js} +4 -0
- package/dist/theme.css +2 -2
- package/dist/tooltip-70WIAMmC.js +4 -0
- package/dist/{tooltip-C4RiUZwy.js → tooltip-CWv9skVu.js} +3 -2
- package/dist/{vanilla-NR7MOE5P.js → vanilla-D30b-_ch.js} +1 -1
- package/dist/vanilla-DV7fYrnj.js +4 -0
- package/dist/{yaml-DP0yfJyS.js → yaml-DL5ozHZ_.js} +4 -0
- package/dist/{zoom-container-CqZQ4X6w.js → zoom-container-DbeN8U39.js} +33 -9
- package/dist/zoom-container-Dc8N-wuo.js +7 -0
- package/package.json +4 -5
- package/dist/button-BFS-gHGF.js +0 -6
- package/dist/code-block-CTM9VEwA.js +0 -10
- package/dist/dropdown-BQ3uynLf.js +0 -6
- package/dist/error-component-B_Vacrqa.js +0 -5
- package/dist/icon-BX3KKloR.js +0 -4
- package/dist/image-BtkXhzG1.js +0 -9
- package/dist/modal-CFOdkYNj.js +0 -4
- package/dist/node-list-BYDvt6bq.js +0 -4
- package/dist/previewers-Cpx1Wqu8.js +0 -10
- package/dist/segmented-CaVb5_Rp.js +0 -7
- package/dist/tooltip-BIvCaFUj.js +0 -4
- package/dist/vanilla-DfHiHWnr.js +0 -4
- package/dist/zoom-container-DtkZ07v1.js +0 -7
package/dist/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { t as CODE_PREVIEWERS } from "./previewers-
|
|
2
|
-
import { A as tableDataToMarkdown, B as flow, C as loadLocaleMessages, D as escapeMarkdownTableCell, E as useFloating, F as hasKatex, G as useControls, H as saveImage, I as hasMermaid, K as useContext, L as hasShiki, M as preloadAsyncComponents, N as findLastLeafNode, O as extractTableDataFromElement, P as findNodeParent, R as isClient, S as currentLocale, T as localesGlob, U as svgToPngBlob, V as save, W as transformUrl, a as SHADCN_SCHEMAS, b as useI18n, c as DEFAULT_HARDEN_OPTIONS, d as LANGUAGE_ALIAS, f as LANGUAGE_EXTENSIONS, g as useMathRenderer, h as useMediumZoom, i as useSanitizers, j as tableDataToTSV, k as tableDataToCSV, l as DEFAULT_DARK_THEME, m as useMermaid, n as useTailwindV3Theme, o as PRELOAD_NODE_RENDERER, p as LANGUAGE_ICONS, q as useCodeOptions, r as useShiki, s as ICONS, t as useZoom, u as DEFAULT_LIGHT_THEME, v as _defineProperty, w as localeMessages, x as SUPPORT_LANGUAGES, y as useKatex, z as isServer } from "./composables-
|
|
3
|
-
import { t as node_list_default } from "./node-list-
|
|
1
|
+
import { t as CODE_PREVIEWERS } from "./previewers-DB2HHDGb.js";
|
|
2
|
+
import { A as tableDataToMarkdown, B as flow, C as loadLocaleMessages, D as escapeMarkdownTableCell, E as useFloating, F as hasKatex, G as useControls, H as saveImage, I as hasMermaid, K as useContext, L as hasShiki, M as preloadAsyncComponents, N as findLastLeafNode, O as extractTableDataFromElement, P as findNodeParent, R as isClient, S as currentLocale, T as localesGlob, U as svgToPngBlob, V as save, W as transformUrl, a as SHADCN_SCHEMAS, b as useI18n, c as DEFAULT_HARDEN_OPTIONS, d as LANGUAGE_ALIAS, f as LANGUAGE_EXTENSIONS, g as useMathRenderer, h as useMediumZoom, i as useSanitizers, j as tableDataToTSV, k as tableDataToCSV, l as DEFAULT_DARK_THEME, m as useMermaid, n as useTailwindV3Theme, o as PRELOAD_NODE_RENDERER, p as LANGUAGE_ICONS, q as useCodeOptions, r as useShiki, s as ICONS, t as useZoom, u as DEFAULT_LIGHT_THEME, v as _defineProperty, w as localeMessages, x as SUPPORT_LANGUAGES, y as useKatex, z as isServer } from "./composables-BvaSMf02.js";
|
|
3
|
+
import { t as node_list_default } from "./node-list-CWy--Gin.js";
|
|
4
4
|
import { n as treeFlatFilter, t as treeFilter } from "./dist-CYkm26BF.js";
|
|
5
5
|
import { computed, createElementBlock, createVNode, defineAsyncComponent, defineComponent, mergeProps, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, toRefs, unref, watch } from "vue";
|
|
6
|
-
import { MarkdownItAsync } from "markdown-it-async";
|
|
7
|
-
import remend from "remend";
|
|
8
6
|
|
|
9
7
|
//#region rolldown:runtime
|
|
10
8
|
var __create = Object.create;
|
|
@@ -49,46 +47,46 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
49
47
|
//#endregion
|
|
50
48
|
//#region src/components/renderers/index.ts
|
|
51
49
|
const NODE_RENDERERS = {
|
|
52
|
-
blockquote: defineAsyncComponent(() => import("./blockquote-
|
|
53
|
-
break: defineAsyncComponent(() => import("./break-
|
|
54
|
-
code: defineAsyncComponent(() => import("./code-
|
|
55
|
-
delete: defineAsyncComponent(() => import("./delete-
|
|
56
|
-
emphasis: defineAsyncComponent(() => import("./emphasis-
|
|
57
|
-
footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-
|
|
58
|
-
footnoteReference: defineAsyncComponent(() => import("./footnote-reference-
|
|
59
|
-
heading: defineAsyncComponent(() => import("./heading-
|
|
60
|
-
html: defineAsyncComponent(() => import("./html-
|
|
61
|
-
image: defineAsyncComponent(() => import("./image-
|
|
62
|
-
inlineCode: defineAsyncComponent(() => import("./inline-code-
|
|
63
|
-
inlineMath: defineAsyncComponent(() => import("./inline-math-
|
|
64
|
-
link: defineAsyncComponent(() => import("./link-
|
|
65
|
-
list: defineAsyncComponent(() => import("./list-
|
|
66
|
-
listItem: defineAsyncComponent(() => import("./list-item-
|
|
67
|
-
math: defineAsyncComponent(() => import("./math-
|
|
68
|
-
paragraph: defineAsyncComponent(() => import("./paragraph-
|
|
69
|
-
strong: defineAsyncComponent(() => import("./strong-
|
|
70
|
-
table: defineAsyncComponent(() => import("./table-
|
|
71
|
-
text: defineAsyncComponent(() => import("./text-
|
|
72
|
-
thematicBreak: defineAsyncComponent(() => import("./thematic-break-
|
|
73
|
-
yaml: defineAsyncComponent(() => import("./yaml-
|
|
50
|
+
blockquote: defineAsyncComponent(() => import("./blockquote-DTo6zg12.js")),
|
|
51
|
+
break: defineAsyncComponent(() => import("./break-DoDPjOA0.js")),
|
|
52
|
+
code: defineAsyncComponent(() => import("./code-DC7KVCvB.js")),
|
|
53
|
+
delete: defineAsyncComponent(() => import("./delete-xkkM7TML.js")),
|
|
54
|
+
emphasis: defineAsyncComponent(() => import("./emphasis-BmM30dZi.js")),
|
|
55
|
+
footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-6cTbdg-J.js")),
|
|
56
|
+
footnoteReference: defineAsyncComponent(() => import("./footnote-reference-CxJUg8wT.js")),
|
|
57
|
+
heading: defineAsyncComponent(() => import("./heading-DQ4lofbm.js")),
|
|
58
|
+
html: defineAsyncComponent(() => import("./html-Be_6ezK6.js")),
|
|
59
|
+
image: defineAsyncComponent(() => import("./image-e0E51Nc3.js")),
|
|
60
|
+
inlineCode: defineAsyncComponent(() => import("./inline-code-B5lfHACE.js")),
|
|
61
|
+
inlineMath: defineAsyncComponent(() => import("./inline-math-BuO_dWPX.js")),
|
|
62
|
+
link: defineAsyncComponent(() => import("./link-DyD59DzG.js")),
|
|
63
|
+
list: defineAsyncComponent(() => import("./list-De0KPajx.js")),
|
|
64
|
+
listItem: defineAsyncComponent(() => import("./list-item-CuUgvXRC.js")),
|
|
65
|
+
math: defineAsyncComponent(() => import("./math-DnFOOLdz.js")),
|
|
66
|
+
paragraph: defineAsyncComponent(() => import("./paragraph-D3H1qprZ.js")),
|
|
67
|
+
strong: defineAsyncComponent(() => import("./strong-BlCQoXCR.js")),
|
|
68
|
+
table: defineAsyncComponent(() => import("./table-Co_MpK6m.js")),
|
|
69
|
+
text: defineAsyncComponent(() => import("./text-DbHMEN3P.js")),
|
|
70
|
+
thematicBreak: defineAsyncComponent(() => import("./thematic-break-CdlhHAEZ.js")),
|
|
71
|
+
yaml: defineAsyncComponent(() => import("./yaml-DL5ozHZ_.js"))
|
|
74
72
|
};
|
|
75
73
|
|
|
76
74
|
//#endregion
|
|
77
75
|
//#region src/components/index.ts
|
|
78
76
|
const UI = {
|
|
79
|
-
Button: defineAsyncComponent(() => import("./button-
|
|
80
|
-
CodeBlock: defineAsyncComponent(() => import("./code-block-
|
|
81
|
-
Dropdown: defineAsyncComponent(() => import("./dropdown-
|
|
82
|
-
ErrorComponent: defineAsyncComponent(() => import("./error-component-
|
|
83
|
-
Icon: defineAsyncComponent(() => import("./icon-
|
|
84
|
-
Image: defineAsyncComponent(() => import("./image-
|
|
85
|
-
Modal: defineAsyncComponent(() => import("./modal-
|
|
86
|
-
NodeList: defineAsyncComponent(() => import("./node-list-
|
|
87
|
-
Segmented: defineAsyncComponent(() => import("./segmented-
|
|
77
|
+
Button: defineAsyncComponent(() => import("./button-1EHxh8s2.js")),
|
|
78
|
+
CodeBlock: defineAsyncComponent(() => import("./code-block-DYrPMONb.js")),
|
|
79
|
+
Dropdown: defineAsyncComponent(() => import("./dropdown-Cv_yW4GS.js")),
|
|
80
|
+
ErrorComponent: defineAsyncComponent(() => import("./error-component-1U-JNS6o.js")),
|
|
81
|
+
Icon: defineAsyncComponent(() => import("./icon-CvIgAOPh.js")),
|
|
82
|
+
Image: defineAsyncComponent(() => import("./image-Dm5xIWs7.js")),
|
|
83
|
+
Modal: defineAsyncComponent(() => import("./modal-B5jFKJL4.js")),
|
|
84
|
+
NodeList: defineAsyncComponent(() => import("./node-list-Doh9Z-4p.js")),
|
|
85
|
+
Segmented: defineAsyncComponent(() => import("./segmented-fbmq_xK1.js")),
|
|
88
86
|
Spin: defineAsyncComponent(() => import("./spin-DElj7VPm.js")),
|
|
89
87
|
Table: defineAsyncComponent(() => import("./table-D6j6Gl87.js")),
|
|
90
|
-
Tooltip: defineAsyncComponent(() => import("./tooltip-
|
|
91
|
-
ZoomContainer: defineAsyncComponent(() => import("./zoom-container-
|
|
88
|
+
Tooltip: defineAsyncComponent(() => import("./tooltip-70WIAMmC.js")),
|
|
89
|
+
ZoomContainer: defineAsyncComponent(() => import("./zoom-container-Dc8N-wuo.js"))
|
|
92
90
|
};
|
|
93
91
|
|
|
94
92
|
//#endregion
|
|
@@ -2894,7 +2892,7 @@ function initializeContent(effects) {
|
|
|
2894
2892
|
* Construct and its state.
|
|
2895
2893
|
*/
|
|
2896
2894
|
/** @type {InitialConstruct} */
|
|
2897
|
-
const document = { tokenize: initializeDocument };
|
|
2895
|
+
const document$1 = { tokenize: initializeDocument };
|
|
2898
2896
|
/** @type {Construct} */
|
|
2899
2897
|
const containerConstruct = { tokenize: tokenizeContainer };
|
|
2900
2898
|
/**
|
|
@@ -8989,7 +8987,7 @@ var constructs_exports = /* @__PURE__ */ __export({
|
|
|
8989
8987
|
attentionMarkers: () => attentionMarkers,
|
|
8990
8988
|
contentInitial: () => contentInitial,
|
|
8991
8989
|
disable: () => disable,
|
|
8992
|
-
document: () => document$
|
|
8990
|
+
document: () => document$2,
|
|
8993
8991
|
flow: () => flow$2,
|
|
8994
8992
|
flowInitial: () => flowInitial,
|
|
8995
8993
|
insideSpan: () => insideSpan,
|
|
@@ -8997,7 +8995,7 @@ var constructs_exports = /* @__PURE__ */ __export({
|
|
|
8997
8995
|
text: () => text$3
|
|
8998
8996
|
});
|
|
8999
8997
|
/** @satisfies {Extension['document']} */
|
|
9000
|
-
const document$
|
|
8998
|
+
const document$2 = {
|
|
9001
8999
|
[42]: list$2,
|
|
9002
9000
|
[43]: list$2,
|
|
9003
9001
|
[45]: list$2,
|
|
@@ -9552,7 +9550,7 @@ function parse(options) {
|
|
|
9552
9550
|
constructs: combineExtensions([constructs_exports, ...(options || {}).extensions || []]),
|
|
9553
9551
|
content: create$1(content),
|
|
9554
9552
|
defined: [],
|
|
9555
|
-
document: create$1(document),
|
|
9553
|
+
document: create$1(document$1),
|
|
9556
9554
|
flow: create$1(flow$1),
|
|
9557
9555
|
lazy: {},
|
|
9558
9556
|
string: create$1(string),
|
|
@@ -19708,6 +19706,82 @@ const quoteTaskListPattern = /^>\s*- \[[x ]\]/i;
|
|
|
19708
19706
|
const quoteIncompleteTaskListPattern = /^>\s*-\s*\[\s*$/;
|
|
19709
19707
|
const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
|
|
19710
19708
|
|
|
19709
|
+
//#endregion
|
|
19710
|
+
//#region src/preprocess/utils.ts
|
|
19711
|
+
/**
|
|
19712
|
+
* Utility functions for preprocessing markdown content
|
|
19713
|
+
*/
|
|
19714
|
+
/**
|
|
19715
|
+
* Find the start index of the last paragraph in content
|
|
19716
|
+
* A paragraph is defined as content after the last blank line
|
|
19717
|
+
*
|
|
19718
|
+
* @param lines - Array of lines from content.split('\n')
|
|
19719
|
+
* @param skipTrailingEmpty - If true, skip the last element if it's empty (from trailing \n)
|
|
19720
|
+
* @returns The start index of the last paragraph
|
|
19721
|
+
*/
|
|
19722
|
+
function findLastParagraphStart(lines, skipTrailingEmpty = false) {
|
|
19723
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
19724
|
+
const line = lines[i];
|
|
19725
|
+
if (line === void 0) continue;
|
|
19726
|
+
if (skipTrailingEmpty && i === lines.length - 1 && line.trim() === "") continue;
|
|
19727
|
+
if (line.trim() === "") return i + 1;
|
|
19728
|
+
}
|
|
19729
|
+
return 0;
|
|
19730
|
+
}
|
|
19731
|
+
/**
|
|
19732
|
+
* Get the last paragraph and its start index
|
|
19733
|
+
*
|
|
19734
|
+
* @param content - Markdown content
|
|
19735
|
+
* @param skipTrailingEmpty - If true, skip trailing empty line when finding paragraph start
|
|
19736
|
+
* @returns Object with lastParagraph and startIndex
|
|
19737
|
+
*/
|
|
19738
|
+
function getLastParagraphWithIndex(content$2, skipTrailingEmpty = false) {
|
|
19739
|
+
const lines = content$2.split("\n");
|
|
19740
|
+
const startIndex = findLastParagraphStart(lines, skipTrailingEmpty);
|
|
19741
|
+
return {
|
|
19742
|
+
lastParagraph: lines.slice(startIndex).join("\n"),
|
|
19743
|
+
startIndex
|
|
19744
|
+
};
|
|
19745
|
+
}
|
|
19746
|
+
/**
|
|
19747
|
+
* Find the index of the last non-empty line
|
|
19748
|
+
*
|
|
19749
|
+
* @param lines - Array of lines
|
|
19750
|
+
* @returns The index of the last non-empty line, or -1 if all lines are empty
|
|
19751
|
+
*/
|
|
19752
|
+
function findLastNonEmptyLineIndex(lines) {
|
|
19753
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
19754
|
+
const line = lines[i];
|
|
19755
|
+
if (line && line.trim() !== "") return i;
|
|
19756
|
+
}
|
|
19757
|
+
return -1;
|
|
19758
|
+
}
|
|
19759
|
+
/**
|
|
19760
|
+
* Calculate the absolute position in content from a relative position in a paragraph
|
|
19761
|
+
*
|
|
19762
|
+
* @param paragraphStartIndex - The line index where the paragraph starts
|
|
19763
|
+
* @param relativePos - The position relative to the paragraph start
|
|
19764
|
+
* @param lines - All lines from content.split('\n')
|
|
19765
|
+
* @returns The absolute position in the full content
|
|
19766
|
+
*/
|
|
19767
|
+
function calculateAbsolutePosition(paragraphStartIndex, relativePos, lines) {
|
|
19768
|
+
if (paragraphStartIndex === 0) return relativePos;
|
|
19769
|
+
const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
|
|
19770
|
+
return beforeParagraph.length > 0 ? beforeParagraph.length + 1 + relativePos : relativePos;
|
|
19771
|
+
}
|
|
19772
|
+
/**
|
|
19773
|
+
* Calculate the paragraph offset for absolute position calculations
|
|
19774
|
+
*
|
|
19775
|
+
* @param paragraphStartIndex - The line index where the paragraph starts
|
|
19776
|
+
* @param lines - All lines from content.split('\n')
|
|
19777
|
+
* @returns The offset to add to relative positions
|
|
19778
|
+
*/
|
|
19779
|
+
function calculateParagraphOffset(paragraphStartIndex, lines) {
|
|
19780
|
+
if (paragraphStartIndex === 0) return 0;
|
|
19781
|
+
const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
|
|
19782
|
+
return beforeParagraph.length > 0 ? beforeParagraph.length + 1 : 0;
|
|
19783
|
+
}
|
|
19784
|
+
|
|
19711
19785
|
//#endregion
|
|
19712
19786
|
//#region src/preprocess/code.ts
|
|
19713
19787
|
/**
|
|
@@ -19740,10 +19814,13 @@ const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
|
|
|
19740
19814
|
* // Returns: '```' (no completion, code block has no content)
|
|
19741
19815
|
*/
|
|
19742
19816
|
function fixCode(content$2) {
|
|
19817
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
19818
|
+
const isInsideCodeBlock = (codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1;
|
|
19743
19819
|
const cleaned = removeTrailingIncompleteBackticks(content$2);
|
|
19744
19820
|
const wasCleanedUp = cleaned !== content$2;
|
|
19745
19821
|
content$2 = cleaned;
|
|
19746
|
-
if (
|
|
19822
|
+
if (isInsideCodeBlock && wasCleanedUp) content$2 = fixCodeBlock(content$2);
|
|
19823
|
+
else if (!wasCleanedUp) content$2 = fixCodeBlock(content$2);
|
|
19747
19824
|
if (!wasCleanedUp) content$2 = fixInlineCode(content$2);
|
|
19748
19825
|
return content$2;
|
|
19749
19826
|
}
|
|
@@ -19761,13 +19838,8 @@ function removeTrailingIncompleteBackticks(content$2) {
|
|
|
19761
19838
|
const afterBackticks = content$2.substring(backtickPos + backtickSequence.length);
|
|
19762
19839
|
if (afterBackticks.trim().length > 0) return content$2;
|
|
19763
19840
|
if (backtickSequence.length === 1) {
|
|
19764
|
-
const
|
|
19765
|
-
|
|
19766
|
-
for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
|
|
19767
|
-
paragraphStartIndex = i + 1;
|
|
19768
|
-
break;
|
|
19769
|
-
}
|
|
19770
|
-
const backticks = lines.slice(paragraphStartIndex).join("\n").replace(codeBlockPattern, "").match(singleBacktickPattern);
|
|
19841
|
+
const { lastParagraph } = getLastParagraphWithIndex(beforeBackticks);
|
|
19842
|
+
const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
|
|
19771
19843
|
const count = backticks ? backticks.length : 0;
|
|
19772
19844
|
const codeBlockMatches = beforeBackticks.match(tripleBacktickPattern);
|
|
19773
19845
|
const codeBlockCount = codeBlockMatches ? codeBlockMatches.length : 0;
|
|
@@ -19807,12 +19879,7 @@ function fixInlineCode(content$2) {
|
|
|
19807
19879
|
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
19808
19880
|
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
19809
19881
|
const lines = content$2.split("\n");
|
|
19810
|
-
|
|
19811
|
-
for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
|
|
19812
|
-
paragraphStartIndex = i + 1;
|
|
19813
|
-
break;
|
|
19814
|
-
}
|
|
19815
|
-
const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
|
|
19882
|
+
const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
19816
19883
|
const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
|
|
19817
19884
|
if ((backticks ? backticks.length : 0) % 2 === 1) {
|
|
19818
19885
|
let lastBacktickPos = -1;
|
|
@@ -19834,8 +19901,7 @@ function fixInlineCode(content$2) {
|
|
|
19834
19901
|
}
|
|
19835
19902
|
}
|
|
19836
19903
|
if (lastBacktickPos !== -1) {
|
|
19837
|
-
const
|
|
19838
|
-
const actualPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastBacktickPos;
|
|
19904
|
+
const actualPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastBacktickPos;
|
|
19839
19905
|
if (content$2.substring(actualPos + 1).trim().length > 0) return `${content$2}\``;
|
|
19840
19906
|
else return content$2.slice(0, actualPos) + content$2.slice(actualPos + 1);
|
|
19841
19907
|
}
|
|
@@ -19867,31 +19933,28 @@ function fixInlineCode(content$2) {
|
|
|
19867
19933
|
* // Returns: 'List item\n\n~~' (no completion, ~~ has no content)
|
|
19868
19934
|
*/
|
|
19869
19935
|
function fixDelete(content$2) {
|
|
19870
|
-
const
|
|
19871
|
-
|
|
19872
|
-
|
|
19873
|
-
|
|
19874
|
-
|
|
19875
|
-
}
|
|
19876
|
-
const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
|
|
19877
|
-
const matches = lastParagraph.match(doubleTildePattern);
|
|
19936
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
19937
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
19938
|
+
const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
19939
|
+
const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
|
|
19940
|
+
const matches = lastParagraphWithoutCodeBlocks.match(doubleTildePattern);
|
|
19878
19941
|
const count = matches ? matches.length : 0;
|
|
19879
19942
|
if (content$2.endsWith("~") && !content$2.endsWith("~~")) {
|
|
19880
19943
|
const contentWithoutLastTilde = content$2.slice(0, -1);
|
|
19881
|
-
const
|
|
19882
|
-
const matchesWithoutTilde =
|
|
19944
|
+
const lastParagraphWithoutTildeAndCodeBlocks = contentWithoutLastTilde.split("\n").slice(paragraphStartIndex).join("\n").replace(codeBlockPattern, "");
|
|
19945
|
+
const matchesWithoutTilde = lastParagraphWithoutTildeAndCodeBlocks.match(doubleTildePattern);
|
|
19883
19946
|
if ((matchesWithoutTilde ? matchesWithoutTilde.length : 0) % 2 === 1) {
|
|
19884
|
-
const lastTildePos =
|
|
19947
|
+
const lastTildePos = lastParagraphWithoutTildeAndCodeBlocks.lastIndexOf("~~");
|
|
19885
19948
|
if (lastTildePos >= 0) {
|
|
19886
|
-
if (
|
|
19949
|
+
if (lastParagraphWithoutTildeAndCodeBlocks.substring(lastTildePos + 2).length > 0) return `${content$2}~`;
|
|
19887
19950
|
}
|
|
19888
19951
|
} else return contentWithoutLastTilde;
|
|
19889
19952
|
}
|
|
19890
19953
|
if (count % 2 === 1) {
|
|
19891
|
-
const lastTildePos =
|
|
19892
|
-
const afterLast =
|
|
19954
|
+
const lastTildePos = lastParagraphWithoutCodeBlocks.lastIndexOf("~~");
|
|
19955
|
+
const afterLast = lastParagraphWithoutCodeBlocks.substring(lastTildePos + 2);
|
|
19893
19956
|
if (afterLast.trim().length > 0) return `${content$2}~~`;
|
|
19894
|
-
else return content$2.substring(0, content$2.length - afterLast.length - 2);
|
|
19957
|
+
else return content$2.substring(0, content$2.length - afterLast.length - 2).trimEnd();
|
|
19895
19958
|
}
|
|
19896
19959
|
return content$2;
|
|
19897
19960
|
}
|
|
@@ -19905,35 +19968,46 @@ function fixDelete(content$2) {
|
|
|
19905
19968
|
* This respects Markdown's rule that emphasis cannot span across paragraphs.
|
|
19906
19969
|
*/
|
|
19907
19970
|
function fixEmphasis(content$2) {
|
|
19971
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
19972
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
19908
19973
|
const lines = content$2.split("\n");
|
|
19909
|
-
|
|
19910
|
-
|
|
19911
|
-
|
|
19912
|
-
break;
|
|
19913
|
-
}
|
|
19914
|
-
const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
|
|
19915
|
-
const withoutDoubleAsterisk = lastParagraph.replace(doubleAsteriskPattern, "");
|
|
19974
|
+
const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
19975
|
+
const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
|
|
19976
|
+
const withoutDoubleAsterisk = lastParagraphWithoutCodeBlocks.replace(doubleAsteriskPattern, "");
|
|
19916
19977
|
const asteriskMatches = withoutDoubleAsterisk.match(singleAsteriskPattern);
|
|
19917
|
-
|
|
19978
|
+
const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
|
|
19979
|
+
const withoutDoubleUnderscore = lastParagraphWithoutCodeBlocks.replace(doubleUnderscorePattern, "");
|
|
19980
|
+
const underscoreMatches = withoutDoubleUnderscore.match(singleUnderscorePattern);
|
|
19981
|
+
const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
|
|
19982
|
+
let needsAsteriskCompletion = false;
|
|
19983
|
+
let needsUnderscoreCompletion = false;
|
|
19984
|
+
let needsAsteriskRemoval = false;
|
|
19985
|
+
let needsUnderscoreRemoval = false;
|
|
19986
|
+
if (asteriskCount % 2 === 1) {
|
|
19918
19987
|
const lastStarPos = withoutDoubleAsterisk.lastIndexOf("*");
|
|
19919
|
-
if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0)
|
|
19920
|
-
else
|
|
19921
|
-
let result = content$2.slice(0, -1);
|
|
19922
|
-
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
19923
|
-
return result;
|
|
19924
|
-
}
|
|
19988
|
+
if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0) needsAsteriskCompletion = true;
|
|
19989
|
+
else needsAsteriskRemoval = true;
|
|
19925
19990
|
}
|
|
19926
|
-
|
|
19927
|
-
const underscoreMatches = withoutDoubleUnderscore.match(singleUnderscorePattern);
|
|
19928
|
-
if ((underscoreMatches ? underscoreMatches.length : 0) % 2 === 1) {
|
|
19991
|
+
if (underscoreCount % 2 === 1) {
|
|
19929
19992
|
const lastUnderscorePos = withoutDoubleUnderscore.lastIndexOf("_");
|
|
19930
|
-
if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0)
|
|
19931
|
-
else
|
|
19932
|
-
let result = content$2.slice(0, -1);
|
|
19933
|
-
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
19934
|
-
return result;
|
|
19935
|
-
}
|
|
19993
|
+
if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0) needsUnderscoreCompletion = true;
|
|
19994
|
+
else needsUnderscoreRemoval = true;
|
|
19936
19995
|
}
|
|
19996
|
+
if (needsAsteriskRemoval) {
|
|
19997
|
+
let result = content$2.slice(0, -1).trimEnd();
|
|
19998
|
+
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
19999
|
+
return result;
|
|
20000
|
+
}
|
|
20001
|
+
if (needsUnderscoreRemoval) {
|
|
20002
|
+
const absoluteLastUnderscorePos = calculateParagraphOffset(paragraphStartIndex, lines) + withoutDoubleUnderscore.lastIndexOf("_");
|
|
20003
|
+
let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
|
|
20004
|
+
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
20005
|
+
return result;
|
|
20006
|
+
}
|
|
20007
|
+
if (needsAsteriskCompletion && needsUnderscoreCompletion) if (withoutDoubleAsterisk.indexOf("*") < withoutDoubleUnderscore.indexOf("_")) return `${content$2}_*`;
|
|
20008
|
+
else return `${content$2}*_`;
|
|
20009
|
+
if (needsAsteriskCompletion) return `${content$2}*`;
|
|
20010
|
+
if (needsUnderscoreCompletion) return `${content$2}_`;
|
|
19937
20011
|
return content$2;
|
|
19938
20012
|
}
|
|
19939
20013
|
|
|
@@ -20007,47 +20081,42 @@ function fixFootnote(content$2) {
|
|
|
20007
20081
|
if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
|
|
20008
20082
|
}
|
|
20009
20083
|
}
|
|
20010
|
-
for (let i = 0; i < backtickPositions.length; i += 2)
|
|
20084
|
+
for (let i = 0; i < backtickPositions.length; i += 2) {
|
|
20011
20085
|
const start = backtickPositions[i];
|
|
20012
|
-
const end = backtickPositions[i + 1]
|
|
20013
|
-
inlineCodeRanges.push({
|
|
20086
|
+
const end = backtickPositions[i + 1];
|
|
20087
|
+
if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
|
|
20014
20088
|
start,
|
|
20015
|
-
end
|
|
20089
|
+
end: end + 1
|
|
20016
20090
|
});
|
|
20017
20091
|
}
|
|
20018
20092
|
const footnoteDefRanges = [];
|
|
20019
20093
|
let lineOffset = 0;
|
|
20020
20094
|
for (let i = 0; i < lines.length; i++) {
|
|
20021
20095
|
const line = lines[i];
|
|
20022
|
-
if (isFootnoteDefLine(line)) {
|
|
20096
|
+
if (line && isFootnoteDefLine(line)) {
|
|
20023
20097
|
const lineEnd = lineOffset + line.length;
|
|
20024
20098
|
footnoteDefRanges.push({
|
|
20025
20099
|
start: lineOffset,
|
|
20026
20100
|
end: lineEnd
|
|
20027
20101
|
});
|
|
20028
20102
|
}
|
|
20029
|
-
lineOffset += line.length + 1;
|
|
20030
|
-
}
|
|
20031
|
-
let lastParagraphStartIndex = 0;
|
|
20032
|
-
for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
|
|
20033
|
-
lastParagraphStartIndex = i + 1;
|
|
20034
|
-
break;
|
|
20103
|
+
if (line) lineOffset += line.length + 1;
|
|
20035
20104
|
}
|
|
20036
|
-
const lastParagraph =
|
|
20105
|
+
const { lastParagraph, startIndex: lastParagraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
20037
20106
|
let result = content$2;
|
|
20038
20107
|
if (incompleteFootnoteRefPattern.test(lastParagraph)) {
|
|
20039
20108
|
const incompleteRefPos = lastParagraph.lastIndexOf("[^");
|
|
20040
20109
|
if (incompleteRefPos !== -1) {
|
|
20041
|
-
const absolutePos = lastParagraphStartIndex
|
|
20110
|
+
const absolutePos = calculateAbsolutePosition(lastParagraphStartIndex, incompleteRefPos, lines);
|
|
20042
20111
|
const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
|
|
20043
20112
|
const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
|
|
20044
20113
|
if (!isInCodeBlock && !isInInlineCode) {
|
|
20045
20114
|
const lineEnd = lastParagraph.indexOf("\n", incompleteRefPos);
|
|
20046
20115
|
const refEnd = lineEnd !== -1 ? lineEnd : lastParagraph.length;
|
|
20047
|
-
|
|
20048
|
-
|
|
20049
|
-
const absoluteStart =
|
|
20050
|
-
const absoluteEnd =
|
|
20116
|
+
let refStart = incompleteRefPos;
|
|
20117
|
+
if (refStart > 0 && lastParagraph[refStart - 1] === " ") refStart--;
|
|
20118
|
+
const absoluteStart = calculateAbsolutePosition(lastParagraphStartIndex, refStart, lines);
|
|
20119
|
+
const absoluteEnd = calculateAbsolutePosition(lastParagraphStartIndex, refEnd, lines);
|
|
20051
20120
|
result = result.substring(0, absoluteStart) + result.substring(absoluteEnd);
|
|
20052
20121
|
content$2 = result;
|
|
20053
20122
|
codeBlockRanges.length = 0;
|
|
@@ -20081,12 +20150,12 @@ function fixFootnote(content$2) {
|
|
|
20081
20150
|
if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
|
|
20082
20151
|
}
|
|
20083
20152
|
}
|
|
20084
|
-
for (let i = 0; i < backtickPositions.length; i += 2)
|
|
20153
|
+
for (let i = 0; i < backtickPositions.length; i += 2) {
|
|
20085
20154
|
const start = backtickPositions[i];
|
|
20086
|
-
const end = backtickPositions[i + 1]
|
|
20087
|
-
inlineCodeRanges.push({
|
|
20155
|
+
const end = backtickPositions[i + 1];
|
|
20156
|
+
if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
|
|
20088
20157
|
start,
|
|
20089
|
-
end
|
|
20158
|
+
end: end + 1
|
|
20090
20159
|
});
|
|
20091
20160
|
}
|
|
20092
20161
|
}
|
|
@@ -20095,8 +20164,8 @@ function fixFootnote(content$2) {
|
|
|
20095
20164
|
const refPositions = [];
|
|
20096
20165
|
let refMatch = footnoteRefPattern.exec(content$2);
|
|
20097
20166
|
while (refMatch !== null) {
|
|
20098
|
-
const absolutePos = refMatch.index;
|
|
20099
|
-
const refText = refMatch[0];
|
|
20167
|
+
const absolutePos = refMatch.index ?? 0;
|
|
20168
|
+
const refText = refMatch[0] ?? "";
|
|
20100
20169
|
const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
|
|
20101
20170
|
const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
|
|
20102
20171
|
const isInFootnoteDef = footnoteDefRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
|
|
@@ -20113,7 +20182,11 @@ function fixFootnote(content$2) {
|
|
|
20113
20182
|
if (refPositions.length === 0) return content$2;
|
|
20114
20183
|
for (let i = refPositions.length - 1; i >= 0; i--) {
|
|
20115
20184
|
const ref$1 = refPositions[i];
|
|
20116
|
-
if (!definedLabels.has(ref$1.label))
|
|
20185
|
+
if (ref$1 && !definedLabels.has(ref$1.label)) {
|
|
20186
|
+
let refStart = ref$1.start;
|
|
20187
|
+
if (refStart > 0 && result[refStart - 1] === " ") refStart--;
|
|
20188
|
+
result = result.substring(0, refStart) + result.substring(ref$1.end);
|
|
20189
|
+
}
|
|
20117
20190
|
}
|
|
20118
20191
|
return result;
|
|
20119
20192
|
}
|
|
@@ -20149,15 +20222,11 @@ function fixFootnote(content$2) {
|
|
|
20149
20222
|
* // Returns: '$$\n' (no completion, this is block math)
|
|
20150
20223
|
*/
|
|
20151
20224
|
function fixInlineMath(content$2) {
|
|
20225
|
+
if (content$2 === "$") return "";
|
|
20152
20226
|
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20153
20227
|
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20154
20228
|
const lines = content$2.split("\n");
|
|
20155
|
-
|
|
20156
|
-
for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
|
|
20157
|
-
paragraphStartIndex = i + 1;
|
|
20158
|
-
break;
|
|
20159
|
-
}
|
|
20160
|
-
const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
|
|
20229
|
+
const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
20161
20230
|
let withoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
|
|
20162
20231
|
withoutCodeBlocks = withoutCodeBlocks.replace(/`[^`\n]+`/g, "");
|
|
20163
20232
|
const dollarMatches = withoutCodeBlocks.match(doubleDollarPattern);
|
|
@@ -20165,36 +20234,22 @@ function fixInlineMath(content$2) {
|
|
|
20165
20234
|
const lastDollarPos = findLastDollarPairNotInCodeBlock(lastParagraph);
|
|
20166
20235
|
if (lastDollarPos === -1) return content$2;
|
|
20167
20236
|
let afterLast = lastParagraph.substring(lastDollarPos + 2);
|
|
20237
|
+
if (afterLast.startsWith("\n") || afterLast.includes("\n")) return content$2;
|
|
20168
20238
|
if (afterLast.trim() === "$") return content$2;
|
|
20169
20239
|
let shouldRemoveTrailingDollar = false;
|
|
20170
20240
|
if (afterLast.endsWith("$") && !afterLast.endsWith("$$")) {
|
|
20171
20241
|
shouldRemoveTrailingDollar = true;
|
|
20172
20242
|
afterLast = afterLast.slice(0, -1);
|
|
20173
20243
|
}
|
|
20174
|
-
|
|
20175
|
-
const isBlockMathByAfter = !hasContentAfter && afterLast.startsWith("\n");
|
|
20176
|
-
const linesInParagraph = lastParagraph.split("\n");
|
|
20177
|
-
let lineWithDollar = "";
|
|
20178
|
-
for (let i = linesInParagraph.length - 1; i >= 0; i--) {
|
|
20179
|
-
const line = linesInParagraph[i];
|
|
20180
|
-
if (line.includes("$$")) {
|
|
20181
|
-
lineWithDollar = line;
|
|
20182
|
-
break;
|
|
20183
|
-
}
|
|
20184
|
-
}
|
|
20185
|
-
const isBlockMathByLine = lineWithDollar.replace(/\$\$/g, "").trim() === "" && afterLast.startsWith("\n");
|
|
20186
|
-
if (isBlockMathByAfter || isBlockMathByLine) return content$2;
|
|
20187
|
-
if (hasContentAfter) {
|
|
20244
|
+
if (afterLast.trim().length > 0) {
|
|
20188
20245
|
if (shouldRemoveTrailingDollar) {
|
|
20189
|
-
const
|
|
20190
|
-
const actualLastDollarPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastDollarPos;
|
|
20246
|
+
const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
|
|
20191
20247
|
return `${content$2.substring(0, actualLastDollarPos + 2)}${lastParagraph.substring(lastDollarPos + 2, lastParagraph.length - 1)}$$`;
|
|
20192
20248
|
}
|
|
20193
20249
|
return `${content$2}$$`;
|
|
20194
20250
|
} else {
|
|
20195
|
-
const
|
|
20196
|
-
|
|
20197
|
-
return content$2.slice(0, actualLastDollarPos) + content$2.slice(actualLastDollarPos + 2);
|
|
20251
|
+
const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
|
|
20252
|
+
return content$2.slice(0, actualLastDollarPos).trimEnd();
|
|
20198
20253
|
}
|
|
20199
20254
|
}
|
|
20200
20255
|
return content$2;
|
|
@@ -20275,36 +20330,87 @@ function findLastDollarPairNotInCodeBlock(text$4) {
|
|
|
20275
20330
|
* // Removes trailing standalone bracket and trailing newline
|
|
20276
20331
|
*/
|
|
20277
20332
|
function fixLink(content$2) {
|
|
20278
|
-
|
|
20333
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20334
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20279
20335
|
const lines = content$2.split("\n");
|
|
20280
|
-
|
|
20281
|
-
|
|
20282
|
-
|
|
20283
|
-
break;
|
|
20284
|
-
}
|
|
20285
|
-
const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
|
|
20286
|
-
let lastNonEmptyLineIndex = lines.length - 1;
|
|
20287
|
-
while (lastNonEmptyLineIndex >= 0 && ((_lines$lastNonEmptyLi = lines[lastNonEmptyLineIndex]) === null || _lines$lastNonEmptyLi === void 0 ? void 0 : _lines$lastNonEmptyLi.trim()) === "") lastNonEmptyLineIndex--;
|
|
20336
|
+
const { lastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20337
|
+
const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
|
|
20338
|
+
const lastNonEmptyLineIndex = findLastNonEmptyLineIndex(lines);
|
|
20288
20339
|
if (lastNonEmptyLineIndex >= 0) {
|
|
20289
20340
|
const lastLine = lines[lastNonEmptyLineIndex];
|
|
20290
|
-
if (
|
|
20291
|
-
|
|
20292
|
-
|
|
20293
|
-
|
|
20294
|
-
|
|
20295
|
-
|
|
20296
|
-
|
|
20297
|
-
|
|
20298
|
-
|
|
20299
|
-
|
|
20300
|
-
|
|
20341
|
+
if (!lastLine) return content$2;
|
|
20342
|
+
const standaloneBracketMatch = lastLine.match(/(!?\[)\s*$/);
|
|
20343
|
+
if (standaloneBracketMatch && standaloneBracketMatch[1]) {
|
|
20344
|
+
const bracket = standaloneBracketMatch[1];
|
|
20345
|
+
const bracketPos = lastLine.lastIndexOf(bracket);
|
|
20346
|
+
if (lastLine.substring(bracketPos + bracket.length).trim().length === 0) {
|
|
20347
|
+
const newLine = lastLine.substring(0, bracketPos).trimEnd();
|
|
20348
|
+
const newLines = [...lines];
|
|
20349
|
+
newLines[lastNonEmptyLineIndex] = newLine;
|
|
20350
|
+
if (lastNonEmptyLineIndex + 1 < newLines.length) {
|
|
20351
|
+
const nextLine = newLines[lastNonEmptyLineIndex + 1];
|
|
20352
|
+
if (nextLine !== void 0 && nextLine.trim() === "") newLines.splice(lastNonEmptyLineIndex + 1, 1);
|
|
20301
20353
|
}
|
|
20354
|
+
return newLines.join("\n");
|
|
20302
20355
|
}
|
|
20303
20356
|
}
|
|
20304
20357
|
}
|
|
20305
|
-
if (incompleteBracketPattern.test(
|
|
20306
|
-
if (incompleteLinkTextPattern.test(
|
|
20307
|
-
if (incompleteUrlPattern.test(
|
|
20358
|
+
if (incompleteBracketPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2}]()`;
|
|
20359
|
+
if (incompleteLinkTextPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2}()`;
|
|
20360
|
+
if (incompleteUrlPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2})`;
|
|
20361
|
+
return content$2;
|
|
20362
|
+
}
|
|
20363
|
+
|
|
20364
|
+
//#endregion
|
|
20365
|
+
//#region src/preprocess/math.ts
|
|
20366
|
+
/**
|
|
20367
|
+
* Fix unclosed block math ($$) syntax in streaming markdown
|
|
20368
|
+
*
|
|
20369
|
+
* Block math is defined as $$ delimiters on separate lines:
|
|
20370
|
+
* $$
|
|
20371
|
+
* E = mc^2
|
|
20372
|
+
* $$
|
|
20373
|
+
*
|
|
20374
|
+
* This function processes the entire content (not just last paragraph)
|
|
20375
|
+
* because block math can span multiple paragraphs.
|
|
20376
|
+
*
|
|
20377
|
+
* @param content - Markdown content (potentially incomplete in stream mode)
|
|
20378
|
+
* @returns Content with auto-completed block math if needed
|
|
20379
|
+
*
|
|
20380
|
+
* @example
|
|
20381
|
+
* fixMath('$$\nE = mc^2')
|
|
20382
|
+
* // Returns: '$$\nE = mc^2\n$$'
|
|
20383
|
+
*
|
|
20384
|
+
* @example
|
|
20385
|
+
* fixMath('$$\nE = mc^2\n$$')
|
|
20386
|
+
* // Returns: '$$\nE = mc^2\n$$' (no change)
|
|
20387
|
+
*/
|
|
20388
|
+
function fixMath(content$2) {
|
|
20389
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20390
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20391
|
+
const lines = content$2.split("\n");
|
|
20392
|
+
let inCodeBlock = false;
|
|
20393
|
+
const blockMathDelimiters = [];
|
|
20394
|
+
for (let i = 0; i < lines.length; i++) {
|
|
20395
|
+
const line = lines[i] ?? "";
|
|
20396
|
+
if (line.trim().startsWith("```")) {
|
|
20397
|
+
inCodeBlock = !inCodeBlock;
|
|
20398
|
+
continue;
|
|
20399
|
+
}
|
|
20400
|
+
if (inCodeBlock) continue;
|
|
20401
|
+
if (line.trim() === "$$") blockMathDelimiters.push(i);
|
|
20402
|
+
}
|
|
20403
|
+
if (blockMathDelimiters.length % 2 === 1) {
|
|
20404
|
+
const lastDelimiterIndex = blockMathDelimiters[blockMathDelimiters.length - 1] ?? -1;
|
|
20405
|
+
if (lastDelimiterIndex === -1) return content$2;
|
|
20406
|
+
if (lines.slice(lastDelimiterIndex + 1).some((line) => {
|
|
20407
|
+
const trimmed = line.trim();
|
|
20408
|
+
return trimmed.length > 0 && trimmed !== "$$";
|
|
20409
|
+
})) {
|
|
20410
|
+
if (!content$2.endsWith("\n")) return `${content$2}\n$$`;
|
|
20411
|
+
return `${content$2}$$`;
|
|
20412
|
+
} else return lines.slice(0, lastDelimiterIndex).join("\n");
|
|
20413
|
+
}
|
|
20308
20414
|
return content$2;
|
|
20309
20415
|
}
|
|
20310
20416
|
|
|
@@ -20336,32 +20442,96 @@ function fixLink(content$2) {
|
|
|
20336
20442
|
* // Returns: 'List item\n\n**' (no completion, ** has no content)
|
|
20337
20443
|
*/
|
|
20338
20444
|
function fixStrong(content$2) {
|
|
20339
|
-
|
|
20340
|
-
|
|
20341
|
-
|
|
20342
|
-
|
|
20343
|
-
|
|
20445
|
+
if (content$2 === "*" || content$2 === "_") return "";
|
|
20446
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20447
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20448
|
+
const { lastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20449
|
+
const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
|
|
20450
|
+
const endsWithSingleAsterisk = content$2.endsWith("*") && !content$2.endsWith("**");
|
|
20451
|
+
const endsWithSingleUnderscore = content$2.endsWith("_") && !content$2.endsWith("__");
|
|
20452
|
+
const asteriskMatches = lastParagraphWithoutCodeBlocks.match(doubleAsteriskPattern);
|
|
20453
|
+
const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
|
|
20454
|
+
const underscoreMatches = lastParagraphWithoutCodeBlocks.match(doubleUnderscorePattern);
|
|
20455
|
+
const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
|
|
20456
|
+
let needsAsteriskCompletion = false;
|
|
20457
|
+
let needsUnderscoreCompletion = false;
|
|
20458
|
+
let needsAsteriskRemoval = false;
|
|
20459
|
+
let needsUnderscoreRemoval = false;
|
|
20460
|
+
if (asteriskCount % 2 === 1) {
|
|
20461
|
+
const lastStarPos = lastParagraphWithoutCodeBlocks.lastIndexOf("**");
|
|
20462
|
+
if (lastParagraphWithoutCodeBlocks.substring(lastStarPos + 2).trim().length > 0) needsAsteriskCompletion = true;
|
|
20463
|
+
else needsAsteriskRemoval = true;
|
|
20464
|
+
}
|
|
20465
|
+
if (underscoreCount % 2 === 1) {
|
|
20466
|
+
const lastUnderscorePos = lastParagraphWithoutCodeBlocks.lastIndexOf("__");
|
|
20467
|
+
if (lastParagraphWithoutCodeBlocks.substring(lastUnderscorePos + 2).trim().length > 0) needsUnderscoreCompletion = true;
|
|
20468
|
+
else needsUnderscoreRemoval = true;
|
|
20469
|
+
}
|
|
20470
|
+
let removedTrailingSingle = false;
|
|
20471
|
+
if (endsWithSingleAsterisk && (needsAsteriskCompletion || needsAsteriskRemoval)) {
|
|
20472
|
+
content$2 = content$2.slice(0, -1);
|
|
20473
|
+
removedTrailingSingle = true;
|
|
20474
|
+
const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20475
|
+
const newLastParagraphWithoutCodeBlocks = newLastParagraph.replace(codeBlockPattern, "");
|
|
20476
|
+
const newAsteriskMatches = newLastParagraphWithoutCodeBlocks.match(doubleAsteriskPattern);
|
|
20477
|
+
if ((newAsteriskMatches ? newAsteriskMatches.length : 0) % 2 === 1) {
|
|
20478
|
+
const lastStarPos = newLastParagraphWithoutCodeBlocks.lastIndexOf("**");
|
|
20479
|
+
if (newLastParagraphWithoutCodeBlocks.substring(lastStarPos + 2).trim().length > 0) {
|
|
20480
|
+
needsAsteriskCompletion = true;
|
|
20481
|
+
needsAsteriskRemoval = false;
|
|
20482
|
+
} else {
|
|
20483
|
+
needsAsteriskRemoval = true;
|
|
20484
|
+
needsAsteriskCompletion = false;
|
|
20485
|
+
}
|
|
20486
|
+
}
|
|
20344
20487
|
}
|
|
20345
|
-
|
|
20346
|
-
|
|
20347
|
-
|
|
20348
|
-
const
|
|
20349
|
-
|
|
20350
|
-
|
|
20351
|
-
|
|
20352
|
-
|
|
20353
|
-
|
|
20488
|
+
if (endsWithSingleUnderscore && (needsUnderscoreCompletion || needsUnderscoreRemoval)) {
|
|
20489
|
+
content$2 = content$2.slice(0, -1);
|
|
20490
|
+
removedTrailingSingle = true;
|
|
20491
|
+
const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20492
|
+
const newLastParagraphWithoutCodeBlocks = newLastParagraph.replace(codeBlockPattern, "");
|
|
20493
|
+
const newUnderscoreMatches = newLastParagraphWithoutCodeBlocks.match(doubleUnderscorePattern);
|
|
20494
|
+
if ((newUnderscoreMatches ? newUnderscoreMatches.length : 0) % 2 === 1) {
|
|
20495
|
+
const lastUnderscorePos = newLastParagraphWithoutCodeBlocks.lastIndexOf("__");
|
|
20496
|
+
if (newLastParagraphWithoutCodeBlocks.substring(lastUnderscorePos + 2).trim().length > 0) {
|
|
20497
|
+
needsUnderscoreCompletion = true;
|
|
20498
|
+
needsUnderscoreRemoval = false;
|
|
20499
|
+
} else {
|
|
20500
|
+
needsUnderscoreRemoval = true;
|
|
20501
|
+
needsUnderscoreCompletion = false;
|
|
20502
|
+
}
|
|
20354
20503
|
}
|
|
20355
20504
|
}
|
|
20356
|
-
|
|
20357
|
-
|
|
20358
|
-
|
|
20359
|
-
|
|
20360
|
-
|
|
20361
|
-
|
|
20362
|
-
|
|
20363
|
-
|
|
20505
|
+
if (needsAsteriskRemoval) {
|
|
20506
|
+
let result = content$2.slice(0, -2).trimEnd();
|
|
20507
|
+
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
20508
|
+
return result;
|
|
20509
|
+
}
|
|
20510
|
+
if (needsUnderscoreRemoval) {
|
|
20511
|
+
const { lastParagraph: newLastParagraph, startIndex: newParagraphStartIndex } = getLastParagraphWithIndex(content$2);
|
|
20512
|
+
const lastUnderscorePos = newLastParagraph.lastIndexOf("__");
|
|
20513
|
+
const absoluteLastUnderscorePos = calculateParagraphOffset(newParagraphStartIndex, content$2.split("\n")) + lastUnderscorePos;
|
|
20514
|
+
let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
|
|
20515
|
+
if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
|
|
20516
|
+
return result;
|
|
20517
|
+
}
|
|
20518
|
+
if (needsAsteriskCompletion && needsUnderscoreCompletion) if (lastParagraphWithoutCodeBlocks.indexOf("**") < lastParagraphWithoutCodeBlocks.indexOf("__")) return `${content$2}__**`;
|
|
20519
|
+
else return `${content$2}**__`;
|
|
20520
|
+
if (needsAsteriskCompletion) {
|
|
20521
|
+
if (!removedTrailingSingle) {
|
|
20522
|
+
const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20523
|
+
const singleAsteriskMatches = currentLastParagraph.replace(codeBlockPattern, "").replace(doubleAsteriskPattern, "").match(singleAsteriskPattern);
|
|
20524
|
+
if ((singleAsteriskMatches ? singleAsteriskMatches.length : 0) % 2 === 1) return `${content$2}***`;
|
|
20525
|
+
}
|
|
20526
|
+
return `${content$2}**`;
|
|
20527
|
+
}
|
|
20528
|
+
if (needsUnderscoreCompletion) {
|
|
20529
|
+
if (!removedTrailingSingle) {
|
|
20530
|
+
const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
|
|
20531
|
+
const singleUnderscoreMatches = currentLastParagraph.replace(codeBlockPattern, "").replace(doubleUnderscorePattern, "").match(singleUnderscorePattern);
|
|
20532
|
+
if ((singleUnderscoreMatches ? singleUnderscoreMatches.length : 0) % 2 === 1) return `${content$2}___`;
|
|
20364
20533
|
}
|
|
20534
|
+
return `${content$2}__`;
|
|
20365
20535
|
}
|
|
20366
20536
|
return content$2;
|
|
20367
20537
|
}
|
|
@@ -20397,29 +20567,40 @@ function fixStrong(content$2) {
|
|
|
20397
20567
|
function fixTable(content$2) {
|
|
20398
20568
|
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20399
20569
|
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20400
|
-
const
|
|
20401
|
-
let
|
|
20402
|
-
|
|
20403
|
-
const
|
|
20404
|
-
if (
|
|
20405
|
-
|
|
20406
|
-
|
|
20407
|
-
|
|
20408
|
-
|
|
20570
|
+
const codeBlockRanges = [];
|
|
20571
|
+
let searchStart = 0;
|
|
20572
|
+
while (true) {
|
|
20573
|
+
const codeBlockStart = content$2.indexOf("```", searchStart);
|
|
20574
|
+
if (codeBlockStart === -1) break;
|
|
20575
|
+
const codeBlockEnd = content$2.indexOf("```", codeBlockStart + 3);
|
|
20576
|
+
if (codeBlockEnd === -1) break;
|
|
20577
|
+
codeBlockRanges.push({
|
|
20578
|
+
start: codeBlockStart,
|
|
20579
|
+
end: codeBlockEnd + 3
|
|
20580
|
+
});
|
|
20581
|
+
searchStart = codeBlockEnd + 3;
|
|
20409
20582
|
}
|
|
20410
|
-
const
|
|
20583
|
+
const { lastParagraph } = getLastParagraphWithIndex(content$2, true);
|
|
20584
|
+
const paragraphLines = lastParagraph.split("\n").filter((line) => line.trim() !== "");
|
|
20411
20585
|
if (paragraphLines.length === 0) return content$2;
|
|
20412
20586
|
let headerRowIndex = -1;
|
|
20413
20587
|
let headerRow = "";
|
|
20414
20588
|
for (let i = 0; i < paragraphLines.length; i++) {
|
|
20415
|
-
const line = paragraphLines[i]
|
|
20416
|
-
if (
|
|
20589
|
+
const line = paragraphLines[i];
|
|
20590
|
+
if (!line) continue;
|
|
20591
|
+
const trimmedLine = line.trim();
|
|
20592
|
+
if (tableRowPattern.test(trimmedLine) || trimmedLine.startsWith("|") && trimmedLine.length > 1) {
|
|
20417
20593
|
headerRowIndex = i;
|
|
20418
|
-
headerRow =
|
|
20594
|
+
headerRow = trimmedLine;
|
|
20419
20595
|
break;
|
|
20420
20596
|
}
|
|
20421
20597
|
}
|
|
20422
20598
|
if (headerRowIndex === -1) return content$2;
|
|
20599
|
+
const headerRowPos = content$2.lastIndexOf(headerRow);
|
|
20600
|
+
if (headerRowPos !== -1) {
|
|
20601
|
+
const headerRowEndPos = headerRowPos + headerRow.length;
|
|
20602
|
+
if (codeBlockRanges.some((range) => headerRowPos >= range.start && headerRowPos < range.end || headerRowEndPos > range.start && headerRowEndPos <= range.end || headerRowPos < range.start && headerRowEndPos > range.end)) return content$2;
|
|
20603
|
+
}
|
|
20423
20604
|
const trimmedHeader = headerRow.trim();
|
|
20424
20605
|
const isHeaderComplete = trimmedHeader.endsWith("|");
|
|
20425
20606
|
let completedHeaderRow = headerRow;
|
|
@@ -20427,7 +20608,6 @@ function fixTable(content$2) {
|
|
|
20427
20608
|
const headerColumns = (completedHeaderRow.match(/\|/g) || []).length - 1;
|
|
20428
20609
|
if (headerColumns < 1) return content$2;
|
|
20429
20610
|
const separator = generateSeparator(headerColumns);
|
|
20430
|
-
const headerRowPos = content$2.lastIndexOf(headerRow);
|
|
20431
20611
|
const beforeHeaderRow = content$2.substring(0, headerRowPos);
|
|
20432
20612
|
const afterHeaderRow = content$2.substring(headerRowPos + headerRow.length);
|
|
20433
20613
|
if (headerRowIndex === paragraphLines.length - 1) {
|
|
@@ -20435,7 +20615,9 @@ function fixTable(content$2) {
|
|
|
20435
20615
|
if (newContent.endsWith("\n")) return `${newContent}${separator}`;
|
|
20436
20616
|
else return `${newContent}\n${separator}`;
|
|
20437
20617
|
}
|
|
20438
|
-
const
|
|
20618
|
+
const nextLineRaw = paragraphLines[headerRowIndex + 1];
|
|
20619
|
+
if (!nextLineRaw) return content$2;
|
|
20620
|
+
const nextLine = nextLineRaw.trim();
|
|
20439
20621
|
if (separatorPattern.test(nextLine)) {
|
|
20440
20622
|
if ((nextLine.match(/\|/g) || []).length - 1 === headerColumns) {
|
|
20441
20623
|
if (!isHeaderComplete) return `${beforeHeaderRow}${completedHeaderRow}${afterHeaderRow}`;
|
|
@@ -20445,6 +20627,7 @@ function fixTable(content$2) {
|
|
|
20445
20627
|
const afterLines = afterHeaderRow.split("\n");
|
|
20446
20628
|
if (afterLines.length > 1) {
|
|
20447
20629
|
const nextLineInContent = afterLines[1];
|
|
20630
|
+
if (!nextLineInContent) return content$2;
|
|
20448
20631
|
if (nextLineInContent.startsWith("|") && nextLineInContent.includes("-")) {
|
|
20449
20632
|
const remainingLines = afterLines.slice(2).join("\n");
|
|
20450
20633
|
const newHeader = isHeaderComplete ? headerRow : completedHeaderRow;
|
|
@@ -20497,29 +20680,37 @@ function generateSeparator(columns) {
|
|
|
20497
20680
|
* // Returns: '> **Note**: Here\'s a quote with tasks:\n\n'
|
|
20498
20681
|
*/
|
|
20499
20682
|
function fixTaskList(content$2) {
|
|
20683
|
+
const codeBlockMatches = content$2.match(tripleBacktickPattern);
|
|
20684
|
+
if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
|
|
20685
|
+
const codeBlockRanges = [];
|
|
20686
|
+
let searchStart = 0;
|
|
20687
|
+
while (true) {
|
|
20688
|
+
const codeBlockStart = content$2.indexOf("```", searchStart);
|
|
20689
|
+
if (codeBlockStart === -1) break;
|
|
20690
|
+
const codeBlockEnd = content$2.indexOf("```", codeBlockStart + 3);
|
|
20691
|
+
if (codeBlockEnd === -1) break;
|
|
20692
|
+
codeBlockRanges.push({
|
|
20693
|
+
start: codeBlockStart,
|
|
20694
|
+
end: codeBlockEnd + 3
|
|
20695
|
+
});
|
|
20696
|
+
searchStart = codeBlockEnd + 3;
|
|
20697
|
+
}
|
|
20500
20698
|
const lines = content$2.split("\n");
|
|
20501
20699
|
if (lines.length === 0) return content$2;
|
|
20502
20700
|
const lastLine = lines[lines.length - 1];
|
|
20503
|
-
if (
|
|
20504
|
-
|
|
20505
|
-
|
|
20506
|
-
|
|
20507
|
-
|
|
20508
|
-
|
|
20509
|
-
|
|
20510
|
-
|
|
20511
|
-
|
|
20512
|
-
|
|
20513
|
-
if (incompleteTaskListPattern.test(lastLine))
|
|
20514
|
-
|
|
20515
|
-
|
|
20516
|
-
return result;
|
|
20517
|
-
}
|
|
20518
|
-
if (standaloneDashPattern.test(lastLine) && !taskListPattern.test(lastLine)) {
|
|
20519
|
-
const result = lines.slice(0, -1).join("\n");
|
|
20520
|
-
if (lines.length > 1) return `${result}\n`;
|
|
20521
|
-
return result;
|
|
20522
|
-
}
|
|
20701
|
+
if (!lastLine) return content$2;
|
|
20702
|
+
let lastLineStartPos = 0;
|
|
20703
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
20704
|
+
const line = lines[i];
|
|
20705
|
+
if (line !== void 0) lastLineStartPos += line.length + 1;
|
|
20706
|
+
}
|
|
20707
|
+
const lastLineEndPos = lastLineStartPos + lastLine.length;
|
|
20708
|
+
if (codeBlockRanges.some((range) => lastLineStartPos >= range.start && lastLineStartPos < range.end || lastLineEndPos > range.start && lastLineEndPos <= range.end || lastLineStartPos < range.start && lastLineEndPos > range.end)) return content$2;
|
|
20709
|
+
if (quoteIncompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
|
|
20710
|
+
if (quoteStandaloneDashPattern.test(lastLine) && !quoteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
|
|
20711
|
+
if (incompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
|
|
20712
|
+
if (standaloneDashPattern.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
|
|
20713
|
+
if (/^\s*-\s+$/.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
|
|
20523
20714
|
return content$2;
|
|
20524
20715
|
}
|
|
20525
20716
|
|
|
@@ -20554,16 +20745,16 @@ function normalize(content$2) {
|
|
|
20554
20745
|
}
|
|
20555
20746
|
function preprocess(content$2) {
|
|
20556
20747
|
return flow([
|
|
20748
|
+
fixCode,
|
|
20557
20749
|
fixFootnote,
|
|
20558
20750
|
fixStrong,
|
|
20559
20751
|
fixEmphasis,
|
|
20560
20752
|
fixDelete,
|
|
20561
|
-
fixCode,
|
|
20562
20753
|
fixTaskList,
|
|
20563
20754
|
fixLink,
|
|
20564
20755
|
fixTable,
|
|
20565
20756
|
fixInlineMath,
|
|
20566
|
-
|
|
20757
|
+
fixMath
|
|
20567
20758
|
])(content$2);
|
|
20568
20759
|
}
|
|
20569
20760
|
|
|
@@ -20571,16 +20762,12 @@ function preprocess(content$2) {
|
|
|
20571
20762
|
//#region src/markdown-parser.ts
|
|
20572
20763
|
var MarkdownParser = class {
|
|
20573
20764
|
constructor(options) {
|
|
20574
|
-
var _this$options$extendM, _this$options;
|
|
20575
20765
|
_defineProperty(this, "mode", "streaming");
|
|
20576
|
-
_defineProperty(this, "md", void 0);
|
|
20577
20766
|
_defineProperty(this, "content", "");
|
|
20578
20767
|
_defineProperty(this, "syntaxTree", null);
|
|
20579
20768
|
_defineProperty(this, "options", void 0);
|
|
20580
20769
|
this.mode = options.mode;
|
|
20581
20770
|
this.options = options;
|
|
20582
|
-
this.md = new MarkdownItAsync();
|
|
20583
|
-
(_this$options$extendM = (_this$options = this.options).extendMarkdownIt) === null || _this$options$extendM === void 0 || _this$options$extendM.call(_this$options, this.md);
|
|
20584
20771
|
}
|
|
20585
20772
|
update(data) {
|
|
20586
20773
|
data = (this.options.normalize ?? normalize)(data);
|
|
@@ -20606,9 +20793,6 @@ var MarkdownParser = class {
|
|
|
20606
20793
|
nodes: this.syntaxTree.children
|
|
20607
20794
|
};
|
|
20608
20795
|
}
|
|
20609
|
-
markdownToHtml(content$2) {
|
|
20610
|
-
return this.md.render(content$2);
|
|
20611
|
-
}
|
|
20612
20796
|
markdownToAst(content$2, loading = false) {
|
|
20613
20797
|
var _this$options$mdastOp, _this$options$mdastOp2;
|
|
20614
20798
|
const data = fromMarkdown(content$2, {
|
|
@@ -20701,6 +20885,10 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20701
20885
|
required: false,
|
|
20702
20886
|
default: void 0
|
|
20703
20887
|
},
|
|
20888
|
+
beforeDownload: {
|
|
20889
|
+
type: Function,
|
|
20890
|
+
required: false
|
|
20891
|
+
},
|
|
20704
20892
|
controls: {
|
|
20705
20893
|
type: [Boolean, Object],
|
|
20706
20894
|
required: false,
|
|
@@ -20735,6 +20923,10 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20735
20923
|
type: Object,
|
|
20736
20924
|
required: false
|
|
20737
20925
|
},
|
|
20926
|
+
uiOptions: {
|
|
20927
|
+
type: Object,
|
|
20928
|
+
required: false
|
|
20929
|
+
},
|
|
20738
20930
|
isDark: {
|
|
20739
20931
|
type: Boolean,
|
|
20740
20932
|
required: false,
|
|
@@ -20759,26 +20951,16 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20759
20951
|
postprocess: {
|
|
20760
20952
|
type: Function,
|
|
20761
20953
|
required: false
|
|
20762
|
-
},
|
|
20763
|
-
extendMarkdownIt: {
|
|
20764
|
-
type: Function,
|
|
20765
|
-
required: false
|
|
20766
20954
|
}
|
|
20767
20955
|
},
|
|
20768
20956
|
emits: ["copied"],
|
|
20769
20957
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
20770
20958
|
const props = __props;
|
|
20771
20959
|
const emits = __emit;
|
|
20772
|
-
const { mode, shikiOptions, mermaidOptions, isDark, enableAnimate } = toRefs(props);
|
|
20960
|
+
const { mode, shikiOptions, mermaidOptions, uiOptions, isDark, enableAnimate } = toRefs(props);
|
|
20773
20961
|
const containerRef = ref();
|
|
20774
20962
|
const { provideContext } = useContext();
|
|
20775
|
-
const markdownParser = new MarkdownParser(
|
|
20776
|
-
mode: props.mode,
|
|
20777
|
-
mdastOptions: props.mdastOptions,
|
|
20778
|
-
postprocess: props.postprocess,
|
|
20779
|
-
preprocess: props.preprocess,
|
|
20780
|
-
normalize: props.normalize
|
|
20781
|
-
});
|
|
20963
|
+
const markdownParser = new MarkdownParser(props);
|
|
20782
20964
|
const processed = computed(() => markdownParser.parseMarkdown(props.content));
|
|
20783
20965
|
const parsedNodes = computed(() => processed.value.nodes);
|
|
20784
20966
|
const processedContent = computed(() => processed.value.content);
|
|
@@ -20797,10 +20979,29 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20797
20979
|
function getContainer() {
|
|
20798
20980
|
return containerRef.value;
|
|
20799
20981
|
}
|
|
20982
|
+
function getOverlayContainer() {
|
|
20983
|
+
return document.querySelector("#stream-markdown-overlay");
|
|
20984
|
+
}
|
|
20800
20985
|
const { preload: preloadShiki, dispose: disposeShiki } = useShiki({ shikiOptions });
|
|
20801
20986
|
const { preload: preloadMermaid, dispose: disposeMermaid } = useMermaid({ mermaidOptions });
|
|
20802
20987
|
const { preload: preloadKatex, dispose: disposeKatex } = useKatex();
|
|
20988
|
+
function ensureOverlayContainer() {
|
|
20989
|
+
if (!getOverlayContainer()) {
|
|
20990
|
+
const div = document.createElement("div");
|
|
20991
|
+
div.id = "stream-markdown-overlay";
|
|
20992
|
+
div.classList.add("stream-markdown-overlay");
|
|
20993
|
+
div.classList.add(isDark.value ? "dark" : "light");
|
|
20994
|
+
document.body.appendChild(div);
|
|
20995
|
+
}
|
|
20996
|
+
}
|
|
20997
|
+
function updateOverlayContainerTheme() {
|
|
20998
|
+
const overlayContainer = getOverlayContainer();
|
|
20999
|
+
if (!overlayContainer) return;
|
|
21000
|
+
overlayContainer.classList.toggle("dark", isDark.value);
|
|
21001
|
+
overlayContainer.classList.toggle("light", !isDark.value);
|
|
21002
|
+
}
|
|
20803
21003
|
async function bootstrap() {
|
|
21004
|
+
ensureOverlayContainer();
|
|
20804
21005
|
const tasks = [
|
|
20805
21006
|
preloadShiki(),
|
|
20806
21007
|
preloadMermaid(),
|
|
@@ -20814,13 +21015,17 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20814
21015
|
onMounted(bootstrap);
|
|
20815
21016
|
watch(() => props.mode, () => markdownParser.updateMode(props.mode));
|
|
20816
21017
|
watch(() => props.locale, () => loadLocaleMessages(props.locale));
|
|
21018
|
+
watch(() => props.isDark, () => updateOverlayContainerTheme());
|
|
20817
21019
|
provideContext({
|
|
20818
21020
|
mode,
|
|
20819
21021
|
icons,
|
|
21022
|
+
uiOptions,
|
|
20820
21023
|
isDark,
|
|
20821
21024
|
enableAnimate,
|
|
20822
21025
|
parsedNodes,
|
|
20823
21026
|
getContainer,
|
|
21027
|
+
getOverlayContainer,
|
|
21028
|
+
beforeDownload: props.beforeDownload,
|
|
20824
21029
|
onCopied: (content$2) => {
|
|
20825
21030
|
emits("copied", content$2);
|
|
20826
21031
|
}
|
|
@@ -20859,4 +21064,4 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
|
|
|
20859
21064
|
var src_default = index_vue_vue_type_script_setup_true_lang_default;
|
|
20860
21065
|
|
|
20861
21066
|
//#endregion
|
|
20862
|
-
export { CODE_PREVIEWERS, DEFAULT_DARK_THEME, DEFAULT_HARDEN_OPTIONS, DEFAULT_LIGHT_THEME, ICONS, LANGUAGE_ALIAS, LANGUAGE_EXTENSIONS, LANGUAGE_ICONS, src_default as Markdown, MarkdownParser, NODE_RENDERERS, PRELOAD_NODE_RENDERER, SHADCN_SCHEMAS, SUPPORT_LANGUAGES, UI, codeBlockPattern, crlfPattern, currentLocale, doubleAsteriskPattern, doubleDollarPattern, doubleTildePattern, doubleUnderscorePattern, escapeMarkdownTableCell, extractTableDataFromElement, findLastLeafNode, findNodeParent, fixCode, fixDelete, fixEmphasis, fixFootnote, fixLink, fixStrong, fixTable, fixTaskList, flow, footnoteDefLabelPattern, footnoteDefLinePattern, footnoteDefPattern, footnoteRefLabelPattern, footnoteRefPattern, hasKatex, hasMermaid, hasShiki, incompleteBracketPattern, incompleteFootnoteRefPattern, incompleteLinkTextPattern, incompleteTaskListPattern, incompleteUrlPattern, isClient, isServer, loadLocaleMessages, localeMessages, localesGlob, normalize, postFixFootnote, postFixText, postNormalize, postprocess, preloadAsyncComponents, preprocess, preprocessLaTeX, proprocessContent, quoteIncompleteTaskListPattern, quoteStandaloneDashPattern, quoteTaskListPattern,
|
|
21067
|
+
export { CODE_PREVIEWERS, DEFAULT_DARK_THEME, DEFAULT_HARDEN_OPTIONS, DEFAULT_LIGHT_THEME, ICONS, LANGUAGE_ALIAS, LANGUAGE_EXTENSIONS, LANGUAGE_ICONS, src_default as Markdown, MarkdownParser, NODE_RENDERERS, PRELOAD_NODE_RENDERER, SHADCN_SCHEMAS, SUPPORT_LANGUAGES, UI, codeBlockPattern, crlfPattern, currentLocale, doubleAsteriskPattern, doubleDollarPattern, doubleTildePattern, doubleUnderscorePattern, escapeMarkdownTableCell, extractTableDataFromElement, findLastLeafNode, findNodeParent, fixCode, fixDelete, fixEmphasis, fixFootnote, fixLink, fixMath, fixStrong, fixTable, fixTaskList, flow, footnoteDefLabelPattern, footnoteDefLinePattern, footnoteDefPattern, footnoteRefLabelPattern, footnoteRefPattern, hasKatex, hasMermaid, hasShiki, incompleteBracketPattern, incompleteFootnoteRefPattern, incompleteLinkTextPattern, incompleteTaskListPattern, incompleteUrlPattern, isClient, isServer, loadLocaleMessages, localeMessages, localesGlob, normalize, postFixFootnote, postFixText, postNormalize, postprocess, preloadAsyncComponents, preprocess, preprocessLaTeX, proprocessContent, quoteIncompleteTaskListPattern, quoteStandaloneDashPattern, quoteTaskListPattern, save, saveImage, separatorPattern, singleAsteriskPattern, singleBacktickPattern, singleUnderscorePattern, standaloneDashPattern, svgToPngBlob, tableDataToCSV, tableDataToMarkdown, tableDataToTSV, tableRowPattern, taskListPattern, trailingBackticksPattern, trailingStandaloneBracketPattern, trailingStandaloneDashWithNewlinesPattern, trailingWhitespacePattern, transformUrl, tripleBacktickPattern, useCodeOptions, useContext, useControls, useFloating, useI18n, useKatex, useMathRenderer, useMediumZoom, useMermaid, useSanitizers, useShiki, useTailwindV3Theme, useZoom };
|