@@ -90,7 +90,7 @@ interface Attributes {
9090}
9191
9292interface Operation {
93- attributes : Attributes
93+ attributes ? : Attributes
9494 insert : string
9595}
9696
@@ -509,9 +509,22 @@ export const transformOperationsToPhrasingContents = (
509509 ops : Operation [ ] ,
510510) : mdast . PhrasingContent [ ] => {
511511 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+ } )
513526 . map ( op => {
514- if ( op . attributes [ 'inline-component' ] ) {
527+ if ( isDefined ( op . attributes ) && op . attributes [ 'inline-component' ] ) {
515528 try {
516529 const inlineComponent = JSON . parse ( op . attributes [ 'inline-component' ] )
517530 if ( inlineComponent . type === 'mention_doc' ) {
@@ -521,7 +534,7 @@ export const transformOperationsToPhrasingContents = (
521534 link : inlineComponent . data . raw_url ,
522535 } ,
523536 insert : op . insert + inlineComponent . data . title ,
524- }
537+ } as Operation
525538 }
526539
527540 return op
@@ -533,7 +546,7 @@ export const transformOperationsToPhrasingContents = (
533546 return op
534547 } )
535548
536- let indexToMarks = operations . map ( ( { attributes } ) => {
549+ let indexToMarks = operations . map ( ( { attributes = { } } ) => {
537550 type SupportAttrName = 'italic' | 'bold' | 'strikethrough' | 'link'
538551
539552 const isSupportAttr = ( attr : string ) : attr is SupportAttrName =>
@@ -593,7 +606,7 @@ export const transformOperationsToPhrasingContents = (
593606 op : Operation ,
594607 ) : mdast . Text | mdast . InlineCode | InlineMath => {
595608 const { attributes, insert } = op
596- const { inlineCode, equation } = attributes
609+ const { inlineCode, equation } = attributes ?? { }
597610
598611 if ( inlineCode ) {
599612 return {
@@ -624,7 +637,7 @@ export const transformOperationsToPhrasingContents = (
624637 mark === 'link'
625638 ? {
626639 type : mark ,
627- url : decodeURIComponent ( op . attributes . link ?? '' ) ,
640+ url : decodeURIComponent ( op . attributes ? .link ?? '' ) ,
628641 children : [ node ] ,
629642 }
630643 : {
0 commit comments