@@ -421,10 +421,58 @@ describe("ELEMENT_TAGS", () => {
421421 } )
422422} )
423423
424- function htmlToJson ( html : string , options : IHtmlToJsonOptions ) {
424+ function htmlToJson ( html : string , options ? : IHtmlToJsonOptions ) {
425425 const dom = new JSDOM ( html ) ;
426426 let htmlDoc = dom . window . document . querySelector ( "body" ) ;
427427 return fromRedactor ( htmlDoc , options ) ;
428428
429429}
430430
431+ describe ( "data-indent-level handling" , ( ) => {
432+ test ( "should keep data-indent-level as a proper attribute, not in redactor-attributes" , ( ) => {
433+ const html = `<p data-indent-level="2" style="margin-left: 60px;">Indented paragraph</p>`
434+ const json = htmlToJson ( html )
435+
436+ expect ( json . children [ 0 ] . attrs [ 'data-indent-level' ] ) . toBe ( '2' )
437+ expect ( json . children [ 0 ] . attrs [ 'redactor-attributes' ] [ 'data-indent-level' ] ) . toBeUndefined ( )
438+ } )
439+
440+ test ( "should not include margin-left in style when data-indent-level is present" , ( ) => {
441+ const html = `<p data-indent-level="2" style="margin-left: 60px; color: red;">Indented paragraph</p>`
442+ const json = htmlToJson ( html )
443+
444+ expect ( json . children [ 0 ] . attrs . style [ 'margin-left' ] ) . toBeUndefined ( )
445+ expect ( json . children [ 0 ] . attrs . style [ 'color' ] ) . toBe ( 'red' )
446+ expect ( json . children [ 0 ] . attrs [ 'data-indent-level' ] ) . toBe ( '2' )
447+ } )
448+
449+ test ( "should include margin-left in style when data-indent-level is NOT present" , ( ) => {
450+ const html = `<p style="margin-left: 60px; color: blue;">Non-indented paragraph</p>`
451+ const json = htmlToJson ( html )
452+
453+ expect ( json . children [ 0 ] . attrs . style [ 'margin-left' ] ) . toBe ( '60px' )
454+ expect ( json . children [ 0 ] . attrs . style [ 'color' ] ) . toBe ( 'blue' )
455+ expect ( json . children [ 0 ] . attrs [ 'data-indent-level' ] ) . toBeUndefined ( )
456+ } )
457+
458+ test ( "should not include style in redactor-attributes when data-indent-level is present" , ( ) => {
459+ const html = `<p data-indent-level="3" style="margin-left: 90px;">Deeply indented</p>`
460+ const json = htmlToJson ( html )
461+
462+ expect ( json . children [ 0 ] . attrs [ 'redactor-attributes' ] [ 'style' ] ) . toBeUndefined ( )
463+ expect ( json . children [ 0 ] . attrs [ 'data-indent-level' ] ) . toBe ( '3' )
464+ } )
465+
466+ test ( "should handle data-indent-level with multiple style properties correctly" , ( ) => {
467+ const html = `<h2 data-indent-level="1" style="margin-left: 30px; text-align: center; font-size: 24px;">Indented heading</h2>`
468+ const json = htmlToJson ( html )
469+
470+ expect ( json . children [ 0 ] . attrs [ 'data-indent-level' ] ) . toBe ( '1' )
471+ expect ( json . children [ 0 ] . attrs . style [ 'margin-left' ] ) . toBeUndefined ( )
472+ expect ( json . children [ 0 ] . attrs . style [ 'text-align' ] ) . toBe ( 'center' )
473+ expect ( json . children [ 0 ] . attrs . style [ 'font-size' ] ) . toBe ( '24px' )
474+ expect ( json . children [ 0 ] . attrs [ 'redactor-attributes' ] [ 'data-indent-level' ] ) . toBeUndefined ( )
475+ expect ( json . children [ 0 ] . attrs [ 'redactor-attributes' ] [ 'style' ] ) . toBeUndefined ( )
476+ } )
477+ } )
478+
0 commit comments