Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@kentico/kontent-delivery-html-parser-node-js
Advanced tools
Rich text element parser for Kontent Javascript SDK
This library is an optional addon for the javascript delivery SDK
that can be used to resolve rich text elements in node.js
environment.
This is an alternative to built-in browserRichTextResolver
that comes native with the SDK and works in browsers.
Use nodeRichTextResolver
when you need to resolve rich text elements in node.js
environment
import { createDeliveryClient, linkedItemsHelper } from '@kentico/kontent-delivery';
import { nodeRichTextResolver } from '@kentico/kontent-delivery-node-js-parser';
export type Movie = IContentItem<{
plot: Elements.RichTextElement;
}>;
export type Actor = IContentItem<{
firstName: Elements.RichTextElement;
}>;
// get content item with rich text element
const response = (await createDeliveryClient({ projectId: 'projectId' }).item<Movie>('itemCodename').toPromise()).data;
// get rich text element
const richtElement = response.item.plot;
// resolve HTML
const resolvedRichText = nodeRichTextResolver.resolveRichText({
element: richtElement,
linkedItems: linkedItemsHelper.convertLinkedItemsToArray(response.linkedItems),
imageResolver: (image) => {
return {
imageHtml: `<img class="xImage" src="${image?.url}">`,
// alternatively you may return just url
url: 'customUrl'
};
},
urlResolver: (link) => {
return {
linkHtml: `<a class="xLink">${link?.link?.urlSlug}</a>`,
// alternatively you may return just url
url: 'customUrl'
};
},
contentItemResolver: (contentItem) => {
if (contentItem && contentItem.system.type === 'actor') {
const actor = contentItem as Actor;
return {
contentItemHtml: `<div class="xClass">${actor.elements.firstName.value}</div>`
};
}
return {
contentItemHtml: ''
};
}
});
const resolvedHtml = resolvedRichText.html;
If you need to use async functions
within resolvers, use the resolveRichTextAsync
:
const resolvedRichText = await nodeRichTextResolver.resolveRichTextAsync({
element: response.item.elements.plot,
linkedItems: linkedItemsHelper.convertLinkedItemsToArray(response.linkedItems),
imageResolver: async (image) => {
// async function
return {
imageHtml: await customAsyncfunc()
};
},
urlResolver: async (link) => {
// async function
return {
imageHtml: await customAsyncfunc()
};
},
contentItemResolver: async (contentItem) => {
// async function
return {
contentItemHtml: await customAsyncfunc()
};
}
});
FAQs
Rich text element parser for Kontent Javascript SDK
The npm package @kentico/kontent-delivery-html-parser-node-js receives a total of 0 weekly downloads. As such, @kentico/kontent-delivery-html-parser-node-js popularity was classified as not popular.
We found that @kentico/kontent-delivery-html-parser-node-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.