@@ -258,7 +258,7 @@ function deltaToMdast(delta) {
258
258
// Handle newlines within text content
259
259
if ( text . includes ( "\n" ) && text !== "\n" ) {
260
260
const lines = text . split ( "\n" ) ;
261
-
261
+
262
262
// Process all lines except the last one as complete lines
263
263
for ( let i = 0 ; i < lines . length - 1 ; i ++ ) {
264
264
const line = lines [ i ] ;
@@ -271,13 +271,13 @@ function deltaToMdast(delta) {
271
271
currentParagraph . children . push ( ...nodes ) ;
272
272
textBuffer = line ;
273
273
}
274
-
274
+
275
275
// Process line break with empty attributes (regular paragraph break)
276
276
processLineBreak ( mdast , currentParagraph , { } , textBuffer , currentList ) ;
277
277
currentParagraph = null ;
278
278
textBuffer = "" ;
279
279
}
280
-
280
+
281
281
// Add the last line to the buffer without processing the line break yet
282
282
const lastLine = lines [ lines . length - 1 ] ;
283
283
if ( lastLine . length > 0 ) {
@@ -288,7 +288,7 @@ function deltaToMdast(delta) {
288
288
currentParagraph . children . push ( ...nodes ) ;
289
289
textBuffer = lastLine ;
290
290
}
291
-
291
+
292
292
continue ;
293
293
}
294
294
@@ -298,9 +298,9 @@ function deltaToMdast(delta) {
298
298
currentParagraph ,
299
299
attributes ,
300
300
textBuffer ,
301
- currentList
301
+ currentList ,
302
302
) ;
303
-
303
+
304
304
// Reset paragraph and buffer after processing line break
305
305
currentParagraph = null ;
306
306
textBuffer = "" ;
@@ -436,22 +436,27 @@ function processLineBreak(
436
436
if ( attributes . header ) {
437
437
processHeaderLineBreak ( mdast , textBuffer , attributes ) ;
438
438
return null ;
439
- }
440
-
439
+ }
440
+
441
441
if ( attributes [ "code-block" ] ) {
442
442
processCodeBlockLineBreak ( mdast , textBuffer , attributes ) ;
443
443
return currentList ;
444
- }
445
-
444
+ }
445
+
446
446
if ( attributes . list ) {
447
- return processListLineBreak ( mdast , currentParagraph , attributes , currentList ) ;
448
- }
449
-
447
+ return processListLineBreak (
448
+ mdast ,
449
+ currentParagraph ,
450
+ attributes ,
451
+ currentList ,
452
+ ) ;
453
+ }
454
+
450
455
if ( attributes . blockquote ) {
451
456
processBlockquoteLineBreak ( mdast , currentParagraph ) ;
452
457
return currentList ;
453
- }
454
-
458
+ }
459
+
455
460
// Default case: regular paragraph
456
461
mdast . children . push ( currentParagraph ) ;
457
462
return null ;
@@ -468,19 +473,19 @@ function handleEmptyLineWithAttributes(mdast, attributes, currentList) {
468
473
if ( attributes [ "code-block" ] ) {
469
474
mdast . children . push ( createEmptyCodeBlock ( attributes ) ) ;
470
475
return currentList ;
471
- }
472
-
476
+ }
477
+
473
478
if ( attributes . list ) {
474
479
const list = ensureList ( mdast , attributes , currentList ) ;
475
480
list . children . push ( createEmptyListItem ( ) ) ;
476
481
return list ;
477
- }
478
-
482
+ }
483
+
479
484
if ( attributes . blockquote ) {
480
485
mdast . children . push ( createEmptyBlockquote ( ) ) ;
481
486
return currentList ;
482
487
}
483
-
488
+
484
489
return null ;
485
490
}
486
491
@@ -566,7 +571,7 @@ function processHeaderLineBreak(mdast, textBuffer, attributes) {
566
571
function processCodeBlockLineBreak ( mdast , textBuffer , attributes ) {
567
572
const lang =
568
573
attributes [ "code-block" ] === "plain" ? null : attributes [ "code-block" ] ;
569
-
574
+
570
575
// Find the last code block with the same language
571
576
let lastCodeBlock = null ;
572
577
for ( let i = mdast . children . length - 1 ; i >= 0 ; i -- ) {
@@ -599,16 +604,20 @@ function processCodeBlockLineBreak(mdast, textBuffer, attributes) {
599
604
*/
600
605
function ensureList ( mdast , attributes , currentList ) {
601
606
const isOrderedList = attributes . list === "ordered" ;
602
-
607
+
603
608
// If there's no current list or the list type doesn't match
604
609
if ( ! currentList || currentList . ordered !== isOrderedList ) {
605
610
// Check if the last child is a list of the correct type
606
611
const lastChild = mdast . children [ mdast . children . length - 1 ] ;
607
- if ( lastChild && lastChild . type === "list" && lastChild . ordered === isOrderedList ) {
612
+ if (
613
+ lastChild &&
614
+ lastChild . type === "list" &&
615
+ lastChild . ordered === isOrderedList
616
+ ) {
608
617
// Use the last list if it matches the type
609
618
return lastChild ;
610
619
}
611
-
620
+
612
621
// Create a new list
613
622
const newList = {
614
623
type : "list" ,
@@ -619,7 +628,7 @@ function ensureList(mdast, attributes, currentList) {
619
628
mdast . children . push ( newList ) ;
620
629
return newList ;
621
630
}
622
-
631
+
623
632
return currentList ;
624
633
}
625
634
@@ -642,20 +651,21 @@ function processListLineBreak(
642
651
// Check if this list item already exists to avoid duplication
643
652
const paragraphContent = JSON . stringify ( currentParagraph . children ) ;
644
653
const isDuplicate = list . children . some (
645
- item => item . children ?. length === 1 &&
646
- JSON . stringify ( item . children [ 0 ] . children ) === paragraphContent
654
+ ( item ) =>
655
+ item . children ?. length === 1 &&
656
+ JSON . stringify ( item . children [ 0 ] . children ) === paragraphContent ,
647
657
) ;
648
-
658
+
649
659
if ( ! isDuplicate ) {
650
660
const listItem = {
651
661
type : "listItem" ,
652
662
spread : false ,
653
663
children : [ currentParagraph ] ,
654
664
} ;
655
-
665
+
656
666
list . children . push ( listItem ) ;
657
667
}
658
-
668
+
659
669
return list ;
660
670
}
661
671
@@ -669,11 +679,12 @@ function processBlockquoteLineBreak(mdast, currentParagraph) {
669
679
// Look for an existing blockquote with identical content to avoid duplication
670
680
const paragraphContent = JSON . stringify ( currentParagraph . children ) ;
671
681
const existingBlockquote = mdast . children . find (
672
- child => child . type === "blockquote" &&
673
- child . children ?. length === 1 &&
674
- JSON . stringify ( child . children [ 0 ] . children ) === paragraphContent
682
+ ( child ) =>
683
+ child . type === "blockquote" &&
684
+ child . children ?. length === 1 &&
685
+ JSON . stringify ( child . children [ 0 ] . children ) === paragraphContent ,
675
686
) ;
676
-
687
+
677
688
if ( ! existingBlockquote ) {
678
689
mdast . children . push ( {
679
690
type : "blockquote" ,
0 commit comments