Skip to content

fix: customrenderoption for reference entry embedded as link #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [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
Expand Down
12 changes: 8 additions & 4 deletions src/helper/enumerate-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ export function referenceToHTML(
renderOption: RenderOption,
renderEmbed?: (metadata: Metadata) => EmbeddedItem | EntryNode,
): string {

function sendToRenderOption(referenceNode: Node): string {
return (renderOption[referenceNode.type] as RenderNode)(referenceNode, undefined);
}

if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link') {
const entryText = node.children ? nodeChildrenToHTML(node.children, renderOption, renderEmbed) : '';
if (renderOption[node.type] !== undefined) {
return sendToRenderOption(node);
}

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) {
Expand All @@ -90,10 +98,6 @@ export function referenceToHTML(
const aTag = `<a${aTagAttrs}>${entryText}</a>`;
return aTag;
}

function sendToRenderOption(referenceNode: Node): string {
return (renderOption[referenceNode.type] as RenderNode)(referenceNode, undefined);
}

if (!renderEmbed && renderOption[node.type] !== undefined) {
return sendToRenderOption(node);
Expand Down
Loading