@portabletext/markdown 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -156,8 +156,14 @@ const DefaultBlockSpacingRenderer = ({
156
156
  value,
157
157
  listIndex
158
158
  }) => {
159
- const listStyle = value.listItem || "bullet", level = value.level || 1;
160
- return listStyle === "number" ? `${" ".repeat(level - 1)}${listIndex ?? 1}. ${children}` : `${" ".repeat(level - 1)}- ${children}`;
159
+ const listStyle = value.listItem || "bullet", level = value.level || 1, indent = " ".repeat(level - 1);
160
+ if (listStyle === "number")
161
+ return `${indent}${listIndex ?? 1}. ${children}`;
162
+ if (listStyle === "task") {
163
+ const marker = "checked" in value && typeof value.checked == "boolean" && value.checked ? "[x]" : "[ ]";
164
+ return `${indent}- ${marker} ${children}`;
165
+ }
166
+ return `${indent}- ${children}`;
161
167
  }, DefaultUnknownListItemRenderer = ({
162
168
  children
163
169
  }) => `- ${children}
@@ -264,7 +270,52 @@ ${value.code}
264
270
  `);
265
271
  return `> [!${value.tone.toUpperCase()}]
266
272
  ${prefixed}`;
267
- }, DefaultUnknownTypeRenderer = ({
273
+ }, DefaultBlockquoteObjectRenderer = ({ value, renderNode }) => value.content.map(
274
+ (block, index) => renderNode({
275
+ node: { ...block, style: "normal" },
276
+ index,
277
+ isInline: !1,
278
+ renderNode
279
+ })
280
+ ).join(`
281
+
282
+ `).split(`
283
+ `).map((line) => line === "" ? ">" : `> ${line}`).join(`
284
+ `), DefaultListRenderer = ({ value, renderNode }) => {
285
+ const itemSeparator = value.items.some((item) => item.content.filter(
286
+ (block) => block._type !== "list"
287
+ ).length > 1) ? `
288
+
289
+ ` : `
290
+ `;
291
+ return value.items.map((item, itemIndex) => {
292
+ const marker = getListMarker(value.kind, itemIndex, item.checked), indentWidth = value.kind === "task" ? 2 : marker.length, indent = " ".repeat(indentWidth), renderedBlocks = item.content.map((block, blockIndex) => ({
293
+ isNestedList: block._type === "list",
294
+ text: renderNode({
295
+ node: block,
296
+ index: blockIndex,
297
+ isInline: !1,
298
+ renderNode
299
+ })
300
+ })), [first, ...rest] = renderedBlocks, head = `${marker}${first?.text ?? ""}`.trimEnd();
301
+ if (rest.length === 0)
302
+ return head;
303
+ const tail = rest.map((rendered) => {
304
+ const indented = rendered.text.split(`
305
+ `).map((line) => line === "" ? "" : `${indent}${line}`).join(`
306
+ `);
307
+ return rendered.isNestedList ? `
308
+ ${indented}` : `
309
+
310
+ ${indented}`;
311
+ }).join("");
312
+ return `${head}${tail}`;
313
+ }).join(itemSeparator);
314
+ };
315
+ function getListMarker(kind, itemIndex, checked) {
316
+ return kind === "number" ? `${itemIndex + 1}. ` : kind === "task" ? checked ? "- [x] " : "- [ ] " : "- ";
317
+ }
318
+ const DefaultUnknownTypeRenderer = ({
268
319
  value,
269
320
  isInline
270
321
  }) => {
@@ -363,6 +414,8 @@ const normalStyleDefinition = {
363
414
  name: "number"
364
415
  }, defaultUnorderedListItemDefinition = {
365
416
  name: "bullet"
417
+ }, defaultTaskListItemDefinition = {
418
+ name: "task"
366
419
  }, defaultStrongDecoratorDefinition = {
367
420
  name: "strong"
368
421
  }, defaultEmDecoratorDefinition = {
@@ -409,6 +462,9 @@ const normalStyleDefinition = {
409
462
  ]
410
463
  }, defaultSchema = compileSchema(
411
464
  defineSchema({
465
+ block: {
466
+ fields: [{ name: "checked", type: "boolean" }]
467
+ },
412
468
  styles: [
413
469
  normalStyleDefinition,
414
470
  h1StyleDefinition,
@@ -421,7 +477,8 @@ const normalStyleDefinition = {
421
477
  ],
422
478
  lists: [
423
479
  defaultOrderedListItemDefinition,
424
- defaultUnorderedListItemDefinition
480
+ defaultUnorderedListItemDefinition,
481
+ defaultTaskListItemDefinition
425
482
  ],
426
483
  decorators: [
427
484
  defaultStrongDecoratorDefinition,
@@ -525,7 +582,8 @@ const codeBlockMatcher = ({ context, value, isInline }) => {
525
582
  },
526
583
  listItem: {
527
584
  number: buildListItemMatcher(defaultOrderedListItemDefinition),
528
- bullet: buildListItemMatcher(defaultUnorderedListItemDefinition)
585
+ bullet: buildListItemMatcher(defaultUnorderedListItemDefinition),
586
+ task: buildListItemMatcher(defaultTaskListItemDefinition)
529
587
  },
530
588
  marks: {
531
589
  strong: buildDecoratorMatcher(defaultStrongDecoratorDefinition),
@@ -577,11 +635,51 @@ function markdownToPortableText(markdown, options) {
577
635
  html: !0,
578
636
  linkify: !0,
579
637
  typographer: !0
580
- }).enable(["strikethrough", "table"]).use(alert).parse(markdown, {}), portableText = [];
638
+ }).enable(["strikethrough", "table"]).use(alert).parse(markdown, {}), taskCheckedByListItemIndex = /* @__PURE__ */ new Map();
639
+ for (let i = 0; i < tokens.length; i++) {
640
+ if (tokens[i]?.type !== "list_item_open")
641
+ continue;
642
+ let inlineIndex = -1;
643
+ for (let j = i + 1; j < tokens.length; j++) {
644
+ const candidate = tokens[j];
645
+ if (candidate) {
646
+ if (candidate.type === "list_item_close")
647
+ break;
648
+ if (candidate.type === "inline") {
649
+ inlineIndex = j;
650
+ break;
651
+ }
652
+ }
653
+ }
654
+ if (inlineIndex === -1)
655
+ continue;
656
+ const inlineToken = tokens[inlineIndex];
657
+ if (!inlineToken)
658
+ continue;
659
+ const match = inlineToken.content.match(/^\[([ xX])\] /);
660
+ if (!match)
661
+ continue;
662
+ const checked = match[1] !== " ";
663
+ taskCheckedByListItemIndex.set(i, checked), inlineToken.content = inlineToken.content.slice(match[0].length);
664
+ const firstChild = inlineToken.children?.[0];
665
+ firstChild && typeof firstChild.content == "string" && (firstChild.content = firstChild.content.slice(match[0].length));
666
+ }
667
+ const portableText = [];
581
668
  let currentBlock = null;
582
669
  const currentListStack = [], markDefRefs = [];
583
- let currentMarkDefs = [], currentBlockquoteStyle = null, inListItem = !1, calloutStartIndex = null, calloutType = null, currentTable = null, currentTableRow = null, inTableHead = !1;
584
- const startBlock = (style) => {
670
+ let currentMarkDefs = [], currentBlockquoteStyle = null, inListItem = !1, calloutStartIndex = null, calloutStartTarget = null, calloutType = null;
671
+ const blockquoteStack = [];
672
+ let currentTable = null, currentTableRow = null, inTableHead = !1;
673
+ const listContainerStack = [], blockTarget = () => {
674
+ for (let i = listContainerStack.length - 1; i >= 0; i--) {
675
+ const frame = listContainerStack[i];
676
+ if (frame && frame.currentItem)
677
+ return frame.currentItem.content;
678
+ }
679
+ return portableText;
680
+ }, pushBlock = (block) => {
681
+ blockTarget().push(block);
682
+ }, startBlock = (style) => {
585
683
  flushBlock(), currentBlock = {
586
684
  _type: "block",
587
685
  style,
@@ -595,7 +693,7 @@ function markdownToPortableText(markdown, options) {
595
693
  _key: consolidatedOptions.keyGenerator(),
596
694
  text: "",
597
695
  marks: []
598
- }), currentBlock.markDefs = currentMarkDefs, portableText.push(currentBlock), currentBlock = null, currentMarkDefs = []);
696
+ }), currentBlock.markDefs = currentMarkDefs, pushBlock(currentBlock), currentBlock = null, currentMarkDefs = []);
599
697
  }, addSpan = (text) => {
600
698
  if (text.length === 0)
601
699
  return;
@@ -614,7 +712,7 @@ function markdownToPortableText(markdown, options) {
614
712
  text,
615
713
  marks: [...markDefRefs]
616
714
  });
617
- }, listLevel = () => currentListStack.length, ensureListBlock = (listItem) => {
715
+ }, listLevel = () => currentListStack.length, ensureListBlock = (listItem, checked) => {
618
716
  if (!currentBlock) {
619
717
  const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
620
718
  context: { schema: consolidatedOptions.schema }
@@ -623,533 +721,679 @@ function markdownToPortableText(markdown, options) {
623
721
  }
624
722
  if (!currentBlock)
625
723
  throw new Error("Expected current block");
626
- (currentBlock.listItem !== listItem || currentBlock.level !== listLevel()) && (currentBlock.listItem = listItem, currentBlock.level = listLevel());
724
+ (currentBlock.listItem !== listItem || currentBlock.level !== listLevel()) && (currentBlock.listItem = listItem, currentBlock.level = listLevel()), checked !== void 0 && (currentBlock.checked = checked);
627
725
  };
628
- for (const token of tokens)
629
- switch (token.type) {
630
- // Paragraphs
631
- case "paragraph_open": {
632
- if (inListItem) {
633
- if (!currentBlock) {
634
- const listType = currentListStack.at(-1);
635
- listType && ensureListBlock(listType);
726
+ for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) {
727
+ const token = tokens[tokenIndex];
728
+ if (token)
729
+ switch (token.type) {
730
+ // Paragraphs
731
+ case "paragraph_open": {
732
+ if (inListItem) {
733
+ if (listContainerStack.at(-1)) {
734
+ if (!currentBlock) {
735
+ const style2 = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
736
+ context: { schema: consolidatedOptions.schema }
737
+ }) ?? "normal";
738
+ startBlock(style2);
739
+ }
740
+ break;
741
+ }
742
+ if (!currentBlock) {
743
+ const listType = currentListStack.at(-1);
744
+ listType && ensureListBlock(listType);
745
+ }
746
+ break;
636
747
  }
748
+ const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
749
+ context: { schema: consolidatedOptions.schema }
750
+ });
751
+ if (!style) {
752
+ console.warn('No default style found, using "normal"'), startBlock("normal");
753
+ break;
754
+ }
755
+ startBlock(style);
637
756
  break;
638
757
  }
639
- const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
640
- context: { schema: consolidatedOptions.schema }
641
- });
642
- if (!style) {
643
- console.warn('No default style found, using "normal"'), startBlock("normal");
644
- break;
645
- }
646
- startBlock(style);
647
- break;
648
- }
649
- case "paragraph_close":
650
- if (inListItem)
758
+ case "paragraph_close":
759
+ if (inListItem) {
760
+ listContainerStack.at(-1) && flushBlock();
761
+ break;
762
+ }
763
+ flushBlock();
651
764
  break;
652
- flushBlock();
653
- break;
654
- // Headings
655
- case "heading_open": {
656
- const level = Number(token?.tag?.slice(1)), headingMatcher = {
657
- 1: consolidatedOptions.block.h1,
658
- 2: consolidatedOptions.block.h2,
659
- 3: consolidatedOptions.block.h3,
660
- 4: consolidatedOptions.block.h4,
661
- 5: consolidatedOptions.block.h5,
662
- 6: consolidatedOptions.block.h6
663
- }[level], style = headingMatcher?.({
664
- context: { schema: consolidatedOptions.schema }
665
- }) ?? consolidatedOptions.block.normal({
666
- context: { schema: consolidatedOptions.schema }
667
- });
668
- if (!style) {
669
- console.warn('No heading style found, using "normal"'), startBlock("normal");
765
+ // Headings
766
+ case "heading_open": {
767
+ const level = Number(token?.tag?.slice(1)), headingMatcher = {
768
+ 1: consolidatedOptions.block.h1,
769
+ 2: consolidatedOptions.block.h2,
770
+ 3: consolidatedOptions.block.h3,
771
+ 4: consolidatedOptions.block.h4,
772
+ 5: consolidatedOptions.block.h5,
773
+ 6: consolidatedOptions.block.h6
774
+ }[level], style = headingMatcher?.({
775
+ context: { schema: consolidatedOptions.schema }
776
+ }) ?? consolidatedOptions.block.normal({
777
+ context: { schema: consolidatedOptions.schema }
778
+ });
779
+ if (!style) {
780
+ console.warn('No heading style found, using "normal"'), startBlock("normal");
781
+ break;
782
+ }
783
+ startBlock(style);
670
784
  break;
671
785
  }
672
- startBlock(style);
673
- break;
674
- }
675
- case "heading_close":
676
- flushBlock();
677
- break;
678
- // Blockquote
679
- case "blockquote_open": {
680
- flushBlock(), currentBlockquoteStyle = consolidatedOptions.block.blockquote({
681
- context: { schema: consolidatedOptions.schema }
682
- }) ?? consolidatedOptions.block.normal({
683
- context: { schema: consolidatedOptions.schema }
684
- }) ?? "normal";
685
- break;
686
- }
687
- case "blockquote_close": {
688
- flushBlock(), currentBlockquoteStyle = null;
689
- break;
690
- }
691
- // Lists
692
- case "bullet_list_open": {
693
- const listItem = consolidatedOptions.listItem.bullet({
694
- context: { schema: consolidatedOptions.schema }
695
- });
696
- if (!listItem) {
697
- currentListStack.push(null);
786
+ case "heading_close":
787
+ flushBlock();
788
+ break;
789
+ // Blockquote
790
+ case "blockquote_open": {
791
+ if (flushBlock(), consolidatedOptions.types.blockquote) {
792
+ const startTarget = blockTarget();
793
+ blockquoteStack.push({
794
+ startTarget,
795
+ startIndex: startTarget.length
796
+ });
797
+ break;
798
+ }
799
+ currentBlockquoteStyle = consolidatedOptions.block.blockquote({
800
+ context: { schema: consolidatedOptions.schema }
801
+ }) ?? consolidatedOptions.block.normal({
802
+ context: { schema: consolidatedOptions.schema }
803
+ }) ?? "normal";
698
804
  break;
699
805
  }
700
- currentListStack.push(listItem);
701
- break;
702
- }
703
- case "ordered_list_open": {
704
- const listItem = consolidatedOptions.listItem.number({
705
- context: { schema: consolidatedOptions.schema }
706
- });
707
- if (!listItem) {
708
- currentListStack.push(null);
806
+ case "blockquote_close": {
807
+ if (flushBlock(), consolidatedOptions.types.blockquote && blockquoteStack.length > 0) {
808
+ const frame = blockquoteStack.pop();
809
+ if (frame) {
810
+ const contentBlocks = frame.startTarget.splice(
811
+ frame.startIndex
812
+ ), blockquoteObject = consolidatedOptions.types.blockquote({
813
+ context: {
814
+ schema: consolidatedOptions.schema,
815
+ keyGenerator: consolidatedOptions.keyGenerator
816
+ },
817
+ value: { content: contentBlocks },
818
+ isInline: !1
819
+ });
820
+ if (blockquoteObject)
821
+ pushBlock(blockquoteObject);
822
+ else {
823
+ const blockquoteStyle = consolidatedOptions.block.blockquote({
824
+ context: { schema: consolidatedOptions.schema }
825
+ }) ?? consolidatedOptions.block.normal({
826
+ context: { schema: consolidatedOptions.schema }
827
+ }) ?? "blockquote";
828
+ for (const block of contentBlocks)
829
+ block._type === "block" ? pushBlock({
830
+ ...block,
831
+ style: blockquoteStyle
832
+ }) : pushBlock(block);
833
+ }
834
+ }
835
+ break;
836
+ }
837
+ currentBlockquoteStyle = null;
709
838
  break;
710
839
  }
711
- currentListStack.push(listItem);
712
- break;
713
- }
714
- case "bullet_list_close":
715
- case "ordered_list_close":
716
- currentListStack.pop();
717
- break;
718
- case "list_item_open": {
719
- const listType = currentListStack.at(-1);
720
- if (listType === void 0)
721
- throw new Error("Expected an open list");
722
- if (currentBlock && flushBlock(), listType === null) {
723
- const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
840
+ // Lists
841
+ case "bullet_list_open": {
842
+ if (flushBlock(), consolidatedOptions.types.list) {
843
+ listContainerStack.push({
844
+ kind: "bullet",
845
+ items: [],
846
+ currentItem: null
847
+ }), currentListStack.push(null);
848
+ break;
849
+ }
850
+ const listItem = consolidatedOptions.listItem.bullet({
724
851
  context: { schema: consolidatedOptions.schema }
725
852
  });
726
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), inListItem = !0;
853
+ if (listContainerStack.push(null), !listItem) {
854
+ currentListStack.push(null);
855
+ break;
856
+ }
857
+ currentListStack.push(listItem);
727
858
  break;
728
859
  }
729
- ensureListBlock(listType), inListItem = !0;
730
- break;
731
- }
732
- case "list_item_close":
733
- inListItem = !1, flushBlock();
734
- break;
735
- // Code fences / blocks
736
- case "fence": {
737
- flushBlock();
738
- const language = token.info.trim() || void 0, code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
739
- context: {
740
- schema: consolidatedOptions.schema,
741
- keyGenerator: consolidatedOptions.keyGenerator
742
- },
743
- value: { language, code },
744
- isInline: !1
745
- });
746
- if (!codeObject) {
747
- const style = consolidatedOptions.block.normal({
860
+ case "ordered_list_open": {
861
+ if (flushBlock(), consolidatedOptions.types.list) {
862
+ listContainerStack.push({
863
+ kind: "number",
864
+ items: [],
865
+ currentItem: null
866
+ }), currentListStack.push(null);
867
+ break;
868
+ }
869
+ const listItem = consolidatedOptions.listItem.number({
748
870
  context: { schema: consolidatedOptions.schema }
749
871
  });
750
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(code), flushBlock();
872
+ if (listContainerStack.push(null), !listItem) {
873
+ currentListStack.push(null);
874
+ break;
875
+ }
876
+ currentListStack.push(listItem);
751
877
  break;
752
878
  }
753
- portableText.push(codeObject);
754
- break;
755
- }
756
- // Horizontal rule
757
- case "hr": {
758
- flushBlock();
759
- const hrObject = consolidatedOptions.types.horizontalRule({
760
- context: {
761
- schema: consolidatedOptions.schema,
762
- keyGenerator: consolidatedOptions.keyGenerator
763
- },
764
- value: {},
765
- isInline: !1
766
- });
767
- if (!hrObject) {
768
- const style = consolidatedOptions.block.normal({
769
- context: { schema: consolidatedOptions.schema }
770
- });
771
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan("---"), flushBlock();
879
+ case "bullet_list_close":
880
+ case "ordered_list_close": {
881
+ const frame = listContainerStack.pop();
882
+ if (currentListStack.pop(), frame && consolidatedOptions.types.list) {
883
+ const kind = frame.items.some(
884
+ (item) => "checked" in item
885
+ ) ? "task" : frame.kind, listObject = consolidatedOptions.types.list({
886
+ context: {
887
+ schema: consolidatedOptions.schema,
888
+ keyGenerator: consolidatedOptions.keyGenerator
889
+ },
890
+ value: { kind, items: frame.items },
891
+ isInline: !1
892
+ });
893
+ if (listObject)
894
+ pushBlock(listObject);
895
+ else {
896
+ const flatListItem = (kind === "task" ? consolidatedOptions.listItem.task?.({
897
+ context: { schema: consolidatedOptions.schema }
898
+ }) : kind === "number" ? consolidatedOptions.listItem.number({
899
+ context: { schema: consolidatedOptions.schema }
900
+ }) : consolidatedOptions.listItem.bullet({
901
+ context: { schema: consolidatedOptions.schema }
902
+ })) ?? null, level = listContainerStack.length + 1;
903
+ for (const item of frame.items)
904
+ for (const block of item.content)
905
+ if (block._type === "block" && flatListItem !== null && !("listItem" in block)) {
906
+ const flatBlock = {
907
+ ...block,
908
+ listItem: flatListItem,
909
+ level,
910
+ ...item.checked === void 0 ? {} : { checked: item.checked }
911
+ };
912
+ pushBlock(flatBlock);
913
+ } else
914
+ pushBlock(block);
915
+ }
916
+ }
772
917
  break;
773
918
  }
774
- portableText.push(hrObject);
775
- break;
776
- }
777
- // HTML block
778
- case "html_block": {
779
- flushBlock();
780
- const htmlContent = token.content.trim();
781
- if (!htmlContent)
919
+ case "list_item_open": {
920
+ const frame = listContainerStack.at(-1);
921
+ if (currentBlock && flushBlock(), frame) {
922
+ const taskChecked2 = taskCheckedByListItemIndex.get(tokenIndex);
923
+ frame.currentItem = {
924
+ _type: "list-item",
925
+ _key: consolidatedOptions.keyGenerator(),
926
+ ...taskChecked2 === void 0 ? {} : { checked: taskChecked2 },
927
+ content: []
928
+ }, inListItem = !0;
929
+ break;
930
+ }
931
+ const baseListType = currentListStack.at(-1);
932
+ if (baseListType === void 0)
933
+ throw new Error("Expected an open list");
934
+ const taskChecked = taskCheckedByListItemIndex.get(tokenIndex);
935
+ let listType = baseListType, checked;
936
+ if (taskChecked !== void 0) {
937
+ const taskListType = consolidatedOptions.listItem.task?.({
938
+ context: { schema: consolidatedOptions.schema }
939
+ });
940
+ taskListType && (listType = taskListType, checked = taskChecked);
941
+ }
942
+ if (listType === null) {
943
+ const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
944
+ context: { schema: consolidatedOptions.schema }
945
+ });
946
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), inListItem = !0;
947
+ break;
948
+ }
949
+ ensureListBlock(listType, checked), inListItem = !0;
782
950
  break;
783
- const htmlObject = consolidatedOptions.types.html({
784
- context: {
785
- schema: consolidatedOptions.schema,
786
- keyGenerator: consolidatedOptions.keyGenerator
787
- },
788
- value: { html: htmlContent },
789
- isInline: !1
790
- });
791
- if (!htmlObject) {
792
- const style = consolidatedOptions.block.normal({
793
- context: { schema: consolidatedOptions.schema }
794
- });
795
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(htmlContent), flushBlock();
951
+ }
952
+ case "list_item_close": {
953
+ const frame = listContainerStack.at(-1);
954
+ if (frame && frame.currentItem) {
955
+ flushBlock(), frame.items.push(frame.currentItem), frame.currentItem = null, inListItem = !1;
956
+ break;
957
+ }
958
+ inListItem = !1, flushBlock();
796
959
  break;
797
960
  }
798
- portableText.push(htmlObject);
799
- break;
800
- }
801
- case "code_block": {
802
- flushBlock();
803
- const code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
804
- context: {
805
- schema: consolidatedOptions.schema,
806
- keyGenerator: consolidatedOptions.keyGenerator
807
- },
808
- value: { language: void 0, code },
809
- isInline: !1
810
- });
811
- if (codeObject)
812
- portableText.push(codeObject);
813
- else {
814
- const style = consolidatedOptions.block.normal({
815
- context: { schema: consolidatedOptions.schema }
961
+ // Code fences / blocks
962
+ case "fence": {
963
+ flushBlock();
964
+ const language = token.info.trim() || void 0, code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
965
+ context: {
966
+ schema: consolidatedOptions.schema,
967
+ keyGenerator: consolidatedOptions.keyGenerator
968
+ },
969
+ value: { language, code },
970
+ isInline: !1
816
971
  });
817
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(code), flushBlock();
818
- }
819
- break;
820
- }
821
- // Tables
822
- case "table_open":
823
- flushBlock(), currentTable = { rows: [], headerRows: 0 };
824
- break;
825
- case "table_close": {
826
- if (!currentTable)
972
+ if (!codeObject) {
973
+ const style = consolidatedOptions.block.normal({
974
+ context: { schema: consolidatedOptions.schema }
975
+ });
976
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(code), flushBlock();
977
+ break;
978
+ }
979
+ pushBlock(codeObject);
827
980
  break;
828
- if (consolidatedOptions.types.table) {
829
- const tableObject = consolidatedOptions.types.table({
981
+ }
982
+ // Horizontal rule
983
+ case "hr": {
984
+ flushBlock();
985
+ const hrObject = consolidatedOptions.types.horizontalRule({
830
986
  context: {
831
987
  schema: consolidatedOptions.schema,
832
988
  keyGenerator: consolidatedOptions.keyGenerator
833
989
  },
834
- value: {
835
- rows: currentTable.rows,
836
- headerRows: currentTable.headerRows > 0 ? currentTable.headerRows : void 0
837
- },
990
+ value: {},
838
991
  isInline: !1
839
992
  });
840
- tableObject ? portableText.push(tableObject) : flattenTable(currentTable, portableText);
841
- } else
842
- flattenTable(currentTable, portableText);
843
- currentTable = null;
844
- break;
845
- }
846
- case "thead_open":
847
- inTableHead = !0;
848
- break;
849
- case "thead_close":
850
- inTableHead = !1;
851
- break;
852
- case "tbody_open":
853
- case "tbody_close":
854
- break;
855
- case "tr_open":
856
- currentTableRow = [];
857
- break;
858
- case "tr_close":
859
- currentTable && currentTableRow && (currentTable.rows.push({
860
- _key: consolidatedOptions.keyGenerator(),
861
- _type: "row",
862
- cells: currentTableRow
863
- }), inTableHead && currentTable.headerRows++), currentTableRow = null;
864
- break;
865
- case "th_open":
866
- case "td_open": {
867
- const style = consolidatedOptions.block.normal({
868
- context: { schema: consolidatedOptions.schema }
869
- });
870
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal"));
871
- break;
872
- }
873
- case "th_close":
874
- case "td_close": {
875
- flushBlock();
876
- const cellBlocks = [];
877
- if (portableText.length > 0) {
878
- const lastBlock = portableText.at(-1);
879
- lastBlock && lastBlock._type === "block" && cellBlocks.push(portableText.pop());
880
- }
881
- cellBlocks.length === 0 && cellBlocks.push({
882
- _type: "block",
883
- style: consolidatedOptions.block.normal({
884
- context: { schema: consolidatedOptions.schema }
885
- }) || "normal",
886
- children: [
887
- {
888
- _type: consolidatedOptions.schema.span.name,
889
- _key: consolidatedOptions.keyGenerator(),
890
- text: "",
891
- marks: []
892
- }
893
- ],
894
- _key: consolidatedOptions.keyGenerator(),
895
- markDefs: []
896
- });
897
- const firstBlock = cellBlocks[0];
898
- if (cellBlocks.length === 1 && firstBlock && firstBlock._type === "block" && "children" in firstBlock && Array.isArray(firstBlock.children) && firstBlock.children.length === 1) {
899
- const onlyChild = firstBlock.children[0];
900
- typeof onlyChild == "object" && onlyChild !== null && "_type" in onlyChild && onlyChild._type !== consolidatedOptions.schema.span.name && onlyChild._type === "image" && (cellBlocks[0] = onlyChild);
993
+ if (!hrObject) {
994
+ const style = consolidatedOptions.block.normal({
995
+ context: { schema: consolidatedOptions.schema }
996
+ });
997
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan("---"), flushBlock();
998
+ break;
999
+ }
1000
+ pushBlock(hrObject);
1001
+ break;
901
1002
  }
902
- currentTableRow !== null && currentTableRow.push({
903
- _type: "cell",
904
- _key: consolidatedOptions.keyGenerator(),
905
- value: cellBlocks
906
- });
907
- break;
908
- }
909
- // Inline container
910
- case "inline": {
911
- const inTableCell = currentTableRow !== null;
912
- if (token.children?.length === 1 && token.children[0]?.type === "image") {
913
- const imageToken = token.children[0];
914
- if (!imageToken)
1003
+ // HTML block
1004
+ case "html_block": {
1005
+ flushBlock();
1006
+ const htmlContent = token.content.trim();
1007
+ if (!htmlContent)
915
1008
  break;
916
- const src = imageToken.attrs?.find(([name]) => name === "src")?.at(1) || "", alt = unescapeImageAndLinkText(imageToken.content || ""), title = imageToken.attrs?.find(([name]) => name === "title")?.at(1) || void 0, blockImageObject = consolidatedOptions.types.image({
1009
+ const htmlObject = consolidatedOptions.types.html({
917
1010
  context: {
918
1011
  schema: consolidatedOptions.schema,
919
1012
  keyGenerator: consolidatedOptions.keyGenerator
920
1013
  },
921
- value: { src, alt, title },
1014
+ value: { html: htmlContent },
922
1015
  isInline: !1
923
1016
  });
924
- if (blockImageObject) {
925
- inTableCell ? currentBlock && "children" in currentBlock && currentBlock.children.push(
926
- blockImageObject
927
- ) : (currentBlock && "children" in currentBlock && currentBlock.children.length > 0 ? flushBlock() : (currentBlock = null, currentMarkDefs = []), portableText.push(blockImageObject));
1017
+ if (!htmlObject) {
1018
+ const style = consolidatedOptions.block.normal({
1019
+ context: { schema: consolidatedOptions.schema }
1020
+ });
1021
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(htmlContent), flushBlock();
928
1022
  break;
929
1023
  }
930
- const inlineImageObject = consolidatedOptions.types.image({
1024
+ pushBlock(htmlObject);
1025
+ break;
1026
+ }
1027
+ case "code_block": {
1028
+ flushBlock();
1029
+ const code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
931
1030
  context: {
932
1031
  schema: consolidatedOptions.schema,
933
1032
  keyGenerator: consolidatedOptions.keyGenerator
934
1033
  },
935
- value: { src, alt, title },
936
- isInline: !0
1034
+ value: { language: void 0, code },
1035
+ isInline: !1
937
1036
  });
938
- if (inlineImageObject) {
939
- if (!currentBlock)
940
- if (inListItem) {
941
- const listType = currentListStack.at(-1);
942
- listType && ensureListBlock(listType);
943
- } else {
944
- const style = consolidatedOptions.block.normal({
945
- context: { schema: consolidatedOptions.schema }
946
- });
947
- style && startBlock(style);
948
- }
949
- currentBlock && "children" in currentBlock && currentBlock.children.push(
950
- inlineImageObject
951
- );
1037
+ if (codeObject)
1038
+ pushBlock(codeObject);
1039
+ else {
1040
+ const style = consolidatedOptions.block.normal({
1041
+ context: { schema: consolidatedOptions.schema }
1042
+ });
1043
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(code), flushBlock();
1044
+ }
1045
+ break;
1046
+ }
1047
+ // Tables
1048
+ case "table_open":
1049
+ flushBlock(), currentTable = { rows: [], headerRows: 0 };
1050
+ break;
1051
+ case "table_close": {
1052
+ if (!currentTable)
952
1053
  break;
1054
+ if (consolidatedOptions.types.table) {
1055
+ const tableObject = consolidatedOptions.types.table({
1056
+ context: {
1057
+ schema: consolidatedOptions.schema,
1058
+ keyGenerator: consolidatedOptions.keyGenerator
1059
+ },
1060
+ value: {
1061
+ rows: currentTable.rows,
1062
+ headerRows: currentTable.headerRows > 0 ? currentTable.headerRows : void 0
1063
+ },
1064
+ isInline: !1
1065
+ });
1066
+ tableObject ? pushBlock(tableObject) : flattenTable(
1067
+ currentTable,
1068
+ blockTarget()
1069
+ );
1070
+ } else
1071
+ flattenTable(currentTable, blockTarget());
1072
+ currentTable = null;
1073
+ break;
1074
+ }
1075
+ case "thead_open":
1076
+ inTableHead = !0;
1077
+ break;
1078
+ case "thead_close":
1079
+ inTableHead = !1;
1080
+ break;
1081
+ case "tbody_open":
1082
+ case "tbody_close":
1083
+ break;
1084
+ case "tr_open":
1085
+ currentTableRow = [];
1086
+ break;
1087
+ case "tr_close":
1088
+ currentTable && currentTableRow && (currentTable.rows.push({
1089
+ _key: consolidatedOptions.keyGenerator(),
1090
+ _type: "row",
1091
+ cells: currentTableRow
1092
+ }), inTableHead && currentTable.headerRows++), currentTableRow = null;
1093
+ break;
1094
+ case "th_open":
1095
+ case "td_open": {
1096
+ const style = consolidatedOptions.block.normal({
1097
+ context: { schema: consolidatedOptions.schema }
1098
+ });
1099
+ style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal"));
1100
+ break;
1101
+ }
1102
+ case "th_close":
1103
+ case "td_close": {
1104
+ flushBlock();
1105
+ const cellBlocks = [], target = blockTarget();
1106
+ if (target.length > 0) {
1107
+ const lastBlock = target.at(-1);
1108
+ lastBlock && lastBlock._type === "block" && cellBlocks.push(target.pop());
953
1109
  }
954
- addSpan(`![${alt}](${src})`);
1110
+ cellBlocks.length === 0 && cellBlocks.push({
1111
+ _type: "block",
1112
+ style: consolidatedOptions.block.normal({
1113
+ context: { schema: consolidatedOptions.schema }
1114
+ }) || "normal",
1115
+ children: [
1116
+ {
1117
+ _type: consolidatedOptions.schema.span.name,
1118
+ _key: consolidatedOptions.keyGenerator(),
1119
+ text: "",
1120
+ marks: []
1121
+ }
1122
+ ],
1123
+ _key: consolidatedOptions.keyGenerator(),
1124
+ markDefs: []
1125
+ });
1126
+ const firstBlock = cellBlocks[0];
1127
+ if (cellBlocks.length === 1 && firstBlock && firstBlock._type === "block" && "children" in firstBlock && Array.isArray(firstBlock.children) && firstBlock.children.length === 1) {
1128
+ const onlyChild = firstBlock.children[0];
1129
+ typeof onlyChild == "object" && onlyChild !== null && "_type" in onlyChild && onlyChild._type !== consolidatedOptions.schema.span.name && onlyChild._type === "image" && (cellBlocks[0] = onlyChild);
1130
+ }
1131
+ currentTableRow !== null && currentTableRow.push({
1132
+ _type: "cell",
1133
+ _key: consolidatedOptions.keyGenerator(),
1134
+ value: cellBlocks
1135
+ });
955
1136
  break;
956
1137
  }
957
- for (const childToken of token.children ?? [])
958
- switch (childToken.type) {
959
- case "text":
960
- addSpan(childToken.content);
1138
+ // Inline container
1139
+ case "inline": {
1140
+ const inTableCell = currentTableRow !== null;
1141
+ if (token.children?.length === 1 && token.children[0]?.type === "image") {
1142
+ const imageToken = token.children[0];
1143
+ if (!imageToken)
961
1144
  break;
962
- case "softbreak":
963
- case "hardbreak":
964
- addSpan(`
965
- `);
966
- break;
967
- case "code_inline": {
968
- const decorator = consolidatedOptions.marks.code({
969
- context: { schema: consolidatedOptions.schema }
970
- });
971
- if (!decorator) {
972
- addSpan(childToken.content);
973
- break;
974
- }
975
- markDefRefs.push(decorator), addSpan(childToken.content);
976
- const index = markDefRefs.lastIndexOf(decorator);
977
- index !== -1 && markDefRefs.splice(index, 1);
1145
+ const src = imageToken.attrs?.find(([name]) => name === "src")?.at(1) || "", alt = unescapeImageAndLinkText(imageToken.content || ""), title = imageToken.attrs?.find(([name]) => name === "title")?.at(1) || void 0, blockImageObject = consolidatedOptions.types.image({
1146
+ context: {
1147
+ schema: consolidatedOptions.schema,
1148
+ keyGenerator: consolidatedOptions.keyGenerator
1149
+ },
1150
+ value: { src, alt, title },
1151
+ isInline: !1
1152
+ });
1153
+ if (blockImageObject) {
1154
+ inTableCell ? currentBlock && "children" in currentBlock && currentBlock.children.push(
1155
+ blockImageObject
1156
+ ) : (currentBlock && "children" in currentBlock && currentBlock.children.length > 0 ? flushBlock() : (currentBlock = null, currentMarkDefs = []), pushBlock(blockImageObject));
978
1157
  break;
979
1158
  }
980
- case "strong_open": {
981
- const decorator = consolidatedOptions.marks.strong({
982
- context: { schema: consolidatedOptions.schema }
983
- });
984
- if (!decorator)
985
- break;
986
- markDefRefs.push(decorator);
1159
+ const inlineImageObject = consolidatedOptions.types.image({
1160
+ context: {
1161
+ schema: consolidatedOptions.schema,
1162
+ keyGenerator: consolidatedOptions.keyGenerator
1163
+ },
1164
+ value: { src, alt, title },
1165
+ isInline: !0
1166
+ });
1167
+ if (inlineImageObject) {
1168
+ if (!currentBlock)
1169
+ if (inListItem)
1170
+ if (listContainerStack.at(-1)) {
1171
+ const style = consolidatedOptions.block.normal({
1172
+ context: { schema: consolidatedOptions.schema }
1173
+ }) ?? "normal";
1174
+ startBlock(style);
1175
+ } else {
1176
+ const listType = currentListStack.at(-1);
1177
+ listType && ensureListBlock(listType);
1178
+ }
1179
+ else {
1180
+ const style = consolidatedOptions.block.normal({
1181
+ context: { schema: consolidatedOptions.schema }
1182
+ });
1183
+ style && startBlock(style);
1184
+ }
1185
+ currentBlock && "children" in currentBlock && currentBlock.children.push(
1186
+ inlineImageObject
1187
+ );
987
1188
  break;
988
1189
  }
989
- case "strong_close": {
990
- const decorator = consolidatedOptions.marks.strong({
991
- context: { schema: consolidatedOptions.schema }
992
- });
993
- if (!decorator)
1190
+ addSpan(`![${alt}](${src})`);
1191
+ break;
1192
+ }
1193
+ for (const childToken of token.children ?? [])
1194
+ switch (childToken.type) {
1195
+ case "text":
1196
+ addSpan(childToken.content);
994
1197
  break;
995
- const index = markDefRefs.lastIndexOf(decorator);
996
- index !== -1 && markDefRefs.splice(index, 1);
997
- break;
998
- }
999
- case "em_open": {
1000
- const decorator = consolidatedOptions.marks.em({
1001
- context: { schema: consolidatedOptions.schema }
1002
- });
1003
- if (!decorator)
1198
+ case "softbreak":
1199
+ case "hardbreak":
1200
+ addSpan(`
1201
+ `);
1004
1202
  break;
1005
- markDefRefs.push(decorator);
1006
- break;
1007
- }
1008
- case "em_close": {
1009
- const decorator = consolidatedOptions.marks.em({
1010
- context: { schema: consolidatedOptions.schema }
1011
- });
1012
- if (!decorator)
1203
+ case "code_inline": {
1204
+ const decorator = consolidatedOptions.marks.code({
1205
+ context: { schema: consolidatedOptions.schema }
1206
+ });
1207
+ if (!decorator) {
1208
+ addSpan(childToken.content);
1209
+ break;
1210
+ }
1211
+ markDefRefs.push(decorator), addSpan(childToken.content);
1212
+ const index = markDefRefs.lastIndexOf(decorator);
1213
+ index !== -1 && markDefRefs.splice(index, 1);
1013
1214
  break;
1014
- const index = markDefRefs.lastIndexOf(decorator);
1015
- index !== -1 && markDefRefs.splice(index, 1);
1016
- break;
1017
- }
1018
- case "s_open": {
1019
- const decorator = consolidatedOptions.marks.strikeThrough({
1020
- context: { schema: consolidatedOptions.schema }
1021
- });
1022
- if (!decorator)
1215
+ }
1216
+ case "strong_open": {
1217
+ const decorator = consolidatedOptions.marks.strong({
1218
+ context: { schema: consolidatedOptions.schema }
1219
+ });
1220
+ if (!decorator)
1221
+ break;
1222
+ markDefRefs.push(decorator);
1023
1223
  break;
1024
- markDefRefs.push(decorator);
1025
- break;
1026
- }
1027
- case "s_close": {
1028
- const decorator = consolidatedOptions.marks.strikeThrough({
1029
- context: { schema: consolidatedOptions.schema }
1030
- });
1031
- if (!decorator)
1224
+ }
1225
+ case "strong_close": {
1226
+ const decorator = consolidatedOptions.marks.strong({
1227
+ context: { schema: consolidatedOptions.schema }
1228
+ });
1229
+ if (!decorator)
1230
+ break;
1231
+ const index = markDefRefs.lastIndexOf(decorator);
1232
+ index !== -1 && markDefRefs.splice(index, 1);
1032
1233
  break;
1033
- const index = markDefRefs.lastIndexOf(decorator);
1034
- index !== -1 && markDefRefs.splice(index, 1);
1035
- break;
1036
- }
1037
- case "link_open": {
1038
- const href = childToken.attrs?.find(([name]) => name === "href")?.at(1);
1039
- if (!href)
1234
+ }
1235
+ case "em_open": {
1236
+ const decorator = consolidatedOptions.marks.em({
1237
+ context: { schema: consolidatedOptions.schema }
1238
+ });
1239
+ if (!decorator)
1240
+ break;
1241
+ markDefRefs.push(decorator);
1040
1242
  break;
1041
- const title = childToken.attrs?.find(([name]) => name === "title")?.at(1), linkObject = consolidatedOptions.marks.link({
1042
- context: {
1043
- schema: consolidatedOptions.schema,
1044
- keyGenerator: consolidatedOptions.keyGenerator
1045
- },
1046
- value: { href, title }
1047
- });
1048
- if (!linkObject)
1243
+ }
1244
+ case "em_close": {
1245
+ const decorator = consolidatedOptions.marks.em({
1246
+ context: { schema: consolidatedOptions.schema }
1247
+ });
1248
+ if (!decorator)
1249
+ break;
1250
+ const index = markDefRefs.lastIndexOf(decorator);
1251
+ index !== -1 && markDefRefs.splice(index, 1);
1049
1252
  break;
1050
- currentMarkDefs.push(linkObject), markDefRefs.push(linkObject._key);
1051
- break;
1052
- }
1053
- case "link_close": {
1054
- const markDefKeys = new Set(currentMarkDefs.map((d) => d._key));
1055
- let lastLinkIndex;
1056
- for (const markDefRef of markDefRefs.reverse())
1057
- if (markDefKeys.has(markDefRef)) {
1058
- lastLinkIndex = markDefRefs.indexOf(markDefRef);
1253
+ }
1254
+ case "s_open": {
1255
+ const decorator = consolidatedOptions.marks.strikeThrough({
1256
+ context: { schema: consolidatedOptions.schema }
1257
+ });
1258
+ if (!decorator)
1059
1259
  break;
1060
- }
1061
- if (lastLinkIndex !== void 0) {
1062
- const realIndex = markDefRefs.length - 1 - lastLinkIndex;
1063
- markDefRefs.splice(realIndex, 1);
1260
+ markDefRefs.push(decorator);
1261
+ break;
1064
1262
  }
1065
- break;
1066
- }
1067
- case "image": {
1068
- const src = childToken.attrs?.find(([name]) => name === "src")?.at(1) || "", alt = unescapeImageAndLinkText(childToken.content || ""), inlineImageObject = consolidatedOptions.types.image({
1069
- context: {
1070
- schema: consolidatedOptions.schema,
1071
- keyGenerator: consolidatedOptions.keyGenerator
1072
- },
1073
- value: { src, alt, title: void 0 },
1074
- isInline: !0
1075
- });
1076
- if (inlineImageObject) {
1077
- if (!currentBlock) {
1078
- const style2 = consolidatedOptions.block.normal({
1079
- context: { schema: consolidatedOptions.schema }
1080
- });
1081
- style2 ? startBlock(style2) : (console.warn('No default style found, using "normal"'), startBlock("normal"));
1263
+ case "s_close": {
1264
+ const decorator = consolidatedOptions.marks.strikeThrough({
1265
+ context: { schema: consolidatedOptions.schema }
1266
+ });
1267
+ if (!decorator)
1268
+ break;
1269
+ const index = markDefRefs.lastIndexOf(decorator);
1270
+ index !== -1 && markDefRefs.splice(index, 1);
1271
+ break;
1272
+ }
1273
+ case "link_open": {
1274
+ const href = childToken.attrs?.find(([name]) => name === "href")?.at(1);
1275
+ if (!href)
1276
+ break;
1277
+ const title = childToken.attrs?.find(([name]) => name === "title")?.at(1), linkObject = consolidatedOptions.marks.link({
1278
+ context: {
1279
+ schema: consolidatedOptions.schema,
1280
+ keyGenerator: consolidatedOptions.keyGenerator
1281
+ },
1282
+ value: { href, title }
1283
+ });
1284
+ if (!linkObject)
1285
+ break;
1286
+ currentMarkDefs.push(linkObject), markDefRefs.push(linkObject._key);
1287
+ break;
1288
+ }
1289
+ case "link_close": {
1290
+ const markDefKeys = new Set(currentMarkDefs.map((d) => d._key));
1291
+ let lastLinkIndex;
1292
+ for (const markDefRef of markDefRefs.reverse())
1293
+ if (markDefKeys.has(markDefRef)) {
1294
+ lastLinkIndex = markDefRefs.indexOf(markDefRef);
1295
+ break;
1296
+ }
1297
+ if (lastLinkIndex !== void 0) {
1298
+ const realIndex = markDefRefs.length - 1 - lastLinkIndex;
1299
+ markDefRefs.splice(realIndex, 1);
1082
1300
  }
1083
- if (!currentBlock)
1084
- throw new Error("Expected current block after startBlock");
1085
- currentBlock.children.push(
1086
- inlineImageObject
1087
- );
1088
1301
  break;
1089
1302
  }
1090
- const blockImageObject = consolidatedOptions.types.image({
1091
- context: {
1092
- schema: consolidatedOptions.schema,
1093
- keyGenerator: consolidatedOptions.keyGenerator
1094
- },
1095
- value: { src, alt, title: void 0 },
1096
- isInline: !1
1097
- });
1098
- if (!blockImageObject) {
1099
- addSpan(`![${alt}](${src})`);
1303
+ case "image": {
1304
+ const src = childToken.attrs?.find(([name]) => name === "src")?.at(1) || "", alt = unescapeImageAndLinkText(childToken.content || ""), inlineImageObject = consolidatedOptions.types.image({
1305
+ context: {
1306
+ schema: consolidatedOptions.schema,
1307
+ keyGenerator: consolidatedOptions.keyGenerator
1308
+ },
1309
+ value: { src, alt, title: void 0 },
1310
+ isInline: !0
1311
+ });
1312
+ if (inlineImageObject) {
1313
+ if (!currentBlock) {
1314
+ const style2 = consolidatedOptions.block.normal({
1315
+ context: { schema: consolidatedOptions.schema }
1316
+ });
1317
+ style2 ? startBlock(style2) : (console.warn('No default style found, using "normal"'), startBlock("normal"));
1318
+ }
1319
+ if (!currentBlock)
1320
+ throw new Error("Expected current block after startBlock");
1321
+ currentBlock.children.push(
1322
+ inlineImageObject
1323
+ );
1324
+ break;
1325
+ }
1326
+ const blockImageObject = consolidatedOptions.types.image({
1327
+ context: {
1328
+ schema: consolidatedOptions.schema,
1329
+ keyGenerator: consolidatedOptions.keyGenerator
1330
+ },
1331
+ value: { src, alt, title: void 0 },
1332
+ isInline: !1
1333
+ });
1334
+ if (!blockImageObject) {
1335
+ addSpan(`![${alt}](${src})`);
1336
+ break;
1337
+ }
1338
+ if (inTableCell) {
1339
+ currentBlock && "children" in currentBlock && currentBlock.children.push(
1340
+ blockImageObject
1341
+ );
1342
+ break;
1343
+ }
1344
+ flushBlock(), pushBlock(blockImageObject);
1345
+ const style = consolidatedOptions.block.normal({
1346
+ context: { schema: consolidatedOptions.schema }
1347
+ });
1348
+ style && startBlock(style);
1100
1349
  break;
1101
1350
  }
1102
- if (inTableCell) {
1103
- currentBlock && "children" in currentBlock && currentBlock.children.push(
1104
- blockImageObject
1105
- );
1351
+ case "html_inline": {
1352
+ consolidatedOptions.html.inline === "text" && addSpan(childToken.content);
1106
1353
  break;
1107
1354
  }
1108
- flushBlock(), portableText.push(blockImageObject);
1109
- const style = consolidatedOptions.block.normal({
1110
- context: { schema: consolidatedOptions.schema }
1111
- });
1112
- style && startBlock(style);
1113
- break;
1114
- }
1115
- case "html_inline": {
1116
- consolidatedOptions.html.inline === "text" && addSpan(childToken.content);
1117
- break;
1118
1355
  }
1356
+ break;
1357
+ }
1358
+ // Callouts (GFM alerts)
1359
+ case "alert_open": {
1360
+ flushBlock(), calloutStartTarget = blockTarget(), calloutStartIndex = calloutStartTarget.length, calloutType = token.markup, currentBlockquoteStyle = consolidatedOptions.block.blockquote({
1361
+ context: { schema: consolidatedOptions.schema }
1362
+ }) ?? consolidatedOptions.block.normal({
1363
+ context: { schema: consolidatedOptions.schema }
1364
+ }) ?? "normal";
1365
+ break;
1366
+ }
1367
+ case "alert_title":
1368
+ break;
1369
+ case "alert_close": {
1370
+ if (flushBlock(), calloutStartIndex !== null && calloutType !== null && calloutStartTarget !== null) {
1371
+ const contentBlocks = calloutStartTarget.splice(
1372
+ calloutStartIndex
1373
+ ), calloutObject = consolidatedOptions.types.callout?.({
1374
+ context: {
1375
+ schema: consolidatedOptions.schema,
1376
+ keyGenerator: consolidatedOptions.keyGenerator
1377
+ },
1378
+ value: { tone: calloutType, content: contentBlocks },
1379
+ isInline: !1
1380
+ });
1381
+ if (calloutObject)
1382
+ pushBlock(calloutObject);
1383
+ else
1384
+ for (const block of contentBlocks)
1385
+ pushBlock(block);
1119
1386
  }
1120
- break;
1121
- }
1122
- // Callouts (GFM alerts)
1123
- case "alert_open": {
1124
- flushBlock(), calloutStartIndex = portableText.length, calloutType = token.markup, currentBlockquoteStyle = consolidatedOptions.block.blockquote({
1125
- context: { schema: consolidatedOptions.schema }
1126
- }) ?? consolidatedOptions.block.normal({
1127
- context: { schema: consolidatedOptions.schema }
1128
- }) ?? "normal";
1129
- break;
1130
- }
1131
- case "alert_title":
1132
- break;
1133
- case "alert_close": {
1134
- if (flushBlock(), calloutStartIndex !== null && calloutType !== null) {
1135
- const contentBlocks = portableText.splice(calloutStartIndex), calloutObject = consolidatedOptions.types.callout?.({
1136
- context: {
1137
- schema: consolidatedOptions.schema,
1138
- keyGenerator: consolidatedOptions.keyGenerator
1139
- },
1140
- value: { tone: calloutType, content: contentBlocks },
1141
- isInline: !1
1142
- });
1143
- calloutObject ? portableText.push(calloutObject) : portableText.push(...contentBlocks);
1387
+ calloutStartIndex = null, calloutStartTarget = null, calloutType = null, currentBlockquoteStyle = null;
1388
+ break;
1144
1389
  }
1145
- calloutStartIndex = null, calloutType = null, currentBlockquoteStyle = null;
1146
- break;
1147
1390
  }
1148
- }
1391
+ }
1149
1392
  return flushBlock(), portableText;
1150
1393
  }
1151
1394
  export {
1152
1395
  DefaultBlockSpacingRenderer,
1396
+ DefaultBlockquoteObjectRenderer,
1153
1397
  DefaultBlockquoteRenderer,
1154
1398
  DefaultCalloutRenderer,
1155
1399
  DefaultCodeBlockRenderer,
@@ -1167,6 +1411,7 @@ export {
1167
1411
  DefaultImageRenderer,
1168
1412
  DefaultLinkRenderer,
1169
1413
  DefaultListItemRenderer,
1414
+ DefaultListRenderer,
1170
1415
  DefaultNormalRenderer,
1171
1416
  DefaultStrikeThroughRenderer,
1172
1417
  DefaultStrongRenderer,