@portabletext/markdown 1.1.4 → 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
@@ -1,5 +1,6 @@
1
1
  import { compileSchema, defineSchema, isTextBlock, isSpan } from "@portabletext/schema";
2
2
  import { isPortableTextListItemBlock, isPortableTextToolkitSpan, isPortableTextBlock, isPortableTextToolkitTextNode, buildMarksTree, spanToPlainText } from "@portabletext/toolkit";
3
+ import { alert } from "@mdit/plugin-alert";
3
4
  import markdownit from "markdown-it";
4
5
  function defaultKeyGenerator() {
5
6
  return randomKey(12);
@@ -155,8 +156,14 @@ const DefaultBlockSpacingRenderer = ({
155
156
  value,
156
157
  listIndex
157
158
  }) => {
158
- const listStyle = value.listItem || "bullet", level = value.level || 1;
159
- 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}`;
160
167
  }, DefaultUnknownListItemRenderer = ({
161
168
  children
162
169
  }) => `- ${children}
@@ -248,7 +255,67 @@ ${value.code}
248
255
  }
249
256
  return lines.join(`
250
257
  `);
251
- }, DefaultUnknownTypeRenderer = ({
258
+ }, DefaultCalloutRenderer = ({ value, renderNode }) => {
259
+ const prefixed = value.content.map(
260
+ (block, index) => renderNode({
261
+ node: { ...block, style: "normal" },
262
+ index,
263
+ isInline: !1,
264
+ renderNode
265
+ })
266
+ ).join(`
267
+
268
+ `).split(`
269
+ `).map((line) => line === "" ? ">" : `> ${line}`).join(`
270
+ `);
271
+ return `> [!${value.tone.toUpperCase()}]
272
+ ${prefixed}`;
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 = ({
252
319
  value,
253
320
  isInline
254
321
  }) => {
@@ -347,6 +414,8 @@ const normalStyleDefinition = {
347
414
  name: "number"
348
415
  }, defaultUnorderedListItemDefinition = {
349
416
  name: "bullet"
417
+ }, defaultTaskListItemDefinition = {
418
+ name: "task"
350
419
  }, defaultStrongDecoratorDefinition = {
351
420
  name: "strong"
352
421
  }, defaultEmDecoratorDefinition = {
@@ -385,8 +454,17 @@ const normalStyleDefinition = {
385
454
  { name: "headerRows", type: "number" },
386
455
  { name: "rows", type: "array" }
387
456
  ]
457
+ }, defaultCalloutObjectDefinition = {
458
+ name: "callout",
459
+ fields: [
460
+ { name: "tone", type: "string" },
461
+ { name: "content", type: "array" }
462
+ ]
388
463
  }, defaultSchema = compileSchema(
389
464
  defineSchema({
465
+ block: {
466
+ fields: [{ name: "checked", type: "boolean" }]
467
+ },
390
468
  styles: [
391
469
  normalStyleDefinition,
392
470
  h1StyleDefinition,
@@ -399,7 +477,8 @@ const normalStyleDefinition = {
399
477
  ],
400
478
  lists: [
401
479
  defaultOrderedListItemDefinition,
402
- defaultUnorderedListItemDefinition
480
+ defaultUnorderedListItemDefinition,
481
+ defaultTaskListItemDefinition
403
482
  ],
404
483
  decorators: [
405
484
  defaultStrongDecoratorDefinition,
@@ -409,10 +488,11 @@ const normalStyleDefinition = {
409
488
  ],
410
489
  annotations: [defaultLinkObjectDefinition],
411
490
  blockObjects: [
491
+ defaultCalloutObjectDefinition,
412
492
  defaultCodeObjectDefinition,
413
493
  defaultHorizontalRuleObjectDefinition,
414
- defaultImageObjectDefinition,
415
494
  defaultHtmlObjectDefinition,
495
+ defaultImageObjectDefinition,
416
496
  defaultTableObjectDefinition
417
497
  ],
418
498
  inlineObjects: [defaultImageObjectDefinition]
@@ -502,7 +582,8 @@ const codeBlockMatcher = ({ context, value, isInline }) => {
502
582
  },
503
583
  listItem: {
504
584
  number: buildListItemMatcher(defaultOrderedListItemDefinition),
505
- bullet: buildListItemMatcher(defaultUnorderedListItemDefinition)
585
+ bullet: buildListItemMatcher(defaultUnorderedListItemDefinition),
586
+ task: buildListItemMatcher(defaultTaskListItemDefinition)
506
587
  },
507
588
  marks: {
508
589
  strong: buildDecoratorMatcher(defaultStrongDecoratorDefinition),
@@ -517,7 +598,8 @@ const codeBlockMatcher = ({ context, value, isInline }) => {
517
598
  code: codeBlockMatcher,
518
599
  horizontalRule: buildObjectMatcher(defaultHorizontalRuleObjectDefinition),
519
600
  html: buildObjectMatcher(defaultHtmlObjectDefinition),
520
- image: imageBlockMatcher
601
+ image: imageBlockMatcher,
602
+ callout: buildObjectMatcher(defaultCalloutObjectDefinition)
521
603
  }
522
604
  };
523
605
  function flattenTable(table, portableText) {
@@ -553,11 +635,51 @@ function markdownToPortableText(markdown, options) {
553
635
  html: !0,
554
636
  linkify: !0,
555
637
  typographer: !0
556
- }).enable(["strikethrough", "table"]).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 = [];
557
668
  let currentBlock = null;
558
669
  const currentListStack = [], markDefRefs = [];
559
- let currentMarkDefs = [], currentBlockquoteStyle = null, inListItem = !1, currentTable = null, currentTableRow = null, inTableHead = !1;
560
- 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) => {
561
683
  flushBlock(), currentBlock = {
562
684
  _type: "block",
563
685
  style,
@@ -571,7 +693,7 @@ function markdownToPortableText(markdown, options) {
571
693
  _key: consolidatedOptions.keyGenerator(),
572
694
  text: "",
573
695
  marks: []
574
- }), currentBlock.markDefs = currentMarkDefs, portableText.push(currentBlock), currentBlock = null, currentMarkDefs = []);
696
+ }), currentBlock.markDefs = currentMarkDefs, pushBlock(currentBlock), currentBlock = null, currentMarkDefs = []);
575
697
  }, addSpan = (text) => {
576
698
  if (text.length === 0)
577
699
  return;
@@ -590,7 +712,7 @@ function markdownToPortableText(markdown, options) {
590
712
  text,
591
713
  marks: [...markDefRefs]
592
714
  });
593
- }, listLevel = () => currentListStack.length, ensureListBlock = (listItem) => {
715
+ }, listLevel = () => currentListStack.length, ensureListBlock = (listItem, checked) => {
594
716
  if (!currentBlock) {
595
717
  const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
596
718
  context: { schema: consolidatedOptions.schema }
@@ -599,508 +721,681 @@ function markdownToPortableText(markdown, options) {
599
721
  }
600
722
  if (!currentBlock)
601
723
  throw new Error("Expected current block");
602
- (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);
603
725
  };
604
- for (const token of tokens)
605
- switch (token.type) {
606
- // Paragraphs
607
- case "paragraph_open": {
608
- if (inListItem) {
609
- if (!currentBlock) {
610
- const listType = currentListStack.at(-1);
611
- 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;
612
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);
613
756
  break;
614
757
  }
615
- const style = currentBlockquoteStyle ?? consolidatedOptions.block.normal({
616
- context: { schema: consolidatedOptions.schema }
617
- });
618
- if (!style) {
619
- console.warn('No default style found, using "normal"'), startBlock("normal");
620
- break;
621
- }
622
- startBlock(style);
623
- break;
624
- }
625
- case "paragraph_close":
626
- if (inListItem)
758
+ case "paragraph_close":
759
+ if (inListItem) {
760
+ listContainerStack.at(-1) && flushBlock();
761
+ break;
762
+ }
763
+ flushBlock();
627
764
  break;
628
- flushBlock();
629
- break;
630
- // Headings
631
- case "heading_open": {
632
- const level = Number(token?.tag?.slice(1)), headingMatcher = {
633
- 1: consolidatedOptions.block.h1,
634
- 2: consolidatedOptions.block.h2,
635
- 3: consolidatedOptions.block.h3,
636
- 4: consolidatedOptions.block.h4,
637
- 5: consolidatedOptions.block.h5,
638
- 6: consolidatedOptions.block.h6
639
- }[level], style = headingMatcher?.({
640
- context: { schema: consolidatedOptions.schema }
641
- }) ?? consolidatedOptions.block.normal({
642
- context: { schema: consolidatedOptions.schema }
643
- });
644
- if (!style) {
645
- 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);
646
784
  break;
647
785
  }
648
- startBlock(style);
649
- break;
650
- }
651
- case "heading_close":
652
- flushBlock();
653
- break;
654
- // Blockquote
655
- case "blockquote_open": {
656
- flushBlock(), currentBlockquoteStyle = consolidatedOptions.block.blockquote({
657
- context: { schema: consolidatedOptions.schema }
658
- }) ?? consolidatedOptions.block.normal({
659
- context: { schema: consolidatedOptions.schema }
660
- }) ?? "normal";
661
- break;
662
- }
663
- case "blockquote_close": {
664
- flushBlock(), currentBlockquoteStyle = null;
665
- break;
666
- }
667
- // Lists
668
- case "bullet_list_open": {
669
- const listItem = consolidatedOptions.listItem.bullet({
670
- context: { schema: consolidatedOptions.schema }
671
- });
672
- if (!listItem) {
673
- 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";
674
804
  break;
675
805
  }
676
- currentListStack.push(listItem);
677
- break;
678
- }
679
- case "ordered_list_open": {
680
- const listItem = consolidatedOptions.listItem.number({
681
- context: { schema: consolidatedOptions.schema }
682
- });
683
- if (!listItem) {
684
- 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;
685
838
  break;
686
839
  }
687
- currentListStack.push(listItem);
688
- break;
689
- }
690
- case "bullet_list_close":
691
- case "ordered_list_close":
692
- currentListStack.pop();
693
- break;
694
- case "list_item_open": {
695
- const listType = currentListStack.at(-1);
696
- if (listType === void 0)
697
- throw new Error("Expected an open list");
698
- if (currentBlock && flushBlock(), listType === null) {
699
- 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({
700
851
  context: { schema: consolidatedOptions.schema }
701
852
  });
702
- 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);
703
858
  break;
704
859
  }
705
- ensureListBlock(listType), inListItem = !0;
706
- break;
707
- }
708
- case "list_item_close":
709
- inListItem = !1, flushBlock();
710
- break;
711
- // Code fences / blocks
712
- case "fence": {
713
- flushBlock();
714
- const language = token.info.trim() || void 0, code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
715
- context: {
716
- schema: consolidatedOptions.schema,
717
- keyGenerator: consolidatedOptions.keyGenerator
718
- },
719
- value: { language, code },
720
- isInline: !1
721
- });
722
- if (!codeObject) {
723
- 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({
724
870
  context: { schema: consolidatedOptions.schema }
725
871
  });
726
- 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);
727
877
  break;
728
878
  }
729
- portableText.push(codeObject);
730
- break;
731
- }
732
- // Horizontal rule
733
- case "hr": {
734
- flushBlock();
735
- const hrObject = consolidatedOptions.types.horizontalRule({
736
- context: {
737
- schema: consolidatedOptions.schema,
738
- keyGenerator: consolidatedOptions.keyGenerator
739
- },
740
- value: {},
741
- isInline: !1
742
- });
743
- if (!hrObject) {
744
- const style = consolidatedOptions.block.normal({
745
- context: { schema: consolidatedOptions.schema }
746
- });
747
- 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
+ }
748
917
  break;
749
918
  }
750
- portableText.push(hrObject);
751
- break;
752
- }
753
- // HTML block
754
- case "html_block": {
755
- flushBlock();
756
- const htmlContent = token.content.trim();
757
- 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;
758
950
  break;
759
- const htmlObject = consolidatedOptions.types.html({
760
- context: {
761
- schema: consolidatedOptions.schema,
762
- keyGenerator: consolidatedOptions.keyGenerator
763
- },
764
- value: { html: htmlContent },
765
- isInline: !1
766
- });
767
- if (!htmlObject) {
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(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();
772
959
  break;
773
960
  }
774
- portableText.push(htmlObject);
775
- break;
776
- }
777
- case "code_block": {
778
- flushBlock();
779
- const code = token.content.replace(/\n$/, ""), codeObject = consolidatedOptions.types.code({
780
- context: {
781
- schema: consolidatedOptions.schema,
782
- keyGenerator: consolidatedOptions.keyGenerator
783
- },
784
- value: { language: void 0, code },
785
- isInline: !1
786
- });
787
- if (codeObject)
788
- portableText.push(codeObject);
789
- else {
790
- const style = consolidatedOptions.block.normal({
791
- 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
792
971
  });
793
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal")), addSpan(code), flushBlock();
794
- }
795
- break;
796
- }
797
- // Tables
798
- case "table_open":
799
- flushBlock(), currentTable = { rows: [], headerRows: 0 };
800
- break;
801
- case "table_close": {
802
- 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);
803
980
  break;
804
- if (consolidatedOptions.types.table) {
805
- const tableObject = consolidatedOptions.types.table({
981
+ }
982
+ // Horizontal rule
983
+ case "hr": {
984
+ flushBlock();
985
+ const hrObject = consolidatedOptions.types.horizontalRule({
806
986
  context: {
807
987
  schema: consolidatedOptions.schema,
808
988
  keyGenerator: consolidatedOptions.keyGenerator
809
989
  },
810
- value: {
811
- rows: currentTable.rows,
812
- headerRows: currentTable.headerRows > 0 ? currentTable.headerRows : void 0
813
- },
990
+ value: {},
814
991
  isInline: !1
815
992
  });
816
- tableObject ? portableText.push(tableObject) : flattenTable(currentTable, portableText);
817
- } else
818
- flattenTable(currentTable, portableText);
819
- currentTable = null;
820
- break;
821
- }
822
- case "thead_open":
823
- inTableHead = !0;
824
- break;
825
- case "thead_close":
826
- inTableHead = !1;
827
- break;
828
- case "tbody_open":
829
- case "tbody_close":
830
- break;
831
- case "tr_open":
832
- currentTableRow = [];
833
- break;
834
- case "tr_close":
835
- currentTable && currentTableRow && (currentTable.rows.push({
836
- _key: consolidatedOptions.keyGenerator(),
837
- _type: "row",
838
- cells: currentTableRow
839
- }), inTableHead && currentTable.headerRows++), currentTableRow = null;
840
- break;
841
- case "th_open":
842
- case "td_open": {
843
- const style = consolidatedOptions.block.normal({
844
- context: { schema: consolidatedOptions.schema }
845
- });
846
- style ? startBlock(style) : (console.warn('No default style found, using "normal"'), startBlock("normal"));
847
- break;
848
- }
849
- case "th_close":
850
- case "td_close": {
851
- flushBlock();
852
- const cellBlocks = [];
853
- if (portableText.length > 0) {
854
- const lastBlock = portableText.at(-1);
855
- lastBlock && lastBlock._type === "block" && cellBlocks.push(portableText.pop());
856
- }
857
- cellBlocks.length === 0 && cellBlocks.push({
858
- _type: "block",
859
- style: consolidatedOptions.block.normal({
860
- context: { schema: consolidatedOptions.schema }
861
- }) || "normal",
862
- children: [
863
- {
864
- _type: consolidatedOptions.schema.span.name,
865
- _key: consolidatedOptions.keyGenerator(),
866
- text: "",
867
- marks: []
868
- }
869
- ],
870
- _key: consolidatedOptions.keyGenerator(),
871
- markDefs: []
872
- });
873
- const firstBlock = cellBlocks[0];
874
- if (cellBlocks.length === 1 && firstBlock && firstBlock._type === "block" && "children" in firstBlock && Array.isArray(firstBlock.children) && firstBlock.children.length === 1) {
875
- const onlyChild = firstBlock.children[0];
876
- 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;
877
1002
  }
878
- currentTableRow !== null && currentTableRow.push({
879
- _type: "cell",
880
- _key: consolidatedOptions.keyGenerator(),
881
- value: cellBlocks
882
- });
883
- break;
884
- }
885
- // Inline container
886
- case "inline": {
887
- const inTableCell = currentTableRow !== null;
888
- if (token.children?.length === 1 && token.children[0]?.type === "image") {
889
- const imageToken = token.children[0];
890
- if (!imageToken)
1003
+ // HTML block
1004
+ case "html_block": {
1005
+ flushBlock();
1006
+ const htmlContent = token.content.trim();
1007
+ if (!htmlContent)
891
1008
  break;
892
- 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({
893
1010
  context: {
894
1011
  schema: consolidatedOptions.schema,
895
1012
  keyGenerator: consolidatedOptions.keyGenerator
896
1013
  },
897
- value: { src, alt, title },
1014
+ value: { html: htmlContent },
898
1015
  isInline: !1
899
1016
  });
900
- if (blockImageObject) {
901
- inTableCell ? currentBlock && "children" in currentBlock && currentBlock.children.push(
902
- blockImageObject
903
- ) : (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();
904
1022
  break;
905
1023
  }
906
- 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({
907
1030
  context: {
908
1031
  schema: consolidatedOptions.schema,
909
1032
  keyGenerator: consolidatedOptions.keyGenerator
910
1033
  },
911
- value: { src, alt, title },
912
- isInline: !0
1034
+ value: { language: void 0, code },
1035
+ isInline: !1
913
1036
  });
914
- if (inlineImageObject) {
915
- if (!currentBlock)
916
- if (inListItem) {
917
- const listType = currentListStack.at(-1);
918
- listType && ensureListBlock(listType);
919
- } else {
920
- const style = consolidatedOptions.block.normal({
921
- context: { schema: consolidatedOptions.schema }
922
- });
923
- style && startBlock(style);
924
- }
925
- currentBlock && "children" in currentBlock && currentBlock.children.push(
926
- inlineImageObject
927
- );
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)
928
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());
1109
+ }
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);
929
1130
  }
930
- addSpan(`![${alt}](${src})`);
1131
+ currentTableRow !== null && currentTableRow.push({
1132
+ _type: "cell",
1133
+ _key: consolidatedOptions.keyGenerator(),
1134
+ value: cellBlocks
1135
+ });
931
1136
  break;
932
1137
  }
933
- for (const childToken of token.children ?? [])
934
- switch (childToken.type) {
935
- case "text":
936
- addSpan(childToken.content);
937
- break;
938
- case "softbreak":
939
- case "hardbreak":
940
- addSpan(`
941
- `);
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)
942
1144
  break;
943
- case "code_inline": {
944
- const decorator = consolidatedOptions.marks.code({
945
- context: { schema: consolidatedOptions.schema }
946
- });
947
- if (!decorator) {
948
- addSpan(childToken.content);
949
- break;
950
- }
951
- markDefRefs.push(decorator), addSpan(childToken.content);
952
- const index = markDefRefs.lastIndexOf(decorator);
953
- 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));
954
1157
  break;
955
1158
  }
956
- case "strong_open": {
957
- const decorator = consolidatedOptions.marks.strong({
958
- context: { schema: consolidatedOptions.schema }
959
- });
960
- if (!decorator)
961
- break;
962
- 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
+ );
963
1188
  break;
964
1189
  }
965
- case "strong_close": {
966
- const decorator = consolidatedOptions.marks.strong({
967
- context: { schema: consolidatedOptions.schema }
968
- });
969
- 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);
970
1197
  break;
971
- const index = markDefRefs.lastIndexOf(decorator);
972
- index !== -1 && markDefRefs.splice(index, 1);
973
- break;
974
- }
975
- case "em_open": {
976
- const decorator = consolidatedOptions.marks.em({
977
- context: { schema: consolidatedOptions.schema }
978
- });
979
- if (!decorator)
1198
+ case "softbreak":
1199
+ case "hardbreak":
1200
+ addSpan(`
1201
+ `);
980
1202
  break;
981
- markDefRefs.push(decorator);
982
- break;
983
- }
984
- case "em_close": {
985
- const decorator = consolidatedOptions.marks.em({
986
- context: { schema: consolidatedOptions.schema }
987
- });
988
- 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);
989
1214
  break;
990
- const index = markDefRefs.lastIndexOf(decorator);
991
- index !== -1 && markDefRefs.splice(index, 1);
992
- break;
993
- }
994
- case "s_open": {
995
- const decorator = consolidatedOptions.marks.strikeThrough({
996
- context: { schema: consolidatedOptions.schema }
997
- });
998
- 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);
999
1223
  break;
1000
- markDefRefs.push(decorator);
1001
- break;
1002
- }
1003
- case "s_close": {
1004
- const decorator = consolidatedOptions.marks.strikeThrough({
1005
- context: { schema: consolidatedOptions.schema }
1006
- });
1007
- 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);
1008
1233
  break;
1009
- const index = markDefRefs.lastIndexOf(decorator);
1010
- index !== -1 && markDefRefs.splice(index, 1);
1011
- break;
1012
- }
1013
- case "link_open": {
1014
- const href = childToken.attrs?.find(([name]) => name === "href")?.at(1);
1015
- 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);
1016
1242
  break;
1017
- const title = childToken.attrs?.find(([name]) => name === "title")?.at(1), linkObject = consolidatedOptions.marks.link({
1018
- context: {
1019
- schema: consolidatedOptions.schema,
1020
- keyGenerator: consolidatedOptions.keyGenerator
1021
- },
1022
- value: { href, title }
1023
- });
1024
- 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);
1025
1252
  break;
1026
- currentMarkDefs.push(linkObject), markDefRefs.push(linkObject._key);
1027
- break;
1028
- }
1029
- case "link_close": {
1030
- const markDefKeys = new Set(currentMarkDefs.map((d) => d._key));
1031
- let lastLinkIndex;
1032
- for (const markDefRef of markDefRefs.reverse())
1033
- if (markDefKeys.has(markDefRef)) {
1034
- lastLinkIndex = markDefRefs.indexOf(markDefRef);
1253
+ }
1254
+ case "s_open": {
1255
+ const decorator = consolidatedOptions.marks.strikeThrough({
1256
+ context: { schema: consolidatedOptions.schema }
1257
+ });
1258
+ if (!decorator)
1035
1259
  break;
1036
- }
1037
- if (lastLinkIndex !== void 0) {
1038
- const realIndex = markDefRefs.length - 1 - lastLinkIndex;
1039
- markDefRefs.splice(realIndex, 1);
1260
+ markDefRefs.push(decorator);
1261
+ break;
1040
1262
  }
1041
- break;
1042
- }
1043
- case "image": {
1044
- const src = childToken.attrs?.find(([name]) => name === "src")?.at(1) || "", alt = unescapeImageAndLinkText(childToken.content || ""), inlineImageObject = consolidatedOptions.types.image({
1045
- context: {
1046
- schema: consolidatedOptions.schema,
1047
- keyGenerator: consolidatedOptions.keyGenerator
1048
- },
1049
- value: { src, alt, title: void 0 },
1050
- isInline: !0
1051
- });
1052
- if (inlineImageObject) {
1053
- if (!currentBlock) {
1054
- const style2 = consolidatedOptions.block.normal({
1055
- context: { schema: consolidatedOptions.schema }
1056
- });
1057
- 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);
1058
1300
  }
1059
- if (!currentBlock)
1060
- throw new Error("Expected current block after startBlock");
1061
- currentBlock.children.push(
1062
- inlineImageObject
1063
- );
1064
1301
  break;
1065
1302
  }
1066
- const blockImageObject = consolidatedOptions.types.image({
1067
- context: {
1068
- schema: consolidatedOptions.schema,
1069
- keyGenerator: consolidatedOptions.keyGenerator
1070
- },
1071
- value: { src, alt, title: void 0 },
1072
- isInline: !1
1073
- });
1074
- if (!blockImageObject) {
1075
- 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);
1076
1349
  break;
1077
1350
  }
1078
- if (inTableCell) {
1079
- currentBlock && "children" in currentBlock && currentBlock.children.push(
1080
- blockImageObject
1081
- );
1351
+ case "html_inline": {
1352
+ consolidatedOptions.html.inline === "text" && addSpan(childToken.content);
1082
1353
  break;
1083
1354
  }
1084
- flushBlock(), portableText.push(blockImageObject);
1085
- const style = consolidatedOptions.block.normal({
1086
- context: { schema: consolidatedOptions.schema }
1087
- });
1088
- style && startBlock(style);
1089
- break;
1090
- }
1091
- case "html_inline": {
1092
- consolidatedOptions.html.inline === "text" && addSpan(childToken.content);
1093
- break;
1094
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);
1095
1386
  }
1096
- break;
1387
+ calloutStartIndex = null, calloutStartTarget = null, calloutType = null, currentBlockquoteStyle = null;
1388
+ break;
1389
+ }
1097
1390
  }
1098
- }
1391
+ }
1099
1392
  return flushBlock(), portableText;
1100
1393
  }
1101
1394
  export {
1102
1395
  DefaultBlockSpacingRenderer,
1396
+ DefaultBlockquoteObjectRenderer,
1103
1397
  DefaultBlockquoteRenderer,
1398
+ DefaultCalloutRenderer,
1104
1399
  DefaultCodeBlockRenderer,
1105
1400
  DefaultCodeRenderer,
1106
1401
  DefaultEmRenderer,
@@ -1116,6 +1411,7 @@ export {
1116
1411
  DefaultImageRenderer,
1117
1412
  DefaultLinkRenderer,
1118
1413
  DefaultListItemRenderer,
1414
+ DefaultListRenderer,
1119
1415
  DefaultNormalRenderer,
1120
1416
  DefaultStrikeThroughRenderer,
1121
1417
  DefaultStrongRenderer,