vue-stream-markdown 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +4 -0
  2. package/dist/{blockquote-CVFraiyL.js → blockquote-Crr-D7fY.js} +6 -2
  3. package/dist/{break-CzrM3nW0.js → break-DoDPjOA0.js} +4 -0
  4. package/dist/{button-CWSGNZmd.js → button-DVWlhfQ9.js} +2 -2
  5. package/dist/button-Dw4uJRaD.js +6 -0
  6. package/dist/{code-DwwmPoup.js → code-Bz8LM16H.js} +14 -10
  7. package/dist/code-block-Bitp8x1w.js +10 -0
  8. package/dist/{code-block-XfHjZodV.js → code-block-CmUZxKNr.js} +14 -9
  9. package/dist/{composables-BMXMKLLj.js → composables-CzUVrTt_.js} +14 -2
  10. package/dist/{delete-BRwEUU72.js → delete-DFoiOzHW.js} +6 -2
  11. package/dist/dropdown-CSRjqK0u.js +6 -0
  12. package/dist/{emphasis-DblyP-Vp.js → emphasis-DvaBuxeK.js} +6 -2
  13. package/dist/{error-component-CckClFee.js → error-component-BTe-SuY7.js} +2 -2
  14. package/dist/error-component-DDnC0bqw.js +5 -0
  15. package/dist/{footnote-definition-BvZNKSLa.js → footnote-definition-ByWh1N3S.js} +9 -5
  16. package/dist/{footnote-reference-DvAxMjRZ.js → footnote-reference-BJ4J7BFo.js} +5 -1
  17. package/dist/{heading-g87txbB0.js → heading-1fssqGGO.js} +6 -2
  18. package/dist/{html-BG83dEZJ.js → html-Be_6ezK6.js} +4 -0
  19. package/dist/{html-D7bGx0Cz.js → html-DfTs9nEm.js} +4 -0
  20. package/dist/icon-DE3AzDqz.js +4 -0
  21. package/dist/{icon-CpKYt1dR.js → icon-DcLTFhFW.js} +1 -1
  22. package/dist/{image-Dwe5A7RP.js → image-DXnmoID_.js} +4 -4
  23. package/dist/image-Dl-r78_E.js +9 -0
  24. package/dist/{image-CR28eDok.js → image-xPrAKT9D.js} +12 -8
  25. package/dist/index.css +130 -144
  26. package/dist/index.d.ts +170 -144
  27. package/dist/index.js +334 -219
  28. package/dist/{inline-code-E5uGvmnx.js → inline-code-B5lfHACE.js} +4 -0
  29. package/dist/{inline-math-BHDNxQ5R.js → inline-math-CPkpjl8t.js} +7 -3
  30. package/dist/{link-BiA46FMM.js → link-BACrkxRW.js} +8 -4
  31. package/dist/{list-D7QyoGUy.js → list-Cu8G46hK.js} +6 -2
  32. package/dist/{list-item-Cv8l3Ufd.js → list-item-BMgDS1tS.js} +6 -2
  33. package/dist/{math-BzuYH4PG.js → math-XsZX0VMw.js} +7 -3
  34. package/dist/{mermaid-BoiSJ4fF.js → mermaid-CQdSlhqn.js} +22 -8
  35. package/dist/{modal-DHGxvCt5.js → modal-C1riNMrs.js} +8 -5
  36. package/dist/modal-C7O4jt5-.js +4 -0
  37. package/dist/{node-list-D6zJX92N.js → node-list-7H-lIfUX.js} +10 -2
  38. package/dist/node-list-DMwAmH_n.js +4 -0
  39. package/dist/{paragraph-YTqe84Bm.js → paragraph-Cfd37HUK.js} +6 -2
  40. package/dist/previewers-C7PKsIbc.js +10 -0
  41. package/dist/segmented-BRTZXoDN.js +7 -0
  42. package/dist/{segmented-DDQZGL7l.js → segmented-C9j-IIDc.js} +1 -1
  43. package/dist/{shiki-DDfRFzy0.js → shiki-BoBbCakv.js} +7 -3
  44. package/dist/{strong-nPwCJEKq.js → strong-BzOBAWrG.js} +6 -2
  45. package/dist/{table-Dtpd-MnT.js → table-YY5M01Jm.js} +9 -5
  46. package/dist/{text-CfRWiRE0.js → text-DbHMEN3P.js} +4 -0
  47. package/dist/{thematic-break-DgOD2KmY.js → thematic-break-CdlhHAEZ.js} +4 -0
  48. package/dist/theme.css +2 -2
  49. package/dist/{tooltip-C4RiUZwy.js → tooltip-DarhJuZR.js} +3 -2
  50. package/dist/tooltip-vDDEbLwf.js +4 -0
  51. package/dist/vanilla-CzQw2_b4.js +4 -0
  52. package/dist/{vanilla-NR7MOE5P.js → vanilla-Z6d1vQmX.js} +1 -1
  53. package/dist/{yaml-DP0yfJyS.js → yaml-DL5ozHZ_.js} +4 -0
  54. package/dist/{zoom-container-CqZQ4X6w.js → zoom-container-DQMpHHGQ.js} +33 -9
  55. package/dist/zoom-container-JLbwB4gy.js +7 -0
  56. package/package.json +2 -1
  57. package/dist/button-BFS-gHGF.js +0 -6
  58. package/dist/code-block-CTM9VEwA.js +0 -10
  59. package/dist/dropdown-BQ3uynLf.js +0 -6
  60. package/dist/error-component-B_Vacrqa.js +0 -5
  61. package/dist/icon-BX3KKloR.js +0 -4
  62. package/dist/image-BtkXhzG1.js +0 -9
  63. package/dist/modal-CFOdkYNj.js +0 -4
  64. package/dist/node-list-BYDvt6bq.js +0 -4
  65. package/dist/previewers-Cpx1Wqu8.js +0 -10
  66. package/dist/segmented-CaVb5_Rp.js +0 -7
  67. package/dist/tooltip-BIvCaFUj.js +0 -4
  68. package/dist/vanilla-DfHiHWnr.js +0 -4
  69. package/dist/zoom-container-DtkZ07v1.js +0 -7
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { t as CODE_PREVIEWERS } from "./previewers-Cpx1Wqu8.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-BMXMKLLj.js";
3
- import { t as node_list_default } from "./node-list-D6zJX92N.js";
1
+ import { t as CODE_PREVIEWERS } from "./previewers-C7PKsIbc.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-CzUVrTt_.js";
3
+ import { t as node_list_default } from "./node-list-7H-lIfUX.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
6
  import { MarkdownItAsync } from "markdown-it-async";
@@ -49,46 +49,46 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
49
49
  //#endregion
50
50
  //#region src/components/renderers/index.ts
51
51
  const NODE_RENDERERS = {
52
- blockquote: defineAsyncComponent(() => import("./blockquote-CVFraiyL.js")),
53
- break: defineAsyncComponent(() => import("./break-CzrM3nW0.js")),
54
- code: defineAsyncComponent(() => import("./code-DwwmPoup.js")),
55
- delete: defineAsyncComponent(() => import("./delete-BRwEUU72.js")),
56
- emphasis: defineAsyncComponent(() => import("./emphasis-DblyP-Vp.js")),
57
- footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-BvZNKSLa.js")),
58
- footnoteReference: defineAsyncComponent(() => import("./footnote-reference-DvAxMjRZ.js")),
59
- heading: defineAsyncComponent(() => import("./heading-g87txbB0.js")),
60
- html: defineAsyncComponent(() => import("./html-BG83dEZJ.js")),
61
- image: defineAsyncComponent(() => import("./image-CR28eDok.js")),
62
- inlineCode: defineAsyncComponent(() => import("./inline-code-E5uGvmnx.js")),
63
- inlineMath: defineAsyncComponent(() => import("./inline-math-BHDNxQ5R.js")),
64
- link: defineAsyncComponent(() => import("./link-BiA46FMM.js")),
65
- list: defineAsyncComponent(() => import("./list-D7QyoGUy.js")),
66
- listItem: defineAsyncComponent(() => import("./list-item-Cv8l3Ufd.js")),
67
- math: defineAsyncComponent(() => import("./math-BzuYH4PG.js")),
68
- paragraph: defineAsyncComponent(() => import("./paragraph-YTqe84Bm.js")),
69
- strong: defineAsyncComponent(() => import("./strong-nPwCJEKq.js")),
70
- table: defineAsyncComponent(() => import("./table-Dtpd-MnT.js")),
71
- text: defineAsyncComponent(() => import("./text-CfRWiRE0.js")),
72
- thematicBreak: defineAsyncComponent(() => import("./thematic-break-DgOD2KmY.js")),
73
- yaml: defineAsyncComponent(() => import("./yaml-DP0yfJyS.js"))
52
+ blockquote: defineAsyncComponent(() => import("./blockquote-Crr-D7fY.js")),
53
+ break: defineAsyncComponent(() => import("./break-DoDPjOA0.js")),
54
+ code: defineAsyncComponent(() => import("./code-Bz8LM16H.js")),
55
+ delete: defineAsyncComponent(() => import("./delete-DFoiOzHW.js")),
56
+ emphasis: defineAsyncComponent(() => import("./emphasis-DvaBuxeK.js")),
57
+ footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-ByWh1N3S.js")),
58
+ footnoteReference: defineAsyncComponent(() => import("./footnote-reference-BJ4J7BFo.js")),
59
+ heading: defineAsyncComponent(() => import("./heading-1fssqGGO.js")),
60
+ html: defineAsyncComponent(() => import("./html-Be_6ezK6.js")),
61
+ image: defineAsyncComponent(() => import("./image-xPrAKT9D.js")),
62
+ inlineCode: defineAsyncComponent(() => import("./inline-code-B5lfHACE.js")),
63
+ inlineMath: defineAsyncComponent(() => import("./inline-math-CPkpjl8t.js")),
64
+ link: defineAsyncComponent(() => import("./link-BACrkxRW.js")),
65
+ list: defineAsyncComponent(() => import("./list-Cu8G46hK.js")),
66
+ listItem: defineAsyncComponent(() => import("./list-item-BMgDS1tS.js")),
67
+ math: defineAsyncComponent(() => import("./math-XsZX0VMw.js")),
68
+ paragraph: defineAsyncComponent(() => import("./paragraph-Cfd37HUK.js")),
69
+ strong: defineAsyncComponent(() => import("./strong-BzOBAWrG.js")),
70
+ table: defineAsyncComponent(() => import("./table-YY5M01Jm.js")),
71
+ text: defineAsyncComponent(() => import("./text-DbHMEN3P.js")),
72
+ thematicBreak: defineAsyncComponent(() => import("./thematic-break-CdlhHAEZ.js")),
73
+ yaml: defineAsyncComponent(() => import("./yaml-DL5ozHZ_.js"))
74
74
  };
75
75
 
76
76
  //#endregion
77
77
  //#region src/components/index.ts
78
78
  const UI = {
79
- Button: defineAsyncComponent(() => import("./button-BFS-gHGF.js")),
80
- CodeBlock: defineAsyncComponent(() => import("./code-block-CTM9VEwA.js")),
81
- Dropdown: defineAsyncComponent(() => import("./dropdown-BQ3uynLf.js")),
82
- ErrorComponent: defineAsyncComponent(() => import("./error-component-B_Vacrqa.js")),
83
- Icon: defineAsyncComponent(() => import("./icon-BX3KKloR.js")),
84
- Image: defineAsyncComponent(() => import("./image-BtkXhzG1.js")),
85
- Modal: defineAsyncComponent(() => import("./modal-CFOdkYNj.js")),
86
- NodeList: defineAsyncComponent(() => import("./node-list-BYDvt6bq.js")),
87
- Segmented: defineAsyncComponent(() => import("./segmented-CaVb5_Rp.js")),
79
+ Button: defineAsyncComponent(() => import("./button-Dw4uJRaD.js")),
80
+ CodeBlock: defineAsyncComponent(() => import("./code-block-Bitp8x1w.js")),
81
+ Dropdown: defineAsyncComponent(() => import("./dropdown-CSRjqK0u.js")),
82
+ ErrorComponent: defineAsyncComponent(() => import("./error-component-DDnC0bqw.js")),
83
+ Icon: defineAsyncComponent(() => import("./icon-DE3AzDqz.js")),
84
+ Image: defineAsyncComponent(() => import("./image-Dl-r78_E.js")),
85
+ Modal: defineAsyncComponent(() => import("./modal-C7O4jt5-.js")),
86
+ NodeList: defineAsyncComponent(() => import("./node-list-DMwAmH_n.js")),
87
+ Segmented: defineAsyncComponent(() => import("./segmented-BRTZXoDN.js")),
88
88
  Spin: defineAsyncComponent(() => import("./spin-DElj7VPm.js")),
89
89
  Table: defineAsyncComponent(() => import("./table-D6j6Gl87.js")),
90
- Tooltip: defineAsyncComponent(() => import("./tooltip-BIvCaFUj.js")),
91
- ZoomContainer: defineAsyncComponent(() => import("./zoom-container-DtkZ07v1.js"))
90
+ Tooltip: defineAsyncComponent(() => import("./tooltip-vDDEbLwf.js")),
91
+ ZoomContainer: defineAsyncComponent(() => import("./zoom-container-JLbwB4gy.js"))
92
92
  };
93
93
 
94
94
  //#endregion
@@ -2894,7 +2894,7 @@ function initializeContent(effects) {
2894
2894
  * Construct and its state.
2895
2895
  */
2896
2896
  /** @type {InitialConstruct} */
2897
- const document = { tokenize: initializeDocument };
2897
+ const document$1 = { tokenize: initializeDocument };
2898
2898
  /** @type {Construct} */
2899
2899
  const containerConstruct = { tokenize: tokenizeContainer };
2900
2900
  /**
@@ -8989,7 +8989,7 @@ var constructs_exports = /* @__PURE__ */ __export({
8989
8989
  attentionMarkers: () => attentionMarkers,
8990
8990
  contentInitial: () => contentInitial,
8991
8991
  disable: () => disable,
8992
- document: () => document$1,
8992
+ document: () => document$2,
8993
8993
  flow: () => flow$2,
8994
8994
  flowInitial: () => flowInitial,
8995
8995
  insideSpan: () => insideSpan,
@@ -8997,7 +8997,7 @@ var constructs_exports = /* @__PURE__ */ __export({
8997
8997
  text: () => text$3
8998
8998
  });
8999
8999
  /** @satisfies {Extension['document']} */
9000
- const document$1 = {
9000
+ const document$2 = {
9001
9001
  [42]: list$2,
9002
9002
  [43]: list$2,
9003
9003
  [45]: list$2,
@@ -9552,7 +9552,7 @@ function parse(options) {
9552
9552
  constructs: combineExtensions([constructs_exports, ...(options || {}).extensions || []]),
9553
9553
  content: create$1(content),
9554
9554
  defined: [],
9555
- document: create$1(document),
9555
+ document: create$1(document$1),
9556
9556
  flow: create$1(flow$1),
9557
9557
  lazy: {},
9558
9558
  string: create$1(string),
@@ -19708,6 +19708,82 @@ const quoteTaskListPattern = /^>\s*- \[[x ]\]/i;
19708
19708
  const quoteIncompleteTaskListPattern = /^>\s*-\s*\[\s*$/;
19709
19709
  const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
19710
19710
 
19711
+ //#endregion
19712
+ //#region src/preprocess/utils.ts
19713
+ /**
19714
+ * Utility functions for preprocessing markdown content
19715
+ */
19716
+ /**
19717
+ * Find the start index of the last paragraph in content
19718
+ * A paragraph is defined as content after the last blank line
19719
+ *
19720
+ * @param lines - Array of lines from content.split('\n')
19721
+ * @param skipTrailingEmpty - If true, skip the last element if it's empty (from trailing \n)
19722
+ * @returns The start index of the last paragraph
19723
+ */
19724
+ function findLastParagraphStart(lines, skipTrailingEmpty = false) {
19725
+ for (let i = lines.length - 1; i >= 0; i--) {
19726
+ const line = lines[i];
19727
+ if (line === void 0) continue;
19728
+ if (skipTrailingEmpty && i === lines.length - 1 && line.trim() === "") continue;
19729
+ if (line.trim() === "") return i + 1;
19730
+ }
19731
+ return 0;
19732
+ }
19733
+ /**
19734
+ * Get the last paragraph and its start index
19735
+ *
19736
+ * @param content - Markdown content
19737
+ * @param skipTrailingEmpty - If true, skip trailing empty line when finding paragraph start
19738
+ * @returns Object with lastParagraph and startIndex
19739
+ */
19740
+ function getLastParagraphWithIndex(content$2, skipTrailingEmpty = false) {
19741
+ const lines = content$2.split("\n");
19742
+ const startIndex = findLastParagraphStart(lines, skipTrailingEmpty);
19743
+ return {
19744
+ lastParagraph: lines.slice(startIndex).join("\n"),
19745
+ startIndex
19746
+ };
19747
+ }
19748
+ /**
19749
+ * Find the index of the last non-empty line
19750
+ *
19751
+ * @param lines - Array of lines
19752
+ * @returns The index of the last non-empty line, or -1 if all lines are empty
19753
+ */
19754
+ function findLastNonEmptyLineIndex(lines) {
19755
+ for (let i = lines.length - 1; i >= 0; i--) {
19756
+ const line = lines[i];
19757
+ if (line && line.trim() !== "") return i;
19758
+ }
19759
+ return -1;
19760
+ }
19761
+ /**
19762
+ * Calculate the absolute position in content from a relative position in a paragraph
19763
+ *
19764
+ * @param paragraphStartIndex - The line index where the paragraph starts
19765
+ * @param relativePos - The position relative to the paragraph start
19766
+ * @param lines - All lines from content.split('\n')
19767
+ * @returns The absolute position in the full content
19768
+ */
19769
+ function calculateAbsolutePosition(paragraphStartIndex, relativePos, lines) {
19770
+ if (paragraphStartIndex === 0) return relativePos;
19771
+ const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19772
+ return beforeParagraph.length > 0 ? beforeParagraph.length + 1 + relativePos : relativePos;
19773
+ }
19774
+ /**
19775
+ * Calculate the paragraph offset for absolute position calculations
19776
+ *
19777
+ * @param paragraphStartIndex - The line index where the paragraph starts
19778
+ * @param lines - All lines from content.split('\n')
19779
+ * @returns The offset to add to relative positions
19780
+ */
19781
+ function calculateParagraphOffset(paragraphStartIndex, lines) {
19782
+ if (paragraphStartIndex === 0) return 0;
19783
+ const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19784
+ return beforeParagraph.length > 0 ? beforeParagraph.length + 1 : 0;
19785
+ }
19786
+
19711
19787
  //#endregion
19712
19788
  //#region src/preprocess/code.ts
19713
19789
  /**
@@ -19740,10 +19816,13 @@ const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
19740
19816
  * // Returns: '```' (no completion, code block has no content)
19741
19817
  */
19742
19818
  function fixCode(content$2) {
19819
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
19820
+ const isInsideCodeBlock = (codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1;
19743
19821
  const cleaned = removeTrailingIncompleteBackticks(content$2);
19744
19822
  const wasCleanedUp = cleaned !== content$2;
19745
19823
  content$2 = cleaned;
19746
- if (!wasCleanedUp) content$2 = fixCodeBlock(content$2);
19824
+ if (isInsideCodeBlock && wasCleanedUp) content$2 = fixCodeBlock(content$2);
19825
+ else if (!wasCleanedUp) content$2 = fixCodeBlock(content$2);
19747
19826
  if (!wasCleanedUp) content$2 = fixInlineCode(content$2);
19748
19827
  return content$2;
19749
19828
  }
@@ -19761,13 +19840,8 @@ function removeTrailingIncompleteBackticks(content$2) {
19761
19840
  const afterBackticks = content$2.substring(backtickPos + backtickSequence.length);
19762
19841
  if (afterBackticks.trim().length > 0) return content$2;
19763
19842
  if (backtickSequence.length === 1) {
19764
- const lines = beforeBackticks.split("\n");
19765
- let paragraphStartIndex = 0;
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);
19843
+ const { lastParagraph } = getLastParagraphWithIndex(beforeBackticks);
19844
+ const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
19771
19845
  const count = backticks ? backticks.length : 0;
19772
19846
  const codeBlockMatches = beforeBackticks.match(tripleBacktickPattern);
19773
19847
  const codeBlockCount = codeBlockMatches ? codeBlockMatches.length : 0;
@@ -19807,12 +19881,7 @@ function fixInlineCode(content$2) {
19807
19881
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
19808
19882
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
19809
19883
  const lines = content$2.split("\n");
19810
- let paragraphStartIndex = 0;
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");
19884
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19816
19885
  const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
19817
19886
  if ((backticks ? backticks.length : 0) % 2 === 1) {
19818
19887
  let lastBacktickPos = -1;
@@ -19834,8 +19903,7 @@ function fixInlineCode(content$2) {
19834
19903
  }
19835
19904
  }
19836
19905
  if (lastBacktickPos !== -1) {
19837
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19838
- const actualPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastBacktickPos;
19906
+ const actualPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastBacktickPos;
19839
19907
  if (content$2.substring(actualPos + 1).trim().length > 0) return `${content$2}\``;
19840
19908
  else return content$2.slice(0, actualPos) + content$2.slice(actualPos + 1);
19841
19909
  }
@@ -19867,13 +19935,7 @@ function fixInlineCode(content$2) {
19867
19935
  * // Returns: 'List item\n\n~~' (no completion, ~~ has no content)
19868
19936
  */
19869
19937
  function fixDelete(content$2) {
19870
- const lines = content$2.split("\n");
19871
- let paragraphStartIndex = 0;
19872
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19873
- paragraphStartIndex = i + 1;
19874
- break;
19875
- }
19876
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
19938
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19877
19939
  const matches = lastParagraph.match(doubleTildePattern);
19878
19940
  const count = matches ? matches.length : 0;
19879
19941
  if (content$2.endsWith("~") && !content$2.endsWith("~~")) {
@@ -19891,7 +19953,7 @@ function fixDelete(content$2) {
19891
19953
  const lastTildePos = lastParagraph.lastIndexOf("~~");
19892
19954
  const afterLast = lastParagraph.substring(lastTildePos + 2);
19893
19955
  if (afterLast.trim().length > 0) return `${content$2}~~`;
19894
- else return content$2.substring(0, content$2.length - afterLast.length - 2);
19956
+ else return content$2.substring(0, content$2.length - afterLast.length - 2).trimEnd();
19895
19957
  }
19896
19958
  return content$2;
19897
19959
  }
@@ -19906,34 +19968,42 @@ function fixDelete(content$2) {
19906
19968
  */
19907
19969
  function fixEmphasis(content$2) {
19908
19970
  const lines = content$2.split("\n");
19909
- let paragraphStartIndex = 0;
19910
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19911
- paragraphStartIndex = i + 1;
19912
- break;
19913
- }
19914
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
19971
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19915
19972
  const withoutDoubleAsterisk = lastParagraph.replace(doubleAsteriskPattern, "");
19916
19973
  const asteriskMatches = withoutDoubleAsterisk.match(singleAsteriskPattern);
19917
- if ((asteriskMatches ? asteriskMatches.length : 0) % 2 === 1) {
19918
- const lastStarPos = withoutDoubleAsterisk.lastIndexOf("*");
19919
- if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0) return `${content$2}*`;
19920
- else {
19921
- let result = content$2.slice(0, -1);
19922
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19923
- return result;
19924
- }
19925
- }
19974
+ const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
19926
19975
  const withoutDoubleUnderscore = lastParagraph.replace(doubleUnderscorePattern, "");
19927
19976
  const underscoreMatches = withoutDoubleUnderscore.match(singleUnderscorePattern);
19928
- if ((underscoreMatches ? underscoreMatches.length : 0) % 2 === 1) {
19977
+ const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
19978
+ let needsAsteriskCompletion = false;
19979
+ let needsUnderscoreCompletion = false;
19980
+ let needsAsteriskRemoval = false;
19981
+ let needsUnderscoreRemoval = false;
19982
+ if (asteriskCount % 2 === 1) {
19983
+ const lastStarPos = withoutDoubleAsterisk.lastIndexOf("*");
19984
+ if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0) needsAsteriskCompletion = true;
19985
+ else needsAsteriskRemoval = true;
19986
+ }
19987
+ if (underscoreCount % 2 === 1) {
19929
19988
  const lastUnderscorePos = withoutDoubleUnderscore.lastIndexOf("_");
19930
- if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0) return `${content$2}_`;
19931
- else {
19932
- let result = content$2.slice(0, -1);
19933
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19934
- return result;
19935
- }
19989
+ if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0) needsUnderscoreCompletion = true;
19990
+ else needsUnderscoreRemoval = true;
19991
+ }
19992
+ if (needsAsteriskRemoval) {
19993
+ let result = content$2.slice(0, -1).trimEnd();
19994
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19995
+ return result;
19936
19996
  }
19997
+ if (needsUnderscoreRemoval) {
19998
+ const absoluteLastUnderscorePos = calculateParagraphOffset(paragraphStartIndex, lines) + withoutDoubleUnderscore.lastIndexOf("_");
19999
+ let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
20000
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20001
+ return result;
20002
+ }
20003
+ if (needsAsteriskCompletion && needsUnderscoreCompletion) if (withoutDoubleAsterisk.indexOf("*") < withoutDoubleUnderscore.indexOf("_")) return `${content$2}_*`;
20004
+ else return `${content$2}*_`;
20005
+ if (needsAsteriskCompletion) return `${content$2}*`;
20006
+ if (needsUnderscoreCompletion) return `${content$2}_`;
19937
20007
  return content$2;
19938
20008
  }
19939
20009
 
@@ -20007,47 +20077,42 @@ function fixFootnote(content$2) {
20007
20077
  if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
20008
20078
  }
20009
20079
  }
20010
- for (let i = 0; i < backtickPositions.length; i += 2) if (i + 1 < backtickPositions.length) {
20080
+ for (let i = 0; i < backtickPositions.length; i += 2) {
20011
20081
  const start = backtickPositions[i];
20012
- const end = backtickPositions[i + 1] + 1;
20013
- inlineCodeRanges.push({
20082
+ const end = backtickPositions[i + 1];
20083
+ if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
20014
20084
  start,
20015
- end
20085
+ end: end + 1
20016
20086
  });
20017
20087
  }
20018
20088
  const footnoteDefRanges = [];
20019
20089
  let lineOffset = 0;
20020
20090
  for (let i = 0; i < lines.length; i++) {
20021
20091
  const line = lines[i];
20022
- if (isFootnoteDefLine(line)) {
20092
+ if (line && isFootnoteDefLine(line)) {
20023
20093
  const lineEnd = lineOffset + line.length;
20024
20094
  footnoteDefRanges.push({
20025
20095
  start: lineOffset,
20026
20096
  end: lineEnd
20027
20097
  });
20028
20098
  }
20029
- lineOffset += line.length + 1;
20099
+ if (line) lineOffset += line.length + 1;
20030
20100
  }
20031
- let lastParagraphStartIndex = 0;
20032
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20033
- lastParagraphStartIndex = i + 1;
20034
- break;
20035
- }
20036
- const lastParagraph = lines.slice(lastParagraphStartIndex).join("\n");
20101
+ const { lastParagraph, startIndex: lastParagraphStartIndex } = getLastParagraphWithIndex(content$2);
20037
20102
  let result = content$2;
20038
20103
  if (incompleteFootnoteRefPattern.test(lastParagraph)) {
20039
20104
  const incompleteRefPos = lastParagraph.lastIndexOf("[^");
20040
20105
  if (incompleteRefPos !== -1) {
20041
- const absolutePos = lastParagraphStartIndex > 0 ? lines.slice(0, lastParagraphStartIndex).join("\n").length + 1 + incompleteRefPos : incompleteRefPos;
20106
+ const absolutePos = calculateAbsolutePosition(lastParagraphStartIndex, incompleteRefPos, lines);
20042
20107
  const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20043
20108
  const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20044
20109
  if (!isInCodeBlock && !isInInlineCode) {
20045
20110
  const lineEnd = lastParagraph.indexOf("\n", incompleteRefPos);
20046
20111
  const refEnd = lineEnd !== -1 ? lineEnd : lastParagraph.length;
20047
- const beforeLastParagraph = lines.slice(0, lastParagraphStartIndex).join("\n");
20048
- const paragraphOffset = beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0;
20049
- const absoluteStart = paragraphOffset + incompleteRefPos;
20050
- const absoluteEnd = paragraphOffset + refEnd;
20112
+ let refStart = incompleteRefPos;
20113
+ if (refStart > 0 && lastParagraph[refStart - 1] === " ") refStart--;
20114
+ const absoluteStart = calculateAbsolutePosition(lastParagraphStartIndex, refStart, lines);
20115
+ const absoluteEnd = calculateAbsolutePosition(lastParagraphStartIndex, refEnd, lines);
20051
20116
  result = result.substring(0, absoluteStart) + result.substring(absoluteEnd);
20052
20117
  content$2 = result;
20053
20118
  codeBlockRanges.length = 0;
@@ -20081,12 +20146,12 @@ function fixFootnote(content$2) {
20081
20146
  if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
20082
20147
  }
20083
20148
  }
20084
- for (let i = 0; i < backtickPositions.length; i += 2) if (i + 1 < backtickPositions.length) {
20149
+ for (let i = 0; i < backtickPositions.length; i += 2) {
20085
20150
  const start = backtickPositions[i];
20086
- const end = backtickPositions[i + 1] + 1;
20087
- inlineCodeRanges.push({
20151
+ const end = backtickPositions[i + 1];
20152
+ if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
20088
20153
  start,
20089
- end
20154
+ end: end + 1
20090
20155
  });
20091
20156
  }
20092
20157
  }
@@ -20095,8 +20160,8 @@ function fixFootnote(content$2) {
20095
20160
  const refPositions = [];
20096
20161
  let refMatch = footnoteRefPattern.exec(content$2);
20097
20162
  while (refMatch !== null) {
20098
- const absolutePos = refMatch.index;
20099
- const refText = refMatch[0];
20163
+ const absolutePos = refMatch.index ?? 0;
20164
+ const refText = refMatch[0] ?? "";
20100
20165
  const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20101
20166
  const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20102
20167
  const isInFootnoteDef = footnoteDefRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
@@ -20113,7 +20178,11 @@ function fixFootnote(content$2) {
20113
20178
  if (refPositions.length === 0) return content$2;
20114
20179
  for (let i = refPositions.length - 1; i >= 0; i--) {
20115
20180
  const ref$1 = refPositions[i];
20116
- if (!definedLabels.has(ref$1.label)) result = result.substring(0, ref$1.start) + result.substring(ref$1.end);
20181
+ if (ref$1 && !definedLabels.has(ref$1.label)) {
20182
+ let refStart = ref$1.start;
20183
+ if (refStart > 0 && result[refStart - 1] === " ") refStart--;
20184
+ result = result.substring(0, refStart) + result.substring(ref$1.end);
20185
+ }
20117
20186
  }
20118
20187
  return result;
20119
20188
  }
@@ -20149,15 +20218,11 @@ function fixFootnote(content$2) {
20149
20218
  * // Returns: '$$\n' (no completion, this is block math)
20150
20219
  */
20151
20220
  function fixInlineMath(content$2) {
20221
+ if (content$2 === "$") return "";
20152
20222
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
20153
20223
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20154
20224
  const lines = content$2.split("\n");
20155
- let paragraphStartIndex = 0;
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");
20225
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
20161
20226
  let withoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
20162
20227
  withoutCodeBlocks = withoutCodeBlocks.replace(/`[^`\n]+`/g, "");
20163
20228
  const dollarMatches = withoutCodeBlocks.match(doubleDollarPattern);
@@ -20165,36 +20230,22 @@ function fixInlineMath(content$2) {
20165
20230
  const lastDollarPos = findLastDollarPairNotInCodeBlock(lastParagraph);
20166
20231
  if (lastDollarPos === -1) return content$2;
20167
20232
  let afterLast = lastParagraph.substring(lastDollarPos + 2);
20233
+ if (afterLast.startsWith("\n") || afterLast.includes("\n")) return content$2;
20168
20234
  if (afterLast.trim() === "$") return content$2;
20169
20235
  let shouldRemoveTrailingDollar = false;
20170
20236
  if (afterLast.endsWith("$") && !afterLast.endsWith("$$")) {
20171
20237
  shouldRemoveTrailingDollar = true;
20172
20238
  afterLast = afterLast.slice(0, -1);
20173
20239
  }
20174
- const hasContentAfter = (afterLast.split("\n")[0] ?? "").trim().length > 0;
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) {
20240
+ if (afterLast.trim().length > 0) {
20188
20241
  if (shouldRemoveTrailingDollar) {
20189
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
20190
- const actualLastDollarPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastDollarPos;
20242
+ const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
20191
20243
  return `${content$2.substring(0, actualLastDollarPos + 2)}${lastParagraph.substring(lastDollarPos + 2, lastParagraph.length - 1)}$$`;
20192
20244
  }
20193
20245
  return `${content$2}$$`;
20194
20246
  } else {
20195
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
20196
- const actualLastDollarPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastDollarPos;
20197
- return content$2.slice(0, actualLastDollarPos) + content$2.slice(actualLastDollarPos + 2);
20247
+ const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
20248
+ return content$2.slice(0, actualLastDollarPos).trimEnd();
20198
20249
  }
20199
20250
  }
20200
20251
  return content$2;
@@ -20275,30 +20326,25 @@ function findLastDollarPairNotInCodeBlock(text$4) {
20275
20326
  * // Removes trailing standalone bracket and trailing newline
20276
20327
  */
20277
20328
  function fixLink(content$2) {
20278
- var _lines$lastNonEmptyLi;
20279
20329
  const lines = content$2.split("\n");
20280
- let paragraphStartIndex = 0;
20281
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20282
- paragraphStartIndex = i + 1;
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--;
20330
+ const { lastParagraph } = getLastParagraphWithIndex(content$2);
20331
+ const lastNonEmptyLineIndex = findLastNonEmptyLineIndex(lines);
20288
20332
  if (lastNonEmptyLineIndex >= 0) {
20289
20333
  const lastLine = lines[lastNonEmptyLineIndex];
20290
- if (trailingStandaloneBracketPattern.test(lastLine)) {
20291
- const bracketMatch = lastLine.match(trailingStandaloneBracketPattern);
20292
- if (bracketMatch) {
20293
- const bracket = bracketMatch[1];
20294
- const bracketPos = lastLine.lastIndexOf(bracket);
20295
- if (lastLine.substring(bracketPos + bracket.length).trim().length === 0) {
20296
- const newLine = lastLine.substring(0, bracketPos);
20297
- const newLines = [...lines];
20298
- newLines[lastNonEmptyLineIndex] = newLine;
20299
- if (lastNonEmptyLineIndex + 1 < newLines.length && newLines[lastNonEmptyLineIndex + 1].trim() === "") newLines.splice(lastNonEmptyLineIndex + 1, 1);
20300
- return newLines.join("\n");
20334
+ if (!lastLine) return content$2;
20335
+ const standaloneBracketMatch = lastLine.match(/(!?\[)\s*$/);
20336
+ if (standaloneBracketMatch && standaloneBracketMatch[1]) {
20337
+ const bracket = standaloneBracketMatch[1];
20338
+ const bracketPos = lastLine.lastIndexOf(bracket);
20339
+ if (lastLine.substring(bracketPos + bracket.length).trim().length === 0) {
20340
+ const newLine = lastLine.substring(0, bracketPos).trimEnd();
20341
+ const newLines = [...lines];
20342
+ newLines[lastNonEmptyLineIndex] = newLine;
20343
+ if (lastNonEmptyLineIndex + 1 < newLines.length) {
20344
+ const nextLine = newLines[lastNonEmptyLineIndex + 1];
20345
+ if (nextLine !== void 0 && nextLine.trim() === "") newLines.splice(lastNonEmptyLineIndex + 1, 1);
20301
20346
  }
20347
+ return newLines.join("\n");
20302
20348
  }
20303
20349
  }
20304
20350
  }
@@ -20336,33 +20382,92 @@ function fixLink(content$2) {
20336
20382
  * // Returns: 'List item\n\n**' (no completion, ** has no content)
20337
20383
  */
20338
20384
  function fixStrong(content$2) {
20339
- const lines = content$2.split("\n");
20340
- let paragraphStartIndex = 0;
20341
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20342
- paragraphStartIndex = i + 1;
20343
- break;
20344
- }
20345
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
20385
+ if (content$2 === "*" || content$2 === "_") return "";
20386
+ const { lastParagraph } = getLastParagraphWithIndex(content$2);
20387
+ const endsWithSingleAsterisk = content$2.endsWith("*") && !content$2.endsWith("**");
20388
+ const endsWithSingleUnderscore = content$2.endsWith("_") && !content$2.endsWith("__");
20346
20389
  const asteriskMatches = lastParagraph.match(doubleAsteriskPattern);
20347
- if ((asteriskMatches ? asteriskMatches.length : 0) % 2 === 1) {
20390
+ const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
20391
+ const underscoreMatches = lastParagraph.match(doubleUnderscorePattern);
20392
+ const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
20393
+ let needsAsteriskCompletion = false;
20394
+ let needsUnderscoreCompletion = false;
20395
+ let needsAsteriskRemoval = false;
20396
+ let needsUnderscoreRemoval = false;
20397
+ if (asteriskCount % 2 === 1) {
20348
20398
  const lastStarPos = lastParagraph.lastIndexOf("**");
20349
- if (lastParagraph.substring(lastStarPos + 2).trim().length > 0) return `${content$2}**`;
20350
- else {
20351
- let result = content$2.slice(0, -2);
20352
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20353
- return result;
20354
- }
20399
+ if (lastParagraph.substring(lastStarPos + 2).trim().length > 0) needsAsteriskCompletion = true;
20400
+ else needsAsteriskRemoval = true;
20355
20401
  }
20356
- const underscoreMatches = lastParagraph.match(doubleUnderscorePattern);
20357
- if ((underscoreMatches ? underscoreMatches.length : 0) % 2 === 1) {
20402
+ if (underscoreCount % 2 === 1) {
20358
20403
  const lastUnderscorePos = lastParagraph.lastIndexOf("__");
20359
- if (lastParagraph.substring(lastUnderscorePos + 2).trim().length > 0) return `${content$2}__`;
20360
- else {
20361
- let result = content$2.slice(0, -2);
20362
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20363
- return result;
20404
+ if (lastParagraph.substring(lastUnderscorePos + 2).trim().length > 0) needsUnderscoreCompletion = true;
20405
+ else needsUnderscoreRemoval = true;
20406
+ }
20407
+ let removedTrailingSingle = false;
20408
+ if (endsWithSingleAsterisk && (needsAsteriskCompletion || needsAsteriskRemoval)) {
20409
+ content$2 = content$2.slice(0, -1);
20410
+ removedTrailingSingle = true;
20411
+ const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
20412
+ const newAsteriskMatches = newLastParagraph.match(doubleAsteriskPattern);
20413
+ if ((newAsteriskMatches ? newAsteriskMatches.length : 0) % 2 === 1) {
20414
+ const lastStarPos = newLastParagraph.lastIndexOf("**");
20415
+ if (newLastParagraph.substring(lastStarPos + 2).trim().length > 0) {
20416
+ needsAsteriskCompletion = true;
20417
+ needsAsteriskRemoval = false;
20418
+ } else {
20419
+ needsAsteriskRemoval = true;
20420
+ needsAsteriskCompletion = false;
20421
+ }
20422
+ }
20423
+ }
20424
+ if (endsWithSingleUnderscore && (needsUnderscoreCompletion || needsUnderscoreRemoval)) {
20425
+ content$2 = content$2.slice(0, -1);
20426
+ removedTrailingSingle = true;
20427
+ const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
20428
+ const newUnderscoreMatches = newLastParagraph.match(doubleUnderscorePattern);
20429
+ if ((newUnderscoreMatches ? newUnderscoreMatches.length : 0) % 2 === 1) {
20430
+ const lastUnderscorePos = newLastParagraph.lastIndexOf("__");
20431
+ if (newLastParagraph.substring(lastUnderscorePos + 2).trim().length > 0) {
20432
+ needsUnderscoreCompletion = true;
20433
+ needsUnderscoreRemoval = false;
20434
+ } else {
20435
+ needsUnderscoreRemoval = true;
20436
+ needsUnderscoreCompletion = false;
20437
+ }
20364
20438
  }
20365
20439
  }
20440
+ if (needsAsteriskRemoval) {
20441
+ let result = content$2.slice(0, -2).trimEnd();
20442
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20443
+ return result;
20444
+ }
20445
+ if (needsUnderscoreRemoval) {
20446
+ const { lastParagraph: newLastParagraph, startIndex: newParagraphStartIndex } = getLastParagraphWithIndex(content$2);
20447
+ const lastUnderscorePos = newLastParagraph.lastIndexOf("__");
20448
+ const absoluteLastUnderscorePos = calculateParagraphOffset(newParagraphStartIndex, content$2.split("\n")) + lastUnderscorePos;
20449
+ let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
20450
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20451
+ return result;
20452
+ }
20453
+ if (needsAsteriskCompletion && needsUnderscoreCompletion) if (lastParagraph.indexOf("**") < lastParagraph.indexOf("__")) return `${content$2}__**`;
20454
+ else return `${content$2}**__`;
20455
+ if (needsAsteriskCompletion) {
20456
+ if (!removedTrailingSingle) {
20457
+ const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
20458
+ const singleAsteriskMatches = currentLastParagraph.replace(doubleAsteriskPattern, "").match(singleAsteriskPattern);
20459
+ if ((singleAsteriskMatches ? singleAsteriskMatches.length : 0) % 2 === 1) return `${content$2}***`;
20460
+ }
20461
+ return `${content$2}**`;
20462
+ }
20463
+ if (needsUnderscoreCompletion) {
20464
+ if (!removedTrailingSingle) {
20465
+ const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
20466
+ const singleUnderscoreMatches = currentLastParagraph.replace(doubleUnderscorePattern, "").match(singleUnderscorePattern);
20467
+ if ((singleUnderscoreMatches ? singleUnderscoreMatches.length : 0) % 2 === 1) return `${content$2}___`;
20468
+ }
20469
+ return `${content$2}__`;
20470
+ }
20366
20471
  return content$2;
20367
20472
  }
20368
20473
 
@@ -20397,25 +20502,18 @@ function fixStrong(content$2) {
20397
20502
  function fixTable(content$2) {
20398
20503
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
20399
20504
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20400
- const lines = content$2.split("\n");
20401
- let paragraphStartIndex = 0;
20402
- for (let i = lines.length - 1; i >= 0; i--) {
20403
- const line = lines[i];
20404
- if (i === lines.length - 1 && line.trim() === "") continue;
20405
- if (line.trim() === "") {
20406
- paragraphStartIndex = i + 1;
20407
- break;
20408
- }
20409
- }
20410
- const paragraphLines = lines.slice(paragraphStartIndex).join("\n").split("\n").filter((line) => line.trim() !== "");
20505
+ const { lastParagraph } = getLastParagraphWithIndex(content$2, true);
20506
+ const paragraphLines = lastParagraph.split("\n").filter((line) => line.trim() !== "");
20411
20507
  if (paragraphLines.length === 0) return content$2;
20412
20508
  let headerRowIndex = -1;
20413
20509
  let headerRow = "";
20414
20510
  for (let i = 0; i < paragraphLines.length; i++) {
20415
- const line = paragraphLines[i].trim();
20416
- if (tableRowPattern.test(line) || line.startsWith("|") && line.length > 1) {
20511
+ const line = paragraphLines[i];
20512
+ if (!line) continue;
20513
+ const trimmedLine = line.trim();
20514
+ if (tableRowPattern.test(trimmedLine) || trimmedLine.startsWith("|") && trimmedLine.length > 1) {
20417
20515
  headerRowIndex = i;
20418
- headerRow = line;
20516
+ headerRow = trimmedLine;
20419
20517
  break;
20420
20518
  }
20421
20519
  }
@@ -20435,7 +20533,9 @@ function fixTable(content$2) {
20435
20533
  if (newContent.endsWith("\n")) return `${newContent}${separator}`;
20436
20534
  else return `${newContent}\n${separator}`;
20437
20535
  }
20438
- const nextLine = paragraphLines[headerRowIndex + 1].trim();
20536
+ const nextLineRaw = paragraphLines[headerRowIndex + 1];
20537
+ if (!nextLineRaw) return content$2;
20538
+ const nextLine = nextLineRaw.trim();
20439
20539
  if (separatorPattern.test(nextLine)) {
20440
20540
  if ((nextLine.match(/\|/g) || []).length - 1 === headerColumns) {
20441
20541
  if (!isHeaderComplete) return `${beforeHeaderRow}${completedHeaderRow}${afterHeaderRow}`;
@@ -20445,6 +20545,7 @@ function fixTable(content$2) {
20445
20545
  const afterLines = afterHeaderRow.split("\n");
20446
20546
  if (afterLines.length > 1) {
20447
20547
  const nextLineInContent = afterLines[1];
20548
+ if (!nextLineInContent) return content$2;
20448
20549
  if (nextLineInContent.startsWith("|") && nextLineInContent.includes("-")) {
20449
20550
  const remainingLines = afterLines.slice(2).join("\n");
20450
20551
  const newHeader = isHeaderComplete ? headerRow : completedHeaderRow;
@@ -20500,26 +20601,12 @@ function fixTaskList(content$2) {
20500
20601
  const lines = content$2.split("\n");
20501
20602
  if (lines.length === 0) return content$2;
20502
20603
  const lastLine = lines[lines.length - 1];
20503
- if (quoteIncompleteTaskListPattern.test(lastLine)) {
20504
- const result = lines.slice(0, -1).join("\n");
20505
- if (lines.length > 1) return `${result}\n`;
20506
- return result;
20507
- }
20508
- if (quoteStandaloneDashPattern.test(lastLine) && !quoteTaskListPattern.test(lastLine)) {
20509
- const result = lines.slice(0, -1).join("\n");
20510
- if (lines.length > 1) return `${result}\n`;
20511
- return result;
20512
- }
20513
- if (incompleteTaskListPattern.test(lastLine)) {
20514
- const result = lines.slice(0, -1).join("\n");
20515
- if (lines.length > 1) return `${result}\n`;
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
- }
20604
+ if (!lastLine) return content$2;
20605
+ if (quoteIncompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20606
+ if (quoteStandaloneDashPattern.test(lastLine) && !quoteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20607
+ if (incompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20608
+ if (standaloneDashPattern.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20609
+ if (/^\s*-\s+$/.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20523
20610
  return content$2;
20524
20611
  }
20525
20612
 
@@ -20552,8 +20639,8 @@ function proprocessContent(content$2) {
20552
20639
  function normalize(content$2) {
20553
20640
  return flow([proprocessContent, preprocessLaTeX])(content$2);
20554
20641
  }
20555
- function preprocess(content$2) {
20556
- return flow([
20642
+ function preprocess(content$2, streamdown = true) {
20643
+ const tasks = [
20557
20644
  fixFootnote,
20558
20645
  fixStrong,
20559
20646
  fixEmphasis,
@@ -20562,9 +20649,10 @@ function preprocess(content$2) {
20562
20649
  fixTaskList,
20563
20650
  fixLink,
20564
20651
  fixTable,
20565
- fixInlineMath,
20566
- remend
20567
- ])(content$2);
20652
+ fixInlineMath
20653
+ ];
20654
+ if (streamdown) tasks.push(remend);
20655
+ return flow(tasks)(content$2);
20568
20656
  }
20569
20657
 
20570
20658
  //#endregion
@@ -20735,6 +20823,10 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20735
20823
  type: Object,
20736
20824
  required: false
20737
20825
  },
20826
+ uiOptions: {
20827
+ type: Object,
20828
+ required: false
20829
+ },
20738
20830
  isDark: {
20739
20831
  type: Boolean,
20740
20832
  required: false,
@@ -20769,15 +20861,16 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20769
20861
  setup(__props, { expose: __expose, emit: __emit }) {
20770
20862
  const props = __props;
20771
20863
  const emits = __emit;
20772
- const { mode, shikiOptions, mermaidOptions, isDark, enableAnimate } = toRefs(props);
20864
+ const { mode, shikiOptions, mermaidOptions, uiOptions, isDark, enableAnimate } = toRefs(props);
20773
20865
  const containerRef = ref();
20774
20866
  const { provideContext } = useContext();
20775
20867
  const markdownParser = new MarkdownParser({
20776
20868
  mode: props.mode,
20777
20869
  mdastOptions: props.mdastOptions,
20778
- postprocess: props.postprocess,
20870
+ normalize: props.normalize,
20779
20871
  preprocess: props.preprocess,
20780
- normalize: props.normalize
20872
+ postprocess: props.postprocess,
20873
+ extendMarkdownIt: props.extendMarkdownIt
20781
20874
  });
20782
20875
  const processed = computed(() => markdownParser.parseMarkdown(props.content));
20783
20876
  const parsedNodes = computed(() => processed.value.nodes);
@@ -20797,10 +20890,29 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20797
20890
  function getContainer() {
20798
20891
  return containerRef.value;
20799
20892
  }
20893
+ function getOverlayContainer() {
20894
+ return document.querySelector("#stream-markdown-overlay");
20895
+ }
20800
20896
  const { preload: preloadShiki, dispose: disposeShiki } = useShiki({ shikiOptions });
20801
20897
  const { preload: preloadMermaid, dispose: disposeMermaid } = useMermaid({ mermaidOptions });
20802
20898
  const { preload: preloadKatex, dispose: disposeKatex } = useKatex();
20899
+ function ensureOverlayContainer() {
20900
+ if (!getOverlayContainer()) {
20901
+ const div = document.createElement("div");
20902
+ div.id = "stream-markdown-overlay";
20903
+ div.classList.add("stream-markdown-overlay");
20904
+ div.classList.add(isDark.value ? "dark" : "light");
20905
+ document.body.appendChild(div);
20906
+ }
20907
+ }
20908
+ function updateOverlayContainerTheme() {
20909
+ const overlayContainer = getOverlayContainer();
20910
+ if (!overlayContainer) return;
20911
+ overlayContainer.classList.toggle("dark", isDark.value);
20912
+ overlayContainer.classList.toggle("light", !isDark.value);
20913
+ }
20803
20914
  async function bootstrap() {
20915
+ ensureOverlayContainer();
20804
20916
  const tasks = [
20805
20917
  preloadShiki(),
20806
20918
  preloadMermaid(),
@@ -20814,13 +20926,16 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20814
20926
  onMounted(bootstrap);
20815
20927
  watch(() => props.mode, () => markdownParser.updateMode(props.mode));
20816
20928
  watch(() => props.locale, () => loadLocaleMessages(props.locale));
20929
+ watch(() => props.isDark, () => updateOverlayContainerTheme());
20817
20930
  provideContext({
20818
20931
  mode,
20819
20932
  icons,
20933
+ uiOptions,
20820
20934
  isDark,
20821
20935
  enableAnimate,
20822
20936
  parsedNodes,
20823
20937
  getContainer,
20938
+ getOverlayContainer,
20824
20939
  onCopied: (content$2) => {
20825
20940
  emits("copied", content$2);
20826
20941
  }