You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-5Lines changed: 4 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ Install the package via npm
25
25
26
26

27
27
28
-
### Parsing rich text HTML to a JSON tree
28
+
### Parsing rich text HTML to an array of simplified nodes
29
29
30
-
The tool provides environment-aware (browser or Node.js) `parseHtml` function to transform HTML into an array of simplified JSON trees. Any valid HTML is parsed, including all attributes. Together with built-in transformation methods, this tool is a suitable option for processing HTML and rich text from external sources, to make it compatible with Kontent.ai rich text format. See dedicated [JSON transformer docs](docs/index.md) for further information.
30
+
The tool provides environment-aware (browser or Node.js) `parseHTML` function to transform HTML into an array of `DomNode`trees. Any valid HTML is parsed, including all attributes. Together with built-in transformation methods, this tool is a suitable option for processing HTML and rich text from external sources, to make it compatible with Kontent.ai rich text format. See dedicated [HTML transformer docs](docs/index.md) for further information.
31
31
32
32
### Portable text resolution
33
33
@@ -291,8 +291,7 @@ Package exports a `traversePortableText` method, which accepts an array of `Port
291
291
const richTextContent =
292
292
`<p>Here is an <a data-item-id="12345"><strong>internal link</strong></a> in some text.</p>`;
@@ -302,7 +301,7 @@ Package exports a `traversePortableText` method, which accepts an array of `Port
302
301
> [!IMPORTANT]
303
302
> MAPI transformation logic expects Portable Text that had been previously created from management API rich text and performs only minimal validation. It doesn't provide implicit transformation capabilities from other formats (such as delivery API).
304
303
>
305
-
> If you're interested in transforming external HTML or rich text to a MAPI compatible format, see [JSON transformer docs](docs/index.md) instead.
304
+
> If you're interested in transforming external HTML or rich text to a MAPI compatible format, see [HTML transformer docs](docs/index.md) instead.
Copy file name to clipboardExpand all lines: docs/index.md
+20-20Lines changed: 20 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
-
# JSON Transformers
1
+
# HTML Transformers
2
2
3
-
This module provides an environment-aware (browser or Node.js) `parseHtml` function to convert an HTML string into an array of nodes. The resulting array can subsequently be modified by one of the provided functions and transformed back to HTML.
3
+
This module provides an environment-aware (browser or Node.js) `parseHTML` function to convert an HTML string into an array of nodes. The resulting array can subsequently be modified by one of the provided functions and transformed back to HTML.
4
4
5
5
This toolset can be particularly useful for transforming rich text or HTML content from external sources into a valid Kontent.ai rich text format in migration scenarios.
6
6
7
7
## Usage
8
8
9
-
Pass stringified HTML to `parseHtml` function to get an array of `DomNode` objects:
9
+
Pass stringified HTML to `parseHTML` function to get an array of `DomNode` objects:
To transform the `DomNode` array back to HTML, you can use `nodesToHtml` function or its async variant `nodesToHtmlAsync`. The function accepts the parsed array and a `transformers` object, which defines custom transformation for each HTML node. Text nodes are transformed automatically. A wildcard `*` can be used to define fallback transformation for remaining tags. If no explicit or wildcard transformation is provided, default resolution is used.
39
+
To transform the `DomNode` array back to HTML, you can use `nodesToHTML` function or its async variant `nodesToHTMLAsync`. The function accepts the parsed array and a `transformers` object, which defines custom transformation for each HTML node. Text nodes are transformed automatically. A wildcard `*` can be used to define fallback transformation for remaining tags. If no explicit or wildcard transformation is provided, default resolution is used.
40
40
41
41
#### Basic
42
42
Basic example of HTML transformation, removing HTML attribute `style` and transforming `b` tag to `strong`:
For more complex scenarios, optional context and its handler can be passed to `nodesToHtml` as third and fourth parameters respectively.
68
+
For more complex scenarios, optional context and its handler can be passed to `nodesToHTML` as third and fourth parameters respectively.
69
69
70
70
The context can then be accessed in individual transformations, defined in the `transformers` object. If you need to dynamically update the context, you may optionally provide a context handler, which accepts current node and context as parameters and passes a cloned, modified context for child node processing, ensuring each node gets valid contextual data.
71
71
@@ -76,18 +76,18 @@ In Kontent.ai rich text, images are represented by a `<figure>` tag, with `data-
76
76
1. Load the binaries from `src` attribute and create an asset in Kontent.ai asset library
77
77
2. Use the asset ID from previous step to reference the asset in the transformed `<figure>` tag.
78
78
79
-
For that matter, we will use `nodesToHtmlAsync` method and pass an instance of JS SDK `ManagementClient` as context, to perform the asset creation. Since we don't need to modify the client in any way, we can omit the context handler for this example.
79
+
For that matter, we will use `nodesToHTMLAsync` method and pass an instance of JS SDK `ManagementClient` as context, to perform the asset creation. Since we don't need to modify the client in any way, we can omit the context handler for this example.
0 commit comments