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"
@@ -278,6 +278,16 @@ describe("Testing html to json conversion", () => {
278
278
const json = htmlToJson ( html )
279
279
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" :"" } ] } ] } )
280
280
} )
281
+ test ( "should convert asset to reference with non standard tags" , ( ) => {
282
+ const html = `<figure style="margin: 0; text-align: right">
283
+ <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>
284
+ <figcaption style="text-align:center">ss</figcaption>
285
+ </div>
286
+ </figure>
287
+ <p></p>`
288
+ const json = htmlToJson ( html , { allowNonStandardTags : true } )
289
+ 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" :"" } ] } ] } )
290
+ } )
281
291
} )
282
292
283
293
@@ -355,9 +365,15 @@ describe("CS-41001", () =>{
355
365
} )
356
366
} )
357
367
368
+ describe ( "ELEMENT_TAGS" , ( ) => {
369
+ test ( "should have FIGCAPTION as a standard element tag" , ( ) => {
370
+ const standardElementTags = Object . keys ( ELEMENT_TAGS ) ;
371
+ expect ( standardElementTags ) . toContain ( "FIGCAPTION" ) ;
372
+ } )
373
+ } )
374
+
358
375
function htmlToJson ( html : string , options : IHtmlToJsonOptions ) {
359
376
const dom = new JSDOM ( html ) ;
360
377
let htmlDoc = dom . window . document . querySelector ( "body" ) ;
361
378
return fromRedactor ( htmlDoc , options ) ;
362
- }
363
-
379
+ }
0 commit comments