@pod-os/elements 0.41.0-rc.fcadbb6.0 → 0.41.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.
Files changed (104) hide show
  1. package/dist/cjs/{chunk.URTPIBTY-CyUQzrtC.js → chunk.URTPIBTY-C9cOc4B-.js} +2 -2
  2. package/dist/cjs/{chunk.XQ2OKYYA-Dfzydh50.js → chunk.XQ2OKYYA-CTZvRtz3.js} +3 -3
  3. package/dist/cjs/{chunk.ZGGPD2XJ-BhNheC5q.js → chunk.ZGGPD2XJ-BvGHEYp6.js} +1 -1
  4. package/dist/cjs/{class-map-DFvbJjpM.js → class-map-C9P5WsLw.js} +1 -1
  5. package/dist/cjs/elements.cjs.js +2 -2
  6. package/dist/cjs/{index-BP03J2RA.js → index-BPvAwpRj.js} +137 -33
  7. package/dist/cjs/{index-CFcC3IGM.js → index-CjKppELa.js} +2 -2
  8. package/dist/cjs/{jsonld-V2RB47OZ-B6QDxKa1.js → jsonld-V2RB47OZ-C8WVLsWC.js} +1 -1
  9. package/dist/cjs/loader.cjs.js +2 -2
  10. package/dist/cjs/pos-add-literal-value_3.cjs.entry.js +5 -5
  11. package/dist/cjs/pos-add-new-thing_32.cjs.entry.js +27 -10
  12. package/dist/cjs/pos-add-relation.cjs.entry.js +3 -3
  13. package/dist/cjs/pos-app-document-viewer.cjs.entry.js +1 -1
  14. package/dist/cjs/pos-app-generic.cjs.entry.js +1 -1
  15. package/dist/cjs/pos-app-image-viewer.cjs.entry.js +1 -1
  16. package/dist/cjs/pos-app-ldp-container.cjs.entry.js +1 -1
  17. package/dist/cjs/pos-app-rdf-document.cjs.entry.js +1 -1
  18. package/dist/cjs/pos-attachments.cjs.entry.js +1 -1
  19. package/dist/cjs/pos-case.cjs.entry.js +1 -1
  20. package/dist/cjs/pos-container-contents.cjs.entry.js +2 -2
  21. package/dist/cjs/pos-container-item_3.cjs.entry.js +4 -4
  22. package/dist/cjs/pos-document.cjs.entry.js +4 -4
  23. package/dist/cjs/pos-list.cjs.entry.js +1 -1
  24. package/dist/cjs/pos-markdown-document.cjs.entry.js +412 -122
  25. package/dist/cjs/pos-relations_2.cjs.entry.js +1 -1
  26. package/dist/cjs/pos-subjects.cjs.entry.js +2 -2
  27. package/dist/cjs/pos-switch.cjs.entry.js +1 -1
  28. package/dist/cjs/pos-tool-attachments.cjs.entry.js +1 -1
  29. package/dist/cjs/pos-value.cjs.entry.js +22 -2
  30. package/dist/collection/components/pos-description/pos-description.js +18 -3
  31. package/dist/collection/components/pos-label/pos-label.js +15 -4
  32. package/dist/collection/components/pos-value/pos-value.js +27 -4
  33. package/dist/components/index2.js +2 -2
  34. package/dist/components/pos-description2.js +1 -1
  35. package/dist/components/pos-label2.js +1 -1
  36. package/dist/components/pos-markdown-document2.js +1 -1
  37. package/dist/components/pos-value.js +1 -1
  38. package/dist/custom-elements.json +5 -3
  39. package/dist/elements/elements.esm.js +1 -1
  40. package/dist/elements/{p-33783890.entry.js → p-1b8c9b61.entry.js} +1 -1
  41. package/dist/elements/p-1bcdde10.entry.js +1 -0
  42. package/dist/elements/{p-2f122da6.entry.js → p-1e98efdc.entry.js} +1 -1
  43. package/dist/elements/{p-3ef3a9a9.entry.js → p-380d72c2.entry.js} +1 -1
  44. package/dist/elements/{p-31370224.entry.js → p-440a8508.entry.js} +1 -1
  45. package/dist/elements/{p-aca646a4.entry.js → p-4d349a89.entry.js} +1 -1
  46. package/dist/elements/{p-a234b3fe.entry.js → p-52443feb.entry.js} +1 -1
  47. package/dist/elements/{p-513f7548.entry.js → p-641e64fd.entry.js} +1 -1
  48. package/dist/elements/{p-DqO-cIHe.js → p-7TsXf0Xj.js} +1 -1
  49. package/dist/elements/{p-a78df72b.entry.js → p-941b9b51.entry.js} +1 -1
  50. package/dist/elements/{p-5506bf9a.entry.js → p-9b5c45b6.entry.js} +1 -1
  51. package/dist/elements/{p-DPNKR_cm.js → p-BKLehMby.js} +5 -5
  52. package/dist/elements/p-BzjgviTt.js +67 -0
  53. package/dist/elements/{p-DO6v4X9H.js → p-C-Ke6Sdx.js} +3 -3
  54. package/dist/elements/{p-spEUIGXI.js → p-CsdCh9hf.js} +1 -1
  55. package/dist/elements/{p-Bz2zblgU.js → p-KLP10Ef6.js} +7 -7
  56. package/dist/elements/{p-d31c55b9.entry.js → p-a62af5eb.entry.js} +1 -1
  57. package/dist/elements/{p-1e0bd264.entry.js → p-b30e9b9c.entry.js} +9 -9
  58. package/dist/elements/{p-5f8df3c2.entry.js → p-c1cb97ef.entry.js} +1 -1
  59. package/dist/elements/p-c60dc303.entry.js +1 -0
  60. package/dist/elements/{p-c4034954.entry.js → p-c697bb3c.entry.js} +1 -1
  61. package/dist/elements/{p-0febf76e.entry.js → p-c83d76f9.entry.js} +1 -1
  62. package/dist/elements/{p-4fa32d10.entry.js → p-ccfbad21.entry.js} +1 -1
  63. package/dist/elements/{p-e4eae182.entry.js → p-eadbef6c.entry.js} +1 -1
  64. package/dist/elements/p-f26842e5.entry.js +1 -0
  65. package/dist/elements/{p-17d63fec.entry.js → p-f57e26b7.entry.js} +1 -1
  66. package/dist/elements/{p-DpbuT47x.js → p-jSCnU8fW.js} +1 -1
  67. package/dist/esm/{chunk.URTPIBTY-DGDKVdvN.js → chunk.URTPIBTY-CndE5cVS.js} +2 -2
  68. package/dist/esm/{chunk.XQ2OKYYA-DY8d9BRU.js → chunk.XQ2OKYYA-BBXcL00i.js} +3 -3
  69. package/dist/esm/{chunk.ZGGPD2XJ-CLV8PNGL.js → chunk.ZGGPD2XJ-DGIJXk11.js} +1 -1
  70. package/dist/esm/{class-map-CtuZET5H.js → class-map-BaV3g1im.js} +1 -1
  71. package/dist/esm/elements.js +3 -3
  72. package/dist/esm/{index-CMbRpNym.js → index-CmKOSDim.js} +137 -33
  73. package/dist/esm/{index-spEUIGXI.js → index-CsdCh9hf.js} +1 -1
  74. package/dist/esm/{jsonld-V2RB47OZ-zn531VHn.js → jsonld-V2RB47OZ-CIDz9zb9.js} +1 -1
  75. package/dist/esm/loader.js +3 -3
  76. package/dist/esm/pos-add-literal-value_3.entry.js +5 -5
  77. package/dist/esm/pos-add-new-thing_32.entry.js +27 -10
  78. package/dist/esm/pos-add-relation.entry.js +3 -3
  79. package/dist/esm/pos-app-document-viewer.entry.js +1 -1
  80. package/dist/esm/pos-app-generic.entry.js +1 -1
  81. package/dist/esm/pos-app-image-viewer.entry.js +1 -1
  82. package/dist/esm/pos-app-ldp-container.entry.js +1 -1
  83. package/dist/esm/pos-app-rdf-document.entry.js +1 -1
  84. package/dist/esm/pos-attachments.entry.js +1 -1
  85. package/dist/esm/pos-case.entry.js +1 -1
  86. package/dist/esm/pos-container-contents.entry.js +2 -2
  87. package/dist/esm/pos-container-item_3.entry.js +4 -4
  88. package/dist/esm/pos-document.entry.js +4 -4
  89. package/dist/esm/pos-list.entry.js +1 -1
  90. package/dist/esm/pos-markdown-document.entry.js +412 -122
  91. package/dist/esm/pos-relations_2.entry.js +1 -1
  92. package/dist/esm/pos-subjects.entry.js +2 -2
  93. package/dist/esm/pos-switch.entry.js +1 -1
  94. package/dist/esm/pos-tool-attachments.entry.js +1 -1
  95. package/dist/esm/pos-value.entry.js +22 -2
  96. package/dist/types/components/pos-description/pos-description.d.ts +9 -2
  97. package/dist/types/components/pos-label/pos-label.d.ts +6 -2
  98. package/dist/types/components/pos-value/pos-value.d.ts +7 -2
  99. package/dist/types/components.d.ts +32 -8
  100. package/package.json +7 -7
  101. package/dist/elements/p-624503dd.entry.js +0 -1
  102. package/dist/elements/p-d6e9d178.entry.js +0 -1
  103. package/dist/elements/p-f9c10964.entry.js +0 -1
  104. package/dist/elements/p-sVi8GCz5.js +0 -67
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var index$1 = require('./index-CFcC3IGM.js');
3
+ var index$1 = require('./index-CjKppELa.js');
4
4
  var index = require('./index-DlHQ3blV.js');
5
- require('./chunk.ZGGPD2XJ-BhNheC5q.js');
5
+ require('./chunk.ZGGPD2XJ-BvGHEYp6.js');
6
6
 
7
7
  // ::- Persistent data structure representing an ordered mapping from
8
8
  // strings to values, with some convenient update methods.
@@ -13880,7 +13880,6 @@ function isMarkInSet(marks, type, attributes = {}) {
13880
13880
  return !!findMarkInSet(marks, type, attributes);
13881
13881
  }
13882
13882
  function getMarkRange($pos, type, attributes) {
13883
- var _a;
13884
13883
  if (!$pos || !type) {
13885
13884
  return;
13886
13885
  }
@@ -13891,7 +13890,12 @@ function getMarkRange($pos, type, attributes) {
13891
13890
  if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
13892
13891
  return;
13893
13892
  }
13894
- attributes = attributes || ((_a = start.node.marks[0]) == null ? void 0 : _a.attrs);
13893
+ if (!attributes) {
13894
+ const firstMark = start.node.marks.find((mark2) => mark2.type === type);
13895
+ if (firstMark) {
13896
+ attributes = firstMark.attrs;
13897
+ }
13898
+ }
13895
13899
  const mark = findMarkInSet([...start.node.marks], type, attributes);
13896
13900
  if (!mark) {
13897
13901
  return;
@@ -13926,7 +13930,7 @@ function getMarkType(nameOrType, schema) {
13926
13930
  }
13927
13931
 
13928
13932
  // src/commands/extendMarkRange.ts
13929
- var extendMarkRange = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
13933
+ var extendMarkRange = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
13930
13934
  const type = getMarkType(typeOrName, state.schema);
13931
13935
  const { doc, selection } = tr;
13932
13936
  const { $from, from, to } = selection;
@@ -14261,7 +14265,7 @@ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) =
14261
14265
  const fromSelectionAtStart = $from.parentOffset === 0;
14262
14266
  const isTextSelection2 = $fromNode.isText || $fromNode.isTextblock;
14263
14267
  const hasContent = $fromNode.content.size > 0;
14264
- if (fromSelectionAtStart && isTextSelection2 && hasContent) {
14268
+ if (fromSelectionAtStart && isTextSelection2 && hasContent && isOnlyBlockContent) {
14265
14269
  from = Math.max(0, from - 1);
14266
14270
  }
14267
14271
  tr.replaceWith(from, to, newContent);
@@ -14819,6 +14823,67 @@ function getAttributesFromExtensions(extensions) {
14819
14823
  }
14820
14824
 
14821
14825
  // src/utilities/mergeAttributes.ts
14826
+ function splitStyleDeclarations(styles) {
14827
+ const result = [];
14828
+ let current = "";
14829
+ let inSingleQuote = false;
14830
+ let inDoubleQuote = false;
14831
+ let parenDepth = 0;
14832
+ const length = styles.length;
14833
+ for (let i = 0; i < length; i += 1) {
14834
+ const char = styles[i];
14835
+ if (char === "'" && !inDoubleQuote) {
14836
+ inSingleQuote = !inSingleQuote;
14837
+ current += char;
14838
+ continue;
14839
+ }
14840
+ if (char === '"' && !inSingleQuote) {
14841
+ inDoubleQuote = !inDoubleQuote;
14842
+ current += char;
14843
+ continue;
14844
+ }
14845
+ if (!inSingleQuote && !inDoubleQuote) {
14846
+ if (char === "(") {
14847
+ parenDepth += 1;
14848
+ current += char;
14849
+ continue;
14850
+ }
14851
+ if (char === ")" && parenDepth > 0) {
14852
+ parenDepth -= 1;
14853
+ current += char;
14854
+ continue;
14855
+ }
14856
+ if (char === ";" && parenDepth === 0) {
14857
+ result.push(current);
14858
+ current = "";
14859
+ continue;
14860
+ }
14861
+ }
14862
+ current += char;
14863
+ }
14864
+ if (current) {
14865
+ result.push(current);
14866
+ }
14867
+ return result;
14868
+ }
14869
+ function parseStyleEntries(styles) {
14870
+ const pairs = [];
14871
+ const declarations = splitStyleDeclarations(styles || "");
14872
+ const numDeclarations = declarations.length;
14873
+ for (let i = 0; i < numDeclarations; i += 1) {
14874
+ const declaration = declarations[i];
14875
+ const firstColonIndex = declaration.indexOf(":");
14876
+ if (firstColonIndex === -1) {
14877
+ continue;
14878
+ }
14879
+ const property = declaration.slice(0, firstColonIndex).trim();
14880
+ const value = declaration.slice(firstColonIndex + 1).trim();
14881
+ if (property && value) {
14882
+ pairs.push([property, value]);
14883
+ }
14884
+ }
14885
+ return pairs;
14886
+ }
14822
14887
  function mergeAttributes(...objects) {
14823
14888
  return objects.filter((item) => !!item).reduce((items, item) => {
14824
14889
  const mergedAttributes = { ...items };
@@ -14834,17 +14899,7 @@ function mergeAttributes(...objects) {
14834
14899
  const insertClasses = valueClasses.filter((valueClass) => !existingClasses.includes(valueClass));
14835
14900
  mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
14836
14901
  } else if (key === "style") {
14837
- const newStyles = value ? value.split(";").map((style2) => style2.trim()).filter(Boolean) : [];
14838
- const existingStyles = mergedAttributes[key] ? mergedAttributes[key].split(";").map((style2) => style2.trim()).filter(Boolean) : [];
14839
- const styleMap = /* @__PURE__ */ new Map();
14840
- existingStyles.forEach((style2) => {
14841
- const [property, val] = style2.split(":").map((part) => part.trim());
14842
- styleMap.set(property, val);
14843
- });
14844
- newStyles.forEach((style2) => {
14845
- const [property, val] = style2.split(":").map((part) => part.trim());
14846
- styleMap.set(property, val);
14847
- });
14902
+ const styleMap = new Map([...parseStyleEntries(mergedAttributes[key]), ...parseStyleEntries(value)]);
14848
14903
  mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
14849
14904
  } else {
14850
14905
  mergedAttributes[key] = value;
@@ -15442,7 +15497,7 @@ function isNodeEmpty(node, {
15442
15497
  return true;
15443
15498
  }
15444
15499
  if (node.isText) {
15445
- return /^\s*$/m.test((_a = node.text) != null ? _a : "");
15500
+ return !/\S/.test((_a = node.text) != null ? _a : "");
15446
15501
  }
15447
15502
  }
15448
15503
  if (node.isText) {
@@ -15838,6 +15893,16 @@ var joinListForwards = (tr, listType) => {
15838
15893
  tr.join(after);
15839
15894
  return true;
15840
15895
  };
15896
+ function createInnerSelectionForWholeDocList(tr) {
15897
+ const doc = tr.doc;
15898
+ const list = doc.firstChild;
15899
+ if (!list) {
15900
+ return null;
15901
+ }
15902
+ const $start = doc.resolve(1);
15903
+ const $end = doc.resolve(list.nodeSize - 1);
15904
+ return TextSelection.between($start, $end);
15905
+ }
15841
15906
  var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr, state, dispatch, chain, commands, can }) => {
15842
15907
  const { extensions, splittableMarks } = editor.extensionManager;
15843
15908
  const listType = getNodeType(listTypeOrName, state.schema);
@@ -15850,13 +15915,35 @@ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) =>
15850
15915
  return false;
15851
15916
  }
15852
15917
  const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection);
15853
- if (range.depth >= 1 && parentList && range.depth - parentList.depth <= 1) {
15854
- if (parentList.node.type === listType) {
15918
+ const isAllSelection = selection.from === 0 && selection.to === state.doc.content.size;
15919
+ const topLevelNodes = state.doc.content.content;
15920
+ const soleTopLevelNode = topLevelNodes.length === 1 ? topLevelNodes[0] : null;
15921
+ const allSelectionList = isAllSelection && soleTopLevelNode && isList(soleTopLevelNode.type.name, extensions) ? {
15922
+ node: soleTopLevelNode,
15923
+ pos: 0} : null;
15924
+ const currentList = parentList != null ? parentList : allSelectionList;
15925
+ const isInsideExistingList = !!parentList && range.depth >= 1 && range.depth - parentList.depth <= 1;
15926
+ const hasWholeDocSelectedList = !!allSelectionList;
15927
+ if ((isInsideExistingList || hasWholeDocSelectedList) && currentList) {
15928
+ if (currentList.node.type === listType) {
15929
+ if (isAllSelection && hasWholeDocSelectedList) {
15930
+ return chain().command(({ tr: trx, dispatch: disp }) => {
15931
+ const nextSelection = createInnerSelectionForWholeDocList(trx);
15932
+ if (!nextSelection) {
15933
+ return false;
15934
+ }
15935
+ trx.setSelection(nextSelection);
15936
+ if (disp) {
15937
+ disp(trx);
15938
+ }
15939
+ return true;
15940
+ }).liftListItem(itemType).run();
15941
+ }
15855
15942
  return commands.liftListItem(itemType);
15856
15943
  }
15857
- if (isList(parentList.node.type.name, extensions) && listType.validContent(parentList.node.content) && dispatch) {
15944
+ if (isList(currentList.node.type.name, extensions) && listType.validContent(currentList.node.content)) {
15858
15945
  return chain().command(() => {
15859
- tr.setNodeMarkup(parentList.pos, listType);
15946
+ tr.setNodeMarkup(currentList.pos, listType);
15860
15947
  return true;
15861
15948
  }).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
15862
15949
  }
@@ -17141,7 +17228,7 @@ var Delete = Extension.create({
17141
17228
  const newEnd = mapping.slice(index).map(step.to);
17142
17229
  const oldStart = mapping.invert().map(newStart, -1);
17143
17230
  const oldEnd = mapping.invert().map(newEnd);
17144
- const foundBeforeMark = (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark));
17231
+ const foundBeforeMark = newStart > 0 ? (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark)) : false;
17145
17232
  const foundAfterMark = (_b3 = nextTransaction.doc.nodeAt(newEnd)) == null ? void 0 : _b3.marks.some((mark) => mark.eq(step.mark));
17146
17233
  this.editor.emit("delete", {
17147
17234
  type: "mark",
@@ -18639,7 +18726,7 @@ var ResizableNodeView = class {
18639
18726
  const element = document.createElement("div");
18640
18727
  element.dataset.resizeContainer = "";
18641
18728
  element.dataset.node = this.node.type.name;
18642
- element.style.display = "flex";
18729
+ element.style.display = this.node.type.isInline ? "inline-flex" : "flex";
18643
18730
  if (this.classNames.container) {
18644
18731
  element.className = this.classNames.container;
18645
18732
  }
@@ -18979,6 +19066,14 @@ function canInsertNode(state, nodeType) {
18979
19066
  return false;
18980
19067
  }
18981
19068
 
19069
+ // src/utilities/htmlEntities.ts
19070
+ function decodeHtmlEntities(text) {
19071
+ return text.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
19072
+ }
19073
+ function encodeHtmlEntities(text) {
19074
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
19075
+ }
19076
+
18982
19077
  // src/utilities/markdown/index.ts
18983
19078
  var markdown_exports = {};
18984
19079
  __export$1(markdown_exports, {
@@ -19455,17 +19550,21 @@ function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) {
19455
19550
  const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
19456
19551
  const [content, ...children] = node.content;
19457
19552
  const mainContent = h2.renderChildren([content]);
19458
- const output = [`${prefix}${mainContent}`];
19553
+ let output = `${prefix}${mainContent}`;
19459
19554
  if (children && children.length > 0) {
19460
- children.forEach((child) => {
19461
- const childContent = h2.renderChildren([child]);
19462
- if (childContent) {
19463
- const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : "").join("\n");
19464
- output.push(indentedChild);
19555
+ children.forEach((child, index) => {
19556
+ var _a, _b;
19557
+ const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index + 1)) != null ? _b : h2.renderChildren([child]);
19558
+ if (childContent !== void 0 && childContent !== null) {
19559
+ const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : h2.indent("")).join("\n");
19560
+ output += child.type === "paragraph" ? `
19561
+
19562
+ ${indentedChild}` : `
19563
+ ${indentedChild}`;
19465
19564
  }
19466
19565
  });
19467
19566
  }
19468
- return output.join("\n");
19567
+ return output;
19469
19568
  }
19470
19569
 
19471
19570
  // src/MarkView.ts
@@ -19561,7 +19660,10 @@ function markPasteRule(config) {
19561
19660
  }
19562
19661
  markEnd = range.from + startSpaces + captureGroup.length;
19563
19662
  tr.addMark(range.from + startSpaces, markEnd, config.type.create(attributes || {}));
19564
- tr.removeStoredMark(config.type);
19663
+ const isMatchAtEndOfText = match.index !== void 0 && match.input !== void 0 && match.index + match[0].length >= match.input.length;
19664
+ if (!isMatchAtEndOfText) {
19665
+ tr.removeStoredMark(config.type);
19666
+ }
19565
19667
  }
19566
19668
  }
19567
19669
  });
@@ -19673,13 +19775,13 @@ function findMarksToCloseAtEnd(activeMarks, currentMarks, nextNode, markSetsEqua
19673
19775
  if (isLastNode || nextNodeHasNoMarks || nextNodeHasDifferentMarks) {
19674
19776
  if (nextNode && nextNode.type === "text" && nextNode.marks) {
19675
19777
  const nextMarks = new Map(nextNode.marks.map((mark) => [mark.type, mark]));
19676
- Array.from(activeMarks.keys()).forEach((markType) => {
19778
+ Array.from(activeMarks.keys()).reverse().forEach((markType) => {
19677
19779
  if (!nextMarks.has(markType)) {
19678
19780
  marksToCloseAtEnd.push(markType);
19679
19781
  }
19680
19782
  });
19681
19783
  } else if (isLastNode || nextNodeHasNoMarks) {
19682
- marksToCloseAtEnd.push(...Array.from(activeMarks.keys()));
19784
+ marksToCloseAtEnd.push(...Array.from(activeMarks.keys()).reverse());
19683
19785
  }
19684
19786
  }
19685
19787
  return marksToCloseAtEnd;
@@ -19732,12 +19834,14 @@ var MarkdownManager = class {
19732
19834
  * @param options.extensions An array of Tiptap extensions to register for markdown parsing and rendering.
19733
19835
  */
19734
19836
  constructor(options) {
19837
+ this.activeParseLexer = null;
19735
19838
  this.baseExtensions = [];
19736
19839
  this.extensions = [];
19840
+ /** Set of extension names whose `code` spec property is truthy (nodes and marks). */
19841
+ this.codeTypes = /* @__PURE__ */ new Set();
19737
19842
  this.lastParseResult = null;
19738
19843
  var _a, _b, _c, _d, _e;
19739
19844
  this.markedInstance = (_a = options == null ? void 0 : options.marked) != null ? _a : g;
19740
- this.lexer = new this.markedInstance.Lexer();
19741
19845
  this.indentStyle = (_c = (_b = options == null ? void 0 : options.indentation) == null ? void 0 : _b.style) != null ? _c : "space";
19742
19846
  this.indentSize = (_e = (_d = options == null ? void 0 : options.indentation) == null ? void 0 : _d.size) != null ? _e : 2;
19743
19847
  this.baseExtensions = (options == null ? void 0 : options.extensions) || [];
@@ -19749,9 +19853,8 @@ var MarkdownManager = class {
19749
19853
  if (options == null ? void 0 : options.extensions) {
19750
19854
  this.baseExtensions = options.extensions;
19751
19855
  const flattened = flattenExtensions(options.extensions);
19752
- flattened.forEach((ext) => this.registerExtension(ext, false));
19856
+ flattened.forEach((ext) => this.registerExtension(ext));
19753
19857
  }
19754
- this.lexer = new this.markedInstance.Lexer();
19755
19858
  }
19756
19859
  /** Returns the underlying marked instance. */
19757
19860
  get instance() {
@@ -19774,22 +19877,28 @@ var MarkdownManager = class {
19774
19877
  * `markdownName`, `parseMarkdown`, `renderMarkdown` and `priority` from the
19775
19878
  * extension config (using the same resolution used across the codebase).
19776
19879
  */
19777
- registerExtension(extension, recreateLexer = true) {
19880
+ registerExtension(extension) {
19778
19881
  var _a, _b;
19779
19882
  this.extensions.push(extension);
19883
+ const isCode = callOrReturn(getExtensionField(extension, "code"));
19780
19884
  const name = extension.name;
19885
+ if (isCode) {
19886
+ this.codeTypes.add(name);
19887
+ }
19781
19888
  const tokenName = getExtensionField(extension, "markdownTokenName") || name;
19782
19889
  const parseMarkdown = getExtensionField(extension, "parseMarkdown");
19783
19890
  const renderMarkdown = getExtensionField(extension, "renderMarkdown");
19784
19891
  const tokenizer = getExtensionField(extension, "markdownTokenizer");
19785
19892
  const markdownCfg = (_a = getExtensionField(extension, "markdownOptions")) != null ? _a : null;
19786
19893
  const isIndenting = (_b = markdownCfg == null ? void 0 : markdownCfg.indentsContent) != null ? _b : false;
19894
+ const htmlReopen = markdownCfg == null ? void 0 : markdownCfg.htmlReopen;
19787
19895
  const spec = {
19788
19896
  tokenName,
19789
19897
  nodeName: name,
19790
19898
  parseMarkdown,
19791
19899
  renderMarkdown,
19792
19900
  isIndenting,
19901
+ htmlReopen,
19793
19902
  tokenizer
19794
19903
  };
19795
19904
  if (tokenName && parseMarkdown) {
@@ -19804,11 +19913,21 @@ var MarkdownManager = class {
19804
19913
  }
19805
19914
  if (tokenizer && this.hasMarked()) {
19806
19915
  this.registerTokenizer(tokenizer);
19807
- if (recreateLexer) {
19808
- this.lexer = new this.markedInstance.Lexer();
19809
- }
19810
19916
  }
19811
19917
  }
19918
+ createLexer() {
19919
+ return new this.markedInstance.Lexer();
19920
+ }
19921
+ createTokenizerHelpers(lexer) {
19922
+ return {
19923
+ inlineTokens: (src) => lexer.inlineTokens(src),
19924
+ blockTokens: (src) => lexer.blockTokens(src)
19925
+ };
19926
+ }
19927
+ tokenizeInline(src) {
19928
+ var _a;
19929
+ return ((_a = this.activeParseLexer) != null ? _a : this.createLexer()).inlineTokens(src);
19930
+ }
19812
19931
  /**
19813
19932
  * Register a custom tokenizer with marked.js for parsing non-standard markdown syntax.
19814
19933
  */
@@ -19817,20 +19936,12 @@ var MarkdownManager = class {
19817
19936
  return;
19818
19937
  }
19819
19938
  const { name, start, level = "inline", tokenize } = tokenizer;
19820
- const tokenizeInline = (src) => {
19821
- return this.lexer.inlineTokens(src);
19822
- };
19823
- const tokenizeBlock = (src) => {
19824
- return this.lexer.blockTokens(src);
19825
- };
19826
- const helper = {
19827
- inlineTokens: tokenizeInline,
19828
- blockTokens: tokenizeBlock
19829
- };
19939
+ const createTokenizerHelpers = this.createTokenizerHelpers.bind(this);
19940
+ const createLexer = this.createLexer.bind(this);
19830
19941
  let startCb;
19831
19942
  if (!start) {
19832
19943
  startCb = (src) => {
19833
- const result = tokenize(src, [], helper);
19944
+ const result = tokenize(src, [], this.createTokenizerHelpers(this.createLexer()));
19834
19945
  if (result && result.raw) {
19835
19946
  const index = src.indexOf(result.raw);
19836
19947
  return index;
@@ -19844,7 +19955,8 @@ var MarkdownManager = class {
19844
19955
  name,
19845
19956
  level,
19846
19957
  start: startCb,
19847
- tokenizer: (src, tokens) => {
19958
+ tokenizer(src, tokens) {
19959
+ const helper = this.lexer ? createTokenizerHelpers(this.lexer) : createTokenizerHelpers(createLexer());
19848
19960
  const result = tokenize(src, tokens, helper);
19849
19961
  if (result && result.type) {
19850
19962
  return {
@@ -19917,23 +20029,65 @@ var MarkdownManager = class {
19917
20029
  if (!this.hasMarked()) {
19918
20030
  throw new Error("No marked instance available for parsing");
19919
20031
  }
19920
- const tokens = this.markedInstance.lexer(markdown);
19921
- const content = this.parseTokens(tokens);
19922
- return {
19923
- type: "doc",
19924
- content
19925
- };
20032
+ const previousParseLexer = this.activeParseLexer;
20033
+ const parseLexer = this.createLexer();
20034
+ this.activeParseLexer = parseLexer;
20035
+ try {
20036
+ const tokens = parseLexer.lex(markdown);
20037
+ const content = this.parseTokens(tokens, true);
20038
+ return {
20039
+ type: "doc",
20040
+ content
20041
+ };
20042
+ } finally {
20043
+ this.activeParseLexer = previousParseLexer;
20044
+ }
19926
20045
  }
19927
20046
  /**
19928
20047
  * Convert an array of marked tokens into Tiptap JSON nodes using registered extension handlers.
19929
20048
  */
19930
- parseTokens(tokens) {
19931
- return tokens.map((token) => this.parseToken(token)).filter((parsed) => parsed !== null).flatMap((parsed) => Array.isArray(parsed) ? parsed : [parsed]);
20049
+ parseTokens(tokens, parseImplicitEmptyParagraphs = false) {
20050
+ const nonSpaceTokenIndexes = tokens.reduce((indexes, token, index) => {
20051
+ if (token.type !== "space") {
20052
+ indexes.push(index);
20053
+ }
20054
+ return indexes;
20055
+ }, []);
20056
+ let previousNonSpaceTokenIndex = -1;
20057
+ let nextNonSpaceTokenPointer = 0;
20058
+ return tokens.flatMap((token, index) => {
20059
+ var _a;
20060
+ while (nextNonSpaceTokenPointer < nonSpaceTokenIndexes.length && nonSpaceTokenIndexes[nextNonSpaceTokenPointer] < index) {
20061
+ previousNonSpaceTokenIndex = nonSpaceTokenIndexes[nextNonSpaceTokenPointer];
20062
+ nextNonSpaceTokenPointer += 1;
20063
+ }
20064
+ if (parseImplicitEmptyParagraphs && token.type === "space") {
20065
+ const nextNonSpaceTokenIndex = (_a = nonSpaceTokenIndexes[nextNonSpaceTokenPointer]) != null ? _a : -1;
20066
+ return this.createImplicitEmptyParagraphsFromSpace(token, previousNonSpaceTokenIndex, nextNonSpaceTokenIndex);
20067
+ }
20068
+ const parsed = this.parseToken(token, parseImplicitEmptyParagraphs);
20069
+ if (parsed === null) {
20070
+ return [];
20071
+ }
20072
+ return Array.isArray(parsed) ? parsed : [parsed];
20073
+ });
20074
+ }
20075
+ createImplicitEmptyParagraphsFromSpace(token, previousNonSpaceTokenIndex, nextNonSpaceTokenIndex) {
20076
+ const separatorCount = this.countParagraphSeparators(token.raw || "");
20077
+ if (separatorCount === 0) {
20078
+ return [];
20079
+ }
20080
+ const isBoundarySpace = previousNonSpaceTokenIndex === -1 || nextNonSpaceTokenIndex === -1;
20081
+ const emptyParagraphCount = Math.max(separatorCount - (isBoundarySpace ? 0 : 1), 0);
20082
+ return Array.from({ length: emptyParagraphCount }, () => ({ type: "paragraph", content: [] }));
20083
+ }
20084
+ countParagraphSeparators(raw) {
20085
+ return (raw.replace(/\r\n/g, "\n").match(/\n\n/g) || []).length;
19932
20086
  }
19933
20087
  /**
19934
20088
  * Parse a single token into Tiptap JSON using the appropriate registered handler.
19935
20089
  */
19936
- parseToken(token) {
20090
+ parseToken(token, parseImplicitEmptyParagraphs = false) {
19937
20091
  if (!token.type) {
19938
20092
  return null;
19939
20093
  }
@@ -19959,7 +20113,7 @@ var MarkdownManager = class {
19959
20113
  this.lastParseResult = null;
19960
20114
  return toReturn;
19961
20115
  }
19962
- return this.parseFallbackToken(token);
20116
+ return this.parseFallbackToken(token, parseImplicitEmptyParagraphs);
19963
20117
  }
19964
20118
  /**
19965
20119
  * Parse a list token, handling mixed bullet and task list items by splitting them into separate lists.
@@ -20018,7 +20172,7 @@ var MarkdownManager = class {
20018
20172
  indentLevel,
20019
20173
  checked: checked != null ? checked : false,
20020
20174
  text: mainContent,
20021
- tokens: this.lexer.inlineTokens(mainContent),
20175
+ tokens: this.tokenizeInline(mainContent),
20022
20176
  nestedTokens
20023
20177
  };
20024
20178
  }
@@ -20087,6 +20241,7 @@ var MarkdownManager = class {
20087
20241
  return {
20088
20242
  parseInline: (tokens) => this.parseInlineTokens(tokens),
20089
20243
  parseChildren: (tokens) => this.parseTokens(tokens),
20244
+ parseBlockChildren: (tokens) => this.parseTokens(tokens, true),
20090
20245
  createTextNode: (text, marks) => {
20091
20246
  const node = {
20092
20247
  type: "text",
@@ -20131,7 +20286,7 @@ var MarkdownManager = class {
20131
20286
  if (token.type === "text") {
20132
20287
  result.push({
20133
20288
  type: "text",
20134
- text: token.text || ""
20289
+ text: decodeHtmlEntities(token.text || "")
20135
20290
  });
20136
20291
  } else if (token.type === "html") {
20137
20292
  const raw = ((_b = (_a = token.raw) != null ? _a : token.text) != null ? _b : "").toString();
@@ -20245,7 +20400,7 @@ var MarkdownManager = class {
20245
20400
  /**
20246
20401
  * Fallback parsing for common tokens when no specific handler is registered.
20247
20402
  */
20248
- parseFallbackToken(token) {
20403
+ parseFallbackToken(token, parseImplicitEmptyParagraphs = false) {
20249
20404
  switch (token.type) {
20250
20405
  case "paragraph":
20251
20406
  return {
@@ -20261,7 +20416,7 @@ var MarkdownManager = class {
20261
20416
  case "text":
20262
20417
  return {
20263
20418
  type: "text",
20264
- text: token.text || ""
20419
+ text: decodeHtmlEntities(token.text || "")
20265
20420
  };
20266
20421
  case "html":
20267
20422
  return this.parseHTMLToken(token);
@@ -20269,7 +20424,7 @@ var MarkdownManager = class {
20269
20424
  return null;
20270
20425
  default:
20271
20426
  if (token.tokens) {
20272
- return this.parseTokens(token.tokens);
20427
+ return this.parseTokens(token.tokens, parseImplicitEmptyParagraphs);
20273
20428
  }
20274
20429
  return null;
20275
20430
  }
@@ -20316,10 +20471,18 @@ var MarkdownManager = class {
20316
20471
  throw new Error(`Failed to parse HTML in markdown: ${error}`);
20317
20472
  }
20318
20473
  }
20319
- renderNodeToMarkdown(node, parentNode, index = 0, level = 0) {
20474
+ /**
20475
+ * Encode HTML entities in text unless the node is inside a code context
20476
+ * (code mark or code-block parent) where literal characters should be preserved.
20477
+ */
20478
+ encodeTextForMarkdown(text, node, parentNode) {
20479
+ const isInsideCode = (parentNode == null ? void 0 : parentNode.type) != null && this.codeTypes.has(parentNode.type) || (node.marks || []).some((m) => this.codeTypes.has(typeof m === "string" ? m : m.type));
20480
+ return isInsideCode ? text : encodeHtmlEntities(text);
20481
+ }
20482
+ renderNodeToMarkdown(node, parentNode, index = 0, level = 0, meta = {}) {
20320
20483
  var _a;
20321
20484
  if (node.type === "text") {
20322
- return node.text || "";
20485
+ return this.encodeTextForMarkdown(node.text || "", node, parentNode);
20323
20486
  }
20324
20487
  if (!node.type) {
20325
20488
  return "";
@@ -20328,6 +20491,7 @@ var MarkdownManager = class {
20328
20491
  if (!handler) {
20329
20492
  return "";
20330
20493
  }
20494
+ const previousNode = Array.isArray(parentNode == null ? void 0 : parentNode.content) && index > 0 ? parentNode.content[index - 1] : void 0;
20331
20495
  const helpers = {
20332
20496
  renderChildren: (nodes, separator) => {
20333
20497
  const childLevel = handler.isIndenting ? level + 1 : level;
@@ -20336,6 +20500,10 @@ var MarkdownManager = class {
20336
20500
  }
20337
20501
  return this.renderNodes(nodes, node, separator || "", index, childLevel);
20338
20502
  },
20503
+ renderChild: (childNode, childIndex) => {
20504
+ const childLevel = handler.isIndenting ? level + 1 : level;
20505
+ return this.renderNodeToMarkdown(childNode, node, childIndex, childLevel);
20506
+ },
20339
20507
  indent: (content) => {
20340
20508
  return this.indentString + content;
20341
20509
  },
@@ -20345,8 +20513,10 @@ var MarkdownManager = class {
20345
20513
  index,
20346
20514
  level,
20347
20515
  parentType: parentNode == null ? void 0 : parentNode.type,
20516
+ previousNode,
20348
20517
  meta: {
20349
- parentAttrs: parentNode == null ? void 0 : parentNode.attrs
20518
+ parentAttrs: parentNode == null ? void 0 : parentNode.attrs,
20519
+ ...meta
20350
20520
  }
20351
20521
  };
20352
20522
  const rendered = ((_a = handler.renderMarkdown) == null ? void 0 : _a.call(handler, node, helpers, context)) || "";
@@ -20372,34 +20542,44 @@ var MarkdownManager = class {
20372
20542
  renderNodesWithMarkBoundaries(nodes, parentNode, separator = "", level = 0) {
20373
20543
  const result = [];
20374
20544
  const activeMarks = /* @__PURE__ */ new Map();
20545
+ const reopenWithHtmlOnNextOpen = /* @__PURE__ */ new Set();
20546
+ const markOpeningModes = /* @__PURE__ */ new Map();
20375
20547
  nodes.forEach((node, i) => {
20376
20548
  const nextNode = i < nodes.length - 1 ? nodes[i + 1] : null;
20377
20549
  if (!node.type) {
20378
20550
  return;
20379
20551
  }
20380
20552
  if (node.type === "text") {
20381
- let textContent = node.text || "";
20553
+ let textContent = this.encodeTextForMarkdown(node.text || "", node, parentNode);
20382
20554
  const currentMarks = new Map((node.marks || []).map((mark) => [mark.type, mark]));
20383
20555
  const marksToOpen = findMarksToOpen(activeMarks, currentMarks);
20384
20556
  const marksToClose = findMarksToClose(currentMarks, nextNode);
20557
+ const activeMarksClosingHere = marksToClose.filter((markType) => activeMarks.has(markType));
20558
+ const hasCrossedBoundary = activeMarksClosingHere.length > 0 && marksToOpen.length > 0;
20385
20559
  let middleTrailingWhitespace = "";
20386
- if (marksToClose.length > 0) {
20560
+ if (marksToClose.length > 0 && !hasCrossedBoundary) {
20387
20561
  const middleTrailingMatch = textContent.match(/(\s+)$/);
20388
20562
  if (middleTrailingMatch) {
20389
20563
  middleTrailingWhitespace = middleTrailingMatch[1];
20390
20564
  textContent = textContent.slice(0, -middleTrailingWhitespace.length);
20391
20565
  }
20392
20566
  }
20393
- marksToClose.forEach((markType) => {
20394
- const mark = currentMarks.get(markType);
20395
- const closeMarkdown = this.getMarkClosing(markType, mark);
20396
- if (closeMarkdown) {
20397
- textContent += closeMarkdown;
20398
- }
20399
- if (activeMarks.has(markType)) {
20400
- activeMarks.delete(markType);
20401
- }
20402
- });
20567
+ if (!hasCrossedBoundary) {
20568
+ marksToClose.forEach((markType) => {
20569
+ if (!activeMarks.has(markType)) {
20570
+ return;
20571
+ }
20572
+ const mark = currentMarks.get(markType);
20573
+ const closeMarkdown = this.getMarkClosing(markType, mark, markOpeningModes.get(markType));
20574
+ if (closeMarkdown) {
20575
+ textContent += closeMarkdown;
20576
+ }
20577
+ if (activeMarks.has(markType)) {
20578
+ activeMarks.delete(markType);
20579
+ markOpeningModes.delete(markType);
20580
+ }
20581
+ });
20582
+ }
20403
20583
  let leadingWhitespace = "";
20404
20584
  if (marksToOpen.length > 0) {
20405
20585
  const leadingMatch = textContent.match(/^(\s+)/);
@@ -20409,21 +20589,37 @@ var MarkdownManager = class {
20409
20589
  }
20410
20590
  }
20411
20591
  marksToOpen.forEach(({ type, mark }) => {
20412
- const openMarkdown = this.getMarkOpening(type, mark);
20592
+ const openingMode = reopenWithHtmlOnNextOpen.has(type) ? "html" : "markdown";
20593
+ const openMarkdown = this.getMarkOpening(type, mark, openingMode);
20413
20594
  if (openMarkdown) {
20414
20595
  textContent = openMarkdown + textContent;
20415
20596
  }
20416
- if (!marksToClose.includes(type)) {
20417
- activeMarks.set(type, mark);
20418
- }
20597
+ markOpeningModes.set(type, openingMode);
20598
+ reopenWithHtmlOnNextOpen.delete(type);
20419
20599
  });
20600
+ if (!hasCrossedBoundary) {
20601
+ marksToOpen.slice().reverse().forEach(({ type, mark }) => {
20602
+ activeMarks.set(type, mark);
20603
+ });
20604
+ }
20420
20605
  textContent = leadingWhitespace + textContent;
20421
- const marksToCloseAtEnd = findMarksToCloseAtEnd(
20422
- activeMarks,
20423
- currentMarks,
20424
- nextNode,
20425
- this.markSetsEqual.bind(this)
20426
- );
20606
+ let marksToCloseAtEnd;
20607
+ if (hasCrossedBoundary) {
20608
+ const nextMarkTypes = new Set(((nextNode == null ? void 0 : nextNode.marks) || []).map((mark) => mark.type));
20609
+ marksToOpen.forEach(({ type }) => {
20610
+ if (nextMarkTypes.has(type) && this.getHtmlReopenTags(type)) {
20611
+ reopenWithHtmlOnNextOpen.add(type);
20612
+ }
20613
+ });
20614
+ marksToCloseAtEnd = [
20615
+ ...marksToOpen.map((m) => m.type),
20616
+ // inner (opened here) — close first
20617
+ ...activeMarksClosingHere
20618
+ // outer (were active before) — close last
20619
+ ];
20620
+ } else {
20621
+ marksToCloseAtEnd = findMarksToCloseAtEnd(activeMarks, currentMarks, nextNode, this.markSetsEqual.bind(this));
20622
+ }
20427
20623
  let trailingWhitespace = "";
20428
20624
  if (marksToCloseAtEnd.length > 0) {
20429
20625
  const trailingMatch = textContent.match(/(\s+)$/);
@@ -20433,21 +20629,32 @@ var MarkdownManager = class {
20433
20629
  }
20434
20630
  }
20435
20631
  marksToCloseAtEnd.forEach((markType) => {
20436
- const mark = activeMarks.get(markType);
20437
- const closeMarkdown = this.getMarkClosing(markType, mark);
20632
+ var _a;
20633
+ const mark = (_a = activeMarks.get(markType)) != null ? _a : currentMarks.get(markType);
20634
+ const closeMarkdown = this.getMarkClosing(markType, mark, markOpeningModes.get(markType));
20438
20635
  if (closeMarkdown) {
20439
20636
  textContent += closeMarkdown;
20440
20637
  }
20441
20638
  activeMarks.delete(markType);
20639
+ markOpeningModes.delete(markType);
20442
20640
  });
20443
20641
  textContent += trailingWhitespace;
20444
20642
  textContent += middleTrailingWhitespace;
20445
20643
  result.push(textContent);
20446
20644
  } else {
20447
20645
  const marksToReopen = new Map(activeMarks);
20448
- const beforeMarkdown = closeMarksBeforeNode(activeMarks, this.getMarkClosing.bind(this));
20646
+ const openingModesToReopen = new Map(markOpeningModes);
20647
+ const beforeMarkdown = closeMarksBeforeNode(activeMarks, (markType, mark) => {
20648
+ return this.getMarkClosing(markType, mark, markOpeningModes.get(markType));
20649
+ });
20650
+ markOpeningModes.clear();
20449
20651
  const nodeContent = this.renderNodeToMarkdown(node, parentNode, i, level);
20450
- const afterMarkdown = node.type === "hardBreak" ? "" : reopenMarksAfterNode(marksToReopen, activeMarks, this.getMarkOpening.bind(this));
20652
+ const afterMarkdown = node.type === "hardBreak" ? "" : reopenMarksAfterNode(marksToReopen, activeMarks, (markType, mark) => {
20653
+ var _a;
20654
+ const openingMode = (_a = openingModesToReopen.get(markType)) != null ? _a : "markdown";
20655
+ markOpeningModes.set(markType, openingMode);
20656
+ return this.getMarkOpening(markType, mark, openingMode);
20657
+ });
20451
20658
  result.push(beforeMarkdown + nodeContent + afterMarkdown);
20452
20659
  }
20453
20660
  });
@@ -20456,7 +20663,11 @@ var MarkdownManager = class {
20456
20663
  /**
20457
20664
  * Get the opening markdown syntax for a mark type.
20458
20665
  */
20459
- getMarkOpening(markType, mark) {
20666
+ getMarkOpening(markType, mark, openingMode = "markdown") {
20667
+ var _a;
20668
+ if (openingMode === "html") {
20669
+ return ((_a = this.getHtmlReopenTags(markType)) == null ? void 0 : _a.open) || "";
20670
+ }
20460
20671
  const handlers = this.getHandlersForNodeType(markType);
20461
20672
  const handler = handlers.length > 0 ? handlers[0] : void 0;
20462
20673
  if (!handler || !handler.renderMarkdown) {
@@ -20473,6 +20684,7 @@ var MarkdownManager = class {
20473
20684
  syntheticNode,
20474
20685
  {
20475
20686
  renderChildren: () => placeholder,
20687
+ renderChild: () => placeholder,
20476
20688
  indent: (content) => content,
20477
20689
  wrapInBlock: (prefix, content) => prefix + content
20478
20690
  },
@@ -20487,7 +20699,11 @@ var MarkdownManager = class {
20487
20699
  /**
20488
20700
  * Get the closing markdown syntax for a mark type.
20489
20701
  */
20490
- getMarkClosing(markType, mark) {
20702
+ getMarkClosing(markType, mark, openingMode = "markdown") {
20703
+ var _a;
20704
+ if (openingMode === "html") {
20705
+ return ((_a = this.getHtmlReopenTags(markType)) == null ? void 0 : _a.close) || "";
20706
+ }
20491
20707
  const handlers = this.getHandlersForNodeType(markType);
20492
20708
  const handler = handlers.length > 0 ? handlers[0] : void 0;
20493
20709
  if (!handler || !handler.renderMarkdown) {
@@ -20504,6 +20720,7 @@ var MarkdownManager = class {
20504
20720
  syntheticNode,
20505
20721
  {
20506
20722
  renderChildren: () => placeholder,
20723
+ renderChild: () => placeholder,
20507
20724
  indent: (content) => content,
20508
20725
  wrapInBlock: (prefix, content) => prefix + content
20509
20726
  },
@@ -20516,6 +20733,15 @@ var MarkdownManager = class {
20516
20733
  throw new Error(`Failed to get mark closing for ${markType}: ${err}`);
20517
20734
  }
20518
20735
  }
20736
+ /**
20737
+ * Returns the inline HTML tags an extension exposes for overlap-boundary
20738
+ * reopen handling, if that mark explicitly opted into HTML reopen mode.
20739
+ */
20740
+ getHtmlReopenTags(markType) {
20741
+ const handlers = this.getHandlersForNodeType(markType);
20742
+ const handler = handlers.length > 0 ? handlers[0] : void 0;
20743
+ return handler == null ? void 0 : handler.htmlReopen;
20744
+ }
20519
20745
  /**
20520
20746
  * Check if two mark sets are equal.
20521
20747
  */
@@ -20658,7 +20884,9 @@ var Blockquote = Node3.create({
20658
20884
  return /* @__PURE__ */ h("blockquote", { ...mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), children: /* @__PURE__ */ h("slot", {}) });
20659
20885
  },
20660
20886
  parseMarkdown: (token, helpers) => {
20661
- return helpers.createNode("blockquote", void 0, helpers.parseChildren(token.tokens || []));
20887
+ var _a;
20888
+ const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren;
20889
+ return helpers.createNode("blockquote", void 0, parseBlockChildren(token.tokens || []));
20662
20890
  },
20663
20891
  renderMarkdown: (node, h) => {
20664
20892
  if (!node.content) {
@@ -20666,8 +20894,9 @@ var Blockquote = Node3.create({
20666
20894
  }
20667
20895
  const prefix = ">";
20668
20896
  const result = [];
20669
- node.content.forEach((child) => {
20670
- const childContent = h.renderChildren([child]);
20897
+ node.content.forEach((child, index) => {
20898
+ var _a, _b;
20899
+ const childContent = (_b = (_a = h.renderChild) == null ? void 0 : _a.call(h, child, index)) != null ? _b : h.renderChildren([child]);
20671
20900
  const lines = childContent.split("\n");
20672
20901
  const linesWithPrefix = lines.map((line) => {
20673
20902
  if (line.trim() === "") {
@@ -20747,6 +20976,12 @@ var Bold = Mark.create({
20747
20976
  parseMarkdown: (token, helpers) => {
20748
20977
  return helpers.applyMark("bold", helpers.parseInline(token.tokens || []));
20749
20978
  },
20979
+ markdownOptions: {
20980
+ htmlReopen: {
20981
+ open: "<strong>",
20982
+ close: "</strong>"
20983
+ }
20984
+ },
20750
20985
  renderMarkdown: (node, h) => {
20751
20986
  return `**${h.renderChildren(node)}**`;
20752
20987
  },
@@ -20927,8 +21162,8 @@ var CodeBlock = Node3.create({
20927
21162
  },
20928
21163
  markdownTokenName: "code",
20929
21164
  parseMarkdown: (token, helpers) => {
20930
- var _a;
20931
- if (((_a = token.raw) == null ? void 0 : _a.startsWith("```")) === false && token.codeBlockStyle !== "indented") {
21165
+ var _a, _b;
21166
+ if (((_a = token.raw) == null ? void 0 : _a.startsWith("```")) === false && ((_b = token.raw) == null ? void 0 : _b.startsWith("~~~")) === false && token.codeBlockStyle !== "indented") {
20932
21167
  return [];
20933
21168
  }
20934
21169
  return helpers.createNode(
@@ -21456,6 +21691,12 @@ var Italic = Mark.create({
21456
21691
  parseMarkdown: (token, helpers) => {
21457
21692
  return helpers.applyMark("italic", helpers.parseInline(token.tokens || []));
21458
21693
  },
21694
+ markdownOptions: {
21695
+ htmlReopen: {
21696
+ open: "<em>",
21697
+ close: "</em>"
21698
+ }
21699
+ },
21459
21700
  renderMarkdown: (node, h) => {
21460
21701
  return `*${h.renderChildren(node)}*`;
21461
21702
  },
@@ -23759,14 +24000,16 @@ var ListItem = Node3.create({
23759
24000
  },
23760
24001
  markdownTokenName: "list_item",
23761
24002
  parseMarkdown: (token, helpers) => {
24003
+ var _a;
23762
24004
  if (token.type !== "list_item") {
23763
24005
  return [];
23764
24006
  }
24007
+ const parseBlockChildren = (_a = helpers.parseBlockChildren) != null ? _a : helpers.parseChildren;
23765
24008
  let content = [];
23766
24009
  if (token.tokens && token.tokens.length > 0) {
23767
24010
  const hasParagraphTokens = token.tokens.some((t) => t.type === "paragraph");
23768
24011
  if (hasParagraphTokens) {
23769
- content = helpers.parseChildren(token.tokens);
24012
+ content = parseBlockChildren(token.tokens);
23770
24013
  } else {
23771
24014
  const firstToken = token.tokens[0];
23772
24015
  if (firstToken && firstToken.type === "text" && firstToken.tokens && firstToken.tokens.length > 0) {
@@ -23779,11 +24022,11 @@ var ListItem = Node3.create({
23779
24022
  ];
23780
24023
  if (token.tokens.length > 1) {
23781
24024
  const remainingTokens = token.tokens.slice(1);
23782
- const additionalContent = helpers.parseChildren(remainingTokens);
24025
+ const additionalContent = parseBlockChildren(remainingTokens);
23783
24026
  content.push(...additionalContent);
23784
24027
  }
23785
24028
  } else {
23786
- content = helpers.parseChildren(token.tokens);
24029
+ content = parseBlockChildren(token.tokens);
23787
24030
  }
23788
24031
  }
23789
24032
  }
@@ -24088,6 +24331,36 @@ var ListKeymap = Extension.create({
24088
24331
  // src/ordered-list/utils.ts
24089
24332
  var ORDERED_LIST_ITEM_REGEX = /^(\s*)(\d+)\.\s+(.*)$/;
24090
24333
  var INDENTED_LINE_REGEX = /^\s/;
24334
+ function isBlockContentLine(line) {
24335
+ const trimmedLine = line.trimStart();
24336
+ return /^[-+*]\s+/.test(trimmedLine) || /^\d+\.\s+/.test(trimmedLine) || /^>\s?/.test(trimmedLine) || /^```/.test(trimmedLine) || /^~~~/.test(trimmedLine);
24337
+ }
24338
+ function splitItemContent(contentLines) {
24339
+ const paragraphLines = [];
24340
+ const blockLines = [];
24341
+ let reachedBlockBoundary = false;
24342
+ contentLines.forEach((line) => {
24343
+ if (reachedBlockBoundary) {
24344
+ blockLines.push(line);
24345
+ return;
24346
+ }
24347
+ if (line.trim() === "") {
24348
+ reachedBlockBoundary = true;
24349
+ blockLines.push(line);
24350
+ return;
24351
+ }
24352
+ if (paragraphLines.length > 0 && isBlockContentLine(line)) {
24353
+ reachedBlockBoundary = true;
24354
+ blockLines.push(line);
24355
+ return;
24356
+ }
24357
+ paragraphLines.push(line);
24358
+ });
24359
+ return {
24360
+ paragraphLines,
24361
+ blockLines
24362
+ };
24363
+ }
24091
24364
  function collectOrderedListItems(lines) {
24092
24365
  const listItems = [];
24093
24366
  let currentLineIndex = 0;
@@ -24100,9 +24373,10 @@ function collectOrderedListItems(lines) {
24100
24373
  }
24101
24374
  const [, indent, number, content] = match;
24102
24375
  const indentLevel = indent.length;
24103
- let itemContent = content;
24376
+ const itemContentLines = [content];
24104
24377
  let nextLineIndex = currentLineIndex + 1;
24105
24378
  const itemLines = [line];
24379
+ let sawBlankLine = false;
24106
24380
  while (nextLineIndex < lines.length) {
24107
24381
  const nextLine = lines[nextLineIndex];
24108
24382
  const nextMatch = nextLine.match(ORDERED_LIST_ITEM_REGEX);
@@ -24111,21 +24385,27 @@ function collectOrderedListItems(lines) {
24111
24385
  }
24112
24386
  if (nextLine.trim() === "") {
24113
24387
  itemLines.push(nextLine);
24114
- itemContent += "\n";
24388
+ itemContentLines.push("");
24389
+ sawBlankLine = true;
24115
24390
  nextLineIndex += 1;
24116
24391
  } else if (nextLine.match(INDENTED_LINE_REGEX)) {
24117
24392
  itemLines.push(nextLine);
24118
- itemContent += `
24119
- ${nextLine.slice(indentLevel + 2)}`;
24393
+ itemContentLines.push(nextLine.slice(indentLevel + 2));
24120
24394
  nextLineIndex += 1;
24121
24395
  } else {
24122
- break;
24396
+ if (sawBlankLine) {
24397
+ break;
24398
+ }
24399
+ itemLines.push(nextLine);
24400
+ itemContentLines.push(nextLine);
24401
+ nextLineIndex += 1;
24123
24402
  }
24124
24403
  }
24125
24404
  listItems.push({
24126
24405
  indent: indentLevel,
24127
24406
  number: parseInt(number, 10),
24128
- content: itemContent.trim(),
24407
+ content: itemContentLines.join("\n").trim(),
24408
+ contentLines: itemContentLines,
24129
24409
  raw: itemLines.join("\n")
24130
24410
  });
24131
24411
  consumed = nextLineIndex;
@@ -24134,14 +24414,13 @@ ${nextLine.slice(indentLevel + 2)}`;
24134
24414
  return [listItems, consumed];
24135
24415
  }
24136
24416
  function buildNestedStructure(items, baseIndent, lexer) {
24137
- var _a;
24138
24417
  const result = [];
24139
24418
  let currentIndex = 0;
24140
24419
  while (currentIndex < items.length) {
24141
24420
  const item = items[currentIndex];
24142
24421
  if (item.indent === baseIndent) {
24143
- const contentLines = item.content.split("\n");
24144
- const mainText = ((_a = contentLines[0]) == null ? void 0 : _a.trim()) || "";
24422
+ const { paragraphLines, blockLines } = splitItemContent(item.contentLines);
24423
+ const mainText = paragraphLines.join("\n").trim();
24145
24424
  const tokens = [];
24146
24425
  if (mainText) {
24147
24426
  tokens.push({
@@ -24150,7 +24429,7 @@ function buildNestedStructure(items, baseIndent, lexer) {
24150
24429
  tokens: lexer.inlineTokens(mainText)
24151
24430
  });
24152
24431
  }
24153
- const additionalContent = contentLines.slice(1).join("\n").trim();
24432
+ const additionalContent = blockLines.join("\n").trim();
24154
24433
  if (additionalContent) {
24155
24434
  const blockTokens = lexer.blockTokens(additionalContent);
24156
24435
  tokens.push(...blockTokens);
@@ -24727,18 +25006,22 @@ var Paragraph = Node3.create({
24727
25006
  return helpers.parseChildren([tokens[0]]);
24728
25007
  }
24729
25008
  const content = helpers.parseInline(tokens);
24730
- if (content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {
25009
+ const hasExplicitEmptyParagraphMarker = tokens.length === 1 && tokens[0].type === "text" && (tokens[0].raw === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].text === EMPTY_PARAGRAPH_MARKDOWN || tokens[0].raw === NBSP_CHAR || tokens[0].text === NBSP_CHAR);
25010
+ if (hasExplicitEmptyParagraphMarker && content.length === 1 && content[0].type === "text" && (content[0].text === EMPTY_PARAGRAPH_MARKDOWN || content[0].text === NBSP_CHAR)) {
24731
25011
  return helpers.createNode("paragraph", void 0, []);
24732
25012
  }
24733
25013
  return helpers.createNode("paragraph", void 0, content);
24734
25014
  },
24735
- renderMarkdown: (node, h) => {
25015
+ renderMarkdown: (node, h, ctx) => {
25016
+ var _a, _b;
24736
25017
  if (!node) {
24737
25018
  return "";
24738
25019
  }
24739
25020
  const content = Array.isArray(node.content) ? node.content : [];
24740
25021
  if (content.length === 0) {
24741
- return EMPTY_PARAGRAPH_MARKDOWN;
25022
+ const previousContent = Array.isArray((_a = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _a.content) ? ctx.previousNode.content : [];
25023
+ const previousNodeIsEmptyParagraph = ((_b = ctx == null ? void 0 : ctx.previousNode) == null ? void 0 : _b.type) === "paragraph" && previousContent.length === 0;
25024
+ return previousNodeIsEmptyParagraph ? EMPTY_PARAGRAPH_MARKDOWN : "";
24742
25025
  }
24743
25026
  return h.renderChildren(content);
24744
25027
  },
@@ -25870,7 +26153,7 @@ function history(config = {}) {
25870
26153
  beforeinput(view, e) {
25871
26154
  let inputType = e.inputType;
25872
26155
  let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null;
25873
- if (!command)
26156
+ if (!command || !view.editable)
25874
26157
  return false;
25875
26158
  e.preventDefault();
25876
26159
  return command(view.state, view.dispatch);
@@ -26121,6 +26404,9 @@ Extension.create({
26121
26404
  doc.descendants((node, pos) => {
26122
26405
  const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
26123
26406
  const isEmpty = !node.isLeaf && isNodeEmpty(node);
26407
+ if (!node.type.isTextblock) {
26408
+ return this.options.includeChildren;
26409
+ }
26124
26410
  if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
26125
26411
  const classes = [this.options.emptyNodeClass];
26126
26412
  if (isEmptyDoc) {
@@ -26174,6 +26460,7 @@ Extension.create({
26174
26460
  ];
26175
26461
  }
26176
26462
  });
26463
+ var skipTrailingNodeMeta = "skipTrailingNode";
26177
26464
  function nodeEqualsType({ types, node }) {
26178
26465
  return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
26179
26466
  }
@@ -26193,11 +26480,14 @@ var TrailingNode = Extension.create({
26193
26480
  return [
26194
26481
  new Plugin({
26195
26482
  key: plugin,
26196
- appendTransaction: (_, __, state) => {
26483
+ appendTransaction: (transactions, __, state) => {
26197
26484
  const { doc, tr, schema } = state;
26198
26485
  const shouldInsertNodeAtEnd = plugin.getState(state);
26199
26486
  const endPosition = doc.content.size;
26200
26487
  const type = schema.nodes[defaultNode];
26488
+ if (transactions.some((transaction) => transaction.getMeta(skipTrailingNodeMeta))) {
26489
+ return;
26490
+ }
26201
26491
  if (!shouldInsertNodeAtEnd) {
26202
26492
  return;
26203
26493
  }