1
1
// @ts -nocheck
2
- import { fromRedactor , getNestedValueIfAvailable } from "../src/fromRedactor"
2
+ import { ELEMENT_TAGS , fromRedactor , getNestedValueIfAvailable } from "../src/fromRedactor"
3
3
import { JSDOM } from "jsdom"
4
4
import isEqual from "lodash.isequal"
5
5
import omitdeep from "omit-deep-lodash"
@@ -295,6 +295,16 @@ describe("Testing html to json conversion", () => {
295
295
const json = htmlToJson ( html )
296
296
expect ( json ) . toStrictEqual ( { "type" :"doc" , "uid" :"uid" , "attrs" :{ } , "children" :[ { "type" :"reference" , "attrs" :{ "style" :{ "text-align" :"right" } , "redactor-attributes" :{ "src" :"https://picsum.photos/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" :"https://picsum.photos/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" :"" } ] } ] } )
297
297
} )
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="https://picsum.photos/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="https://picsum.photos/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" :"https://picsum.photos/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" :"https://picsum.photos/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
+ } )
298
308
} )
299
309
300
310
@@ -372,14 +382,16 @@ describe("CS-41001", () =>{
372
382
} )
373
383
} )
374
384
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
+ } )
378
391
379
392
function htmlToJson ( html : string , options : IHtmlToJsonOptions ) {
380
393
const dom = new JSDOM ( html ) ;
381
394
let htmlDoc = dom . window . document . querySelector ( "body" ) ;
382
395
return fromRedactor ( htmlDoc , options ) ;
383
396
384
- }
385
-
397
+ }
0 commit comments