11// @ts -nocheck
2- import { fromRedactor , getNestedValueIfAvailable } from "../src/fromRedactor"
2+ import { ELEMENT_TAGS , fromRedactor , getNestedValueIfAvailable } from "../src/fromRedactor"
33import { JSDOM } from "jsdom"
44import isEqual from "lodash.isequal"
55import omitdeep from "omit-deep-lodash"
@@ -295,6 +295,16 @@ describe("Testing html to json conversion", () => {
295295 const json = htmlToJson ( html )
296296 expect ( json ) . toStrictEqual ( { "type" :"doc" , "uid" :"uid" , "attrs" :{ } , "children" :[ { "type" :"reference" , "attrs" :{ "style" :{ "text-align" :"right" } , "redactor-attributes" :{ "src" :"***REMOVED***200" , "height" :"141" , "alt" :"image_(9).png" , "caption" :"ss" , "type" :"asset" , "asset-alt" :"image_(9).png" , "max-height" :"141" , "max-width" :"148" , "sys-style-type" :"display" , "position" :"right" , "captionAttrs" :{ "style" :"text-align:center" } , "anchorLink" :"ss.com" , "target" :true , "asset-caption" :"ss" } , "class-name" :"embedded-asset" , "width" :148 , "type" :"asset" , "asset-caption" :"ss" , "link" :"ss.com" , "asset-alt" :"image_(9).png" , "target" :"_blank" , "position" :"right" , "asset-link" :"***REMOVED***200" , "asset-uid" :"blt137d845621ef8168" , "display-type" :"display" , "asset-name" :"image_(9).png" , "asset-type" :"image/png" , "content-type-uid" :"sys_assets" } , "uid" :"uid" , "children" :[ { "text" :"" } ] } , { "type" :"p" , "attrs" :{ } , "uid" :"uid" , "children" :[ { "text" :"" } ] } ] } )
297297 } )
298+ test ( "should convert asset to reference with non standard tags" , ( ) => {
299+ const html = `<figure style="margin: 0; text-align: right">
300+ <div style="display: inline-block"><a href="ss.com" target="_blank"><img src="***REMOVED***200" height="141" alt="image_(9).png" caption="ss" anchorLink="ss.com" class="embedded-asset" content-type-uid="sys_assets" type="asset" asset-alt="image_(9).png" width="148" max-height="141" max-width="148" style="max-height: 141px; height: 141px; text-align: right; max-width: 148px; width: auto" data-sys-asset-filelink="***REMOVED***200" data-sys-asset-uid="blt137d845621ef8168" data-sys-asset-filename="image_(9).png" data-sys-asset-contenttype="image/png" data-sys-asset-caption="ss" data-sys-asset-alt="image_(9).png" data-sys-asset-link="ss.com" data-sys-asset-position="right" data-sys-asset-isnewtab="true" sys-style-type="display" /></a>
301+ <figcaption style="text-align:center">ss</figcaption>
302+ </div>
303+ </figure>
304+ <p></p>`
305+ const json = htmlToJson ( html , { allowNonStandardTags : true } )
306+ expect ( json ) . toStrictEqual ( { "type" :"doc" , "uid" :"uid" , "attrs" :{ } , "children" :[ { "type" :"reference" , "attrs" :{ "style" :{ "text-align" :"right" } , "redactor-attributes" :{ "src" :"***REMOVED***200" , "height" :"141" , "alt" :"image_(9).png" , "caption" :"ss" , "type" :"asset" , "asset-alt" :"image_(9).png" , "max-height" :"141" , "max-width" :"148" , "sys-style-type" :"display" , "position" :"right" , "captionAttrs" :{ "style" :"text-align:center" } , "anchorLink" :"ss.com" , "target" :true , "asset-caption" :"ss" } , "class-name" :"embedded-asset" , "width" :148 , "type" :"asset" , "asset-caption" :"ss" , "link" :"ss.com" , "asset-alt" :"image_(9).png" , "target" :"_blank" , "position" :"right" , "asset-link" :"***REMOVED***200" , "asset-uid" :"blt137d845621ef8168" , "display-type" :"display" , "asset-name" :"image_(9).png" , "asset-type" :"image/png" , "content-type-uid" :"sys_assets" } , "uid" :"uid" , "children" :[ { "text" :"" } ] } , { "type" :"p" , "attrs" :{ } , "uid" :"uid" , "children" :[ { "text" :"" } ] } ] } )
307+ } )
298308} )
299309
300310
@@ -372,14 +382,16 @@ describe("CS-41001", () =>{
372382 } )
373383} )
374384
375-
376-
377-
385+ describe ( "ELEMENT_TAGS" , ( ) => {
386+ test ( "should have FIGCAPTION as a standard element tag" , ( ) => {
387+ const standardElementTags = Object . keys ( ELEMENT_TAGS ) ;
388+ expect ( standardElementTags ) . toContain ( "FIGCAPTION" ) ;
389+ } )
390+ } )
378391
379392function htmlToJson ( html : string , options : IHtmlToJsonOptions ) {
380393 const dom = new JSDOM ( html ) ;
381394 let htmlDoc = dom . window . document . querySelector ( "body" ) ;
382395 return fromRedactor ( htmlDoc , options ) ;
383396
384- }
385-
397+ }
0 commit comments