@@ -90,7 +90,7 @@ interface Attributes {
90
90
}
91
91
92
92
interface Operation {
93
- attributes : Attributes
93
+ attributes ? : Attributes
94
94
insert : string
95
95
}
96
96
@@ -509,9 +509,22 @@ export const transformOperationsToPhrasingContents = (
509
509
ops : Operation [ ] ,
510
510
) : mdast . PhrasingContent [ ] => {
511
511
const operations = ops
512
- . filter ( operation => ! operation . attributes . fixEnter )
512
+ . filter ( operation => {
513
+ if (
514
+ isDefined ( operation . attributes ) &&
515
+ isDefined ( operation . attributes . fixEnter )
516
+ ) {
517
+ return false
518
+ }
519
+
520
+ if ( ! isDefined ( operation . attributes ) && operation . insert === '\n' ) {
521
+ return false
522
+ }
523
+
524
+ return true
525
+ } )
513
526
. map ( op => {
514
- if ( op . attributes [ 'inline-component' ] ) {
527
+ if ( isDefined ( op . attributes ) && op . attributes [ 'inline-component' ] ) {
515
528
try {
516
529
const inlineComponent = JSON . parse ( op . attributes [ 'inline-component' ] )
517
530
if ( inlineComponent . type === 'mention_doc' ) {
@@ -521,7 +534,7 @@ export const transformOperationsToPhrasingContents = (
521
534
link : inlineComponent . data . raw_url ,
522
535
} ,
523
536
insert : op . insert + inlineComponent . data . title ,
524
- }
537
+ } as Operation
525
538
}
526
539
527
540
return op
@@ -533,7 +546,7 @@ export const transformOperationsToPhrasingContents = (
533
546
return op
534
547
} )
535
548
536
- let indexToMarks = operations . map ( ( { attributes } ) => {
549
+ let indexToMarks = operations . map ( ( { attributes = { } } ) => {
537
550
type SupportAttrName = 'italic' | 'bold' | 'strikethrough' | 'link'
538
551
539
552
const isSupportAttr = ( attr : string ) : attr is SupportAttrName =>
@@ -593,7 +606,7 @@ export const transformOperationsToPhrasingContents = (
593
606
op : Operation ,
594
607
) : mdast . Text | mdast . InlineCode | InlineMath => {
595
608
const { attributes, insert } = op
596
- const { inlineCode, equation } = attributes
609
+ const { inlineCode, equation } = attributes ?? { }
597
610
598
611
if ( inlineCode ) {
599
612
return {
@@ -624,7 +637,7 @@ export const transformOperationsToPhrasingContents = (
624
637
mark === 'link'
625
638
? {
626
639
type : mark ,
627
- url : decodeURIComponent ( op . attributes . link ?? '' ) ,
640
+ url : decodeURIComponent ( op . attributes ? .link ?? '' ) ,
628
641
children : [ node ] ,
629
642
}
630
643
: {
0 commit comments