2.0.0
Kontent.ai Rich Text Resolver 2.0.0
New version of the primary tool for Kontent.ai rich text resolution in JS/TS-based frameworks, including more accurate typing, reworked transformation logic with focus on streamlining migration of external rich text and HTML and performance improvements.
Changes
Since the deprecation of rich text resolution built into the JS SDK, this package has become the primary solution for resolving rich text. To align with familiar naming conventions, a large number of types, properties and functions have been renamed. Some methods were removed altogether, while others have updated signatures. See changes below.
Note
Changes marked with
Changes marked with ℹ️ are non-breaking
Functions
⚠️ transformToPortableText
– updated signature. previously accepted aParseResult
object from eithernodeParse
orbrowserParse
functions. Now acceptsstring
representation of the rich text HTML. Parsing happens internally and is environment-aware (Node.js vs browser).⚠️ nodeParse
,browserParse
– removed in favor ofparseHTML
, which picks a correct parser based on the environment it's called from. The result is now directlyDomNode[]
rather thanParseResult
, which contained the resultingDomNode
array in a nestedchildren
property.⚠️ transformToJson
– removed. See reworked transformation entry below.
Types
-
⚠️ PortableTextComponent
renamed →PortableTextComponentOrItem
⚠️ _type
literal changed tocomponentOrItem
⚠️ component
property renamed tocomponentOrItem
-
⚠️ PortableTextInternalLink
renamed →PortableTextItemLink
⚠️ reference
property renamed tocontentItemLink
-
PortableTextTable
⚠️ numColumns
property removed
-
PortableTextTableCell
⚠️ childBlocksCount
property removed
-
Reference
,AssetReference
- ℹ️ added a
referenceType
property, informing whether the value referencescodename
,id
orexternal-id
- ℹ️ added a
-
⚠️ ParseResult
– removed,parseHTML
function now returns directlyDomNode[]
-
⚠️ ResolveDomTextNodeType
,ResolveDomHtmlNodeType
,TransformDomNodeType
– removed
Features
Reworked HTML parsing and transformation (formerly JSON)
Parsing has been unified under a new, environment-aware (Node.js and browser) parseHTML
function. The result is now directly a DomNode
array, which can be transformed and composed back to HTML using new nodesToHTML
and nodesToHTMLAsync
functions.
The revamped logic is specifically tailored for transforming external rich text and HTML in order to make it compatible with Kontent.ai rich text format. See dedicated transformer documentation for details.
More accurate resolution types
Resolution to React and HTML has been improved by addition of modified types from the respective external packages. The new types (PortableTextReactResolvers
and PortableTextHtmlResolvers
respectively) now natively support custom Kontent.ai portable text objects without the need for explicit typing.
Default resolution improvements for HTML and React
<PortableText>
component and toHTML
functions from respective external packages have been modified and re-exported from the module itself. They now provide default fallback for resolution of tables, images, URL links and previously unsupported sub
and sup
tags, without the need to specify transformations for them explicitly. Existing helper functions (such as resolveImage
and resolveTable
) remain unchanged, but no longer have to be used, as the process will supply them automatically, if no custom resolution was provided.
Reworked internal portable text transformation logic
The transformation logic from DomNode[]
to Portable Text has been simplified and optimized, removing some redundancy and lowering the number of recursive traversals, which may result in slight performance gain with large HTML inputs.
Pull requests
Full Changelog: 1.2.2...2.0.0