File tree Expand file tree Collapse file tree 5 files changed +69
-34
lines changed
Expand file tree Collapse file tree 5 files changed +69
-34
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
33
4+ ## [ 1.3.11] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.11 ) (2024-08-21)
5+ - Fix: Reference to HTML fixed to support assets that are referenced
6+
47## [ 1.3.10] ( https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.10 ) (2024-07-08)
58 - Enhancement: Update default node options
69
Original file line number Diff line number Diff line change @@ -167,6 +167,19 @@ describe('Node parser reference content', () => {
167167 expect ( entry . json_rte [ 0 ] ) . toEqual ( referenceObjHtml )
168168 done ( )
169169 } )
170+
171+ it ( 'should convert to html when asset embedded as link in json_rte' , done => {
172+ const entry = {
173+ uid : 'entry_uid' ,
174+ rte_data : { ...embeddedAssetAsLinkJsonEntry } ,
175+ }
176+ const paths = [ "rte_data" ]
177+ const result = `<p>asda<a class="embedded-entry redactor-component undefined-entry" href="https://images.contentstack.io/v3/assets/***REMOVED***/***REMOVED***/657304603ed4d5773c01feed/Screenshot_2023-03-01_at_1.09.39_PM.png" target="_self" content-type-uid="sys_assets" data-sys-asset-uid="***REMOVED***" sys-style-type="download">s<strong>das</strong></a><strong>d</strong>as</p>`
178+ jsonToHTML ( { entry : entry , paths } )
179+
180+ expect ( entry . rte_data ) . toBe ( result )
181+ done ( )
182+ } )
170183} )
171184
172185describe ( 'Node parse text Content' , ( ) => {
Original file line number Diff line number Diff line change @@ -1139,38 +1139,51 @@ const paragraphJsonArrayEntry = {
11391139}
11401140
11411141const embeddedAssetAsLinkJsonEntry = {
1142- uid : 'entry_uid' ,
1143- rte_data : {
1144- type : 'doc' ,
1145- attrs : { } ,
1146- uid : 'rte_uid' ,
1147- children : [
1142+ "type" : "doc" ,
1143+ "attrs" : { } ,
1144+ "uid" : "1b212916f2784af4bcf9a0af5018364e" ,
1145+ "children" : [
11481146 {
1149- type : 'p' ,
1150- uid : 'p_uid' ,
1151- attrs : { } ,
1152- children : [
1153- { text : '' } ,
1154- {
1155- uid : 'ref_uid' ,
1156- type : 'reference' ,
1157- attrs : {
1158- 'display-type' : 'link' ,
1159- type : 'asset' ,
1160- 'class-name' : 'embedded-entry redactor-component undefined-entry' ,
1161- 'asset-uid' : 'asset_uid_2' ,
1162- 'content-type-uid' : 'sys_assets' ,
1163- target : '_self' ,
1164- href : 'https://picsum.photos/200'
1165- } ,
1166- children : [ { text : 'Door matching' , bold : true , underline : true } ]
1167- } ,
1168- { text : '' }
1169- ]
1147+ "type" : "p" ,
1148+ "attrs" : { } ,
1149+ "uid" : "3f3a84966368435388b7b9948283be2e" ,
1150+ "children" : [
1151+ {
1152+ "text" : "asda"
1153+ } ,
1154+ {
1155+ "uid" : "c2384ca128a64ee89e82b7aaab77e7b1" ,
1156+ "type" : "reference" ,
1157+ "attrs" : {
1158+ "display-type" : "link" ,
1159+ "type" : "asset" ,
1160+ "class-name" : "embedded-entry redactor-component undefined-entry" ,
1161+ "asset-uid" : "***REMOVED***" ,
1162+ "content-type-uid" : "sys_assets" ,
1163+ "target" : "_self" ,
1164+ "href" : "https://images.contentstack.io/v3/assets/***REMOVED***/***REMOVED***/657304603ed4d5773c01feed/Screenshot_2023-03-01_at_1.09.39_PM.png"
1165+ } ,
1166+ "children" : [
1167+ {
1168+ "text" : "s"
1169+ } ,
1170+ {
1171+ "text" : "das" ,
1172+ "bold" : true
1173+ }
1174+ ]
1175+ } ,
1176+ {
1177+ "text" : "d" ,
1178+ "bold" : true
1179+ } ,
1180+ {
1181+ "text" : "as"
1182+ }
1183+ ]
11701184 }
1171- ] ,
1172- _version : 4
1173- }
1185+ ] ,
1186+ "_version" : 1
11741187}
11751188
11761189const embeddedAssetJsonEntry = {
Original file line number Diff line number Diff line change 11{
22 "name" : " @contentstack/utils" ,
3- "version" : " 1.3.10 " ,
3+ "version" : " 1.3.11 " ,
44 "description" : " Contentstack utilities for Javascript" ,
55 "main" : " dist/index.es.js" ,
66 "types" : " dist/types/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -77,12 +77,18 @@ export function referenceToHTML(
7777 renderOption : RenderOption ,
7878 renderEmbed ?: ( metadata : Metadata ) => EmbeddedItem | EntryNode ,
7979) : string {
80- if ( node . attrs . type === 'entry' && node . attrs [ 'display-type' ] === 'link' ) {
80+ if ( ( node . attrs . type === 'entry' || node . attrs . type === 'asset' ) && node . attrs [ 'display-type' ] === 'link' ) {
8181 const entryText = node . children ? nodeChildrenToHTML ( node . children , renderOption , renderEmbed ) : '' ;
82+
83+ let aTagAttrs = `${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs [ 'class-name' ] ? ` class="${ node . attrs [ 'class-name' ] } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ node . attrs . href || node . attrs . url } "` ;
8284 if ( node . attrs . target ) {
83- return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs [ 'class-name' ] ? ` class="${ node . attrs [ 'class-name' ] } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ node . attrs . href || node . attrs . url } " target="${ node . attrs . target } ">${ entryText } </a>`
85+ aTagAttrs += ` target="${ node . attrs . target } "` ;
86+ }
87+ if ( node . attrs . type == 'asset' ) {
88+ aTagAttrs += ` type="asset" content-type-uid="sys_assets" ${ node . attrs [ 'asset-uid' ] ? `data-sys-asset-uid="${ node . attrs [ 'asset-uid' ] } "` : `` } sys-style-type="download"`
8489 }
85- return `<a${ node . attrs . style ? ` style="${ node . attrs . style } "` : `` } ${ node . attrs [ 'class-name' ] ? ` class="${ node . attrs [ 'class-name' ] } "` : `` } ${ node . attrs . id ? ` id="${ node . attrs . id } "` : `` } href="${ node . attrs . href || node . attrs . url } ">${ entryText } </a>` ;
90+ const aTag = `<a${ aTagAttrs } >${ entryText } </a>` ;
91+ return aTag ;
8692 }
8793
8894 function sendToRenderOption ( referenceNode : Node ) : string {
You can’t perform that action at this time.
0 commit comments