diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fbe43d..ee7abce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ # Changelog +## [1.4.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.4.0) (2025-04-21) + - Fix: customRenderOption for entry-embedded-as-link nodes + ## [1.3.20](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.20) (2025-02-24) - Fix: Added data-mtec as allowed attribute - - Fix: customRenderOption for entry-embedded-as-link nodes ## [1.3.19](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.19) (2025-02-24) - Fix: Added fix for html injection in keys and values of attributes diff --git a/__test__/mock/json-element-mock.ts b/__test__/mock/json-element-mock.ts index 463d28e..9a0511a 100644 --- a/__test__/mock/json-element-mock.ts +++ b/__test__/mock/json-element-mock.ts @@ -1102,14 +1102,14 @@ const entryReferenceLinkJson = { "uid": "7626ea98e0e95d602210", "type": "reference", "attrs": { - "target": "_self", - "href": "/copy-of-entry-final-02", - "display-type": "link", - "entry-uid": "entry_uid_20", - "content-type-uid": "embeddedrte", - "locale": "en-us", - "type": "entry", - "class-name": "embedded-entry" + "target": "_self", + "href": "/copy-of-entry-final-02", + "display-type": "link", + "entry-uid": "entry_uid_20", + "content-type-uid": "embeddedrte", + "locale": "en-us", + "type": "entry", + "class-name": "embedded-entry" }, "class": "class", "children": [ diff --git a/__test__/reference-to-html.test.ts b/__test__/reference-to-html.test.ts index 06b43d2..3c00167 100644 --- a/__test__/reference-to-html.test.ts +++ b/__test__/reference-to-html.test.ts @@ -173,7 +173,7 @@ describe('Reference Node To HTML', () => { const resultHTML = referenceToHTML(node, renderOption, (metadata: Metadata) => { return findEmbeddedItems(metadata, { uid: 'uid' })[0] }) - expect(resultHTML).toEqual('/copy-of-entry-final-02') + expect(resultHTML).toEqual('/copy-of-entry-final-02') done() }) }) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7944213..73894bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/utils", - "version": "1.3.20", + "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/utils", - "version": "1.3.20", + "version": "1.4.0", "license": "MIT", "devDependencies": { "@babel/preset-env": "^7.26.0", diff --git a/package.json b/package.json index bf517a0..73f7f99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/utils", - "version": "1.3.20", + "version": "1.4.0", "description": "Contentstack utilities for Javascript", "main": "dist/index.es.js", "types": "dist/types/index.d.ts", diff --git a/src/helper/enumerate-entries.ts b/src/helper/enumerate-entries.ts index 5d80dac..ba688f9 100644 --- a/src/helper/enumerate-entries.ts +++ b/src/helper/enumerate-entries.ts @@ -79,7 +79,8 @@ export function referenceToHTML( ): string { function sendToRenderOption(referenceNode: Node): string { - return (renderOption[referenceNode.type] as RenderNode)(referenceNode, undefined); + const next: Next = (nodes) => nodeChildrenToHTML(nodes, renderOption, renderEmbed); + return (renderOption[referenceNode.type] as RenderNode)(referenceNode, next); } if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link') { diff --git a/src/options/default-node-options.ts b/src/options/default-node-options.ts index d79ad27..27afbe5 100644 --- a/src/options/default-node-options.ts +++ b/src/options/default-node-options.ts @@ -122,6 +122,17 @@ export const defaultNodeOption: RenderOption = { }, ['reference']:(node: Node, next: Next) => { + if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link'){ + 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}"`; + if (node.attrs.target) { + aTagAttrs +=` target="${node.attrs.target}"`; + } + if(node.attrs.type == 'asset') { + aTagAttrs += ` type="asset" content-type-uid="sys_assets" ${node.attrs['asset-uid'] ? `data-sys-asset-uid="${node.attrs['asset-uid']}"` : ``} sys-style-type="download"` + } + const aTag = `${sanitizeHTML(next(node.children))}`; + return aTag; + } if (node.attrs.type === 'asset') { const src = encodeURI(node.attrs['asset-link']); const alt = node.attrs?.['redactor-attributes']?.['alt'];