Skip to content

Commit 2c7f46a

Browse files
committed
add parallel processing flag to HTMLProcessor
1 parent 0b41914 commit 2c7f46a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @code.store/arcxp-sdk-ts
22

3+
## 4.41.0
4+
5+
### Minor Changes
6+
7+
- add parallel processing flag to HTMLProcessor
8+
39
## 4.40.6
410

511
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code.store/arcxp-sdk-ts",
3-
"version": "4.40.6",
3+
"version": "4.41.0",
44
"description": "A strongly typed set of ArcXP API's and utilities reduce the amount of work required to develop with ArcXP, starting with reducing the boilerplate code you have to write.",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/content-elements/html/html.processor.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export type WrapHandler = (node: Node, content: ContentElementType<'text'>) => C
3939
* using the `handle()` and `wrap()` methods.
4040
*/
4141
export class HTMLProcessor {
42+
protected parallelProcessing = true;
43+
4244
protected handlers = {
4345
node: new Map<string, NodeHandler>(),
4446
wrap: new Map<string, WrapHandler>(),
@@ -61,6 +63,7 @@ export class HTMLProcessor {
6163
};
6264
}
6365
});
66+
6467
this.wrap('i', (node, text) => {
6568
if (nodeTagIn(node, ['i'])) {
6669
return {
@@ -280,14 +283,26 @@ export class HTMLProcessor {
280283
* @param node - The HTML node to process
281284
**/
282285
protected async handleNested(node: Node) {
283-
const children = await Promise.all(node.childNodes.map((child) => this.process(child)));
286+
const children = await this.processChildNodes(node);
284287
const filtered = children.filter(Boolean).flat() as CElement[];
285288
const merged = this.mergeParagraphs(filtered);
286289
const wrapped = this.wrapChildrenTextNodes(node, merged);
287290

288291
return wrapped;
289292
}
290293

294+
protected async processChildNodes(node: Node): Promise<(CElement[] | undefined)[]> {
295+
if (this.parallelProcessing) {
296+
return await Promise.all(node.childNodes.map((child) => this.process(child)));
297+
}
298+
299+
const children: (CElement[] | undefined)[] = [];
300+
for (const child of node.childNodes) {
301+
children.push(await this.process(child));
302+
}
303+
return children;
304+
}
305+
291306
/**
292307
* Processes a single HTML node and converts it into content elements.
293308
* This method iterates through registered node handlers and attempts to process the node.
@@ -325,7 +340,7 @@ export class HTMLProcessor {
325340
*
326341
* @param items - The array of content elements to merge
327342
**/
328-
private mergeParagraphs(items: CElement[]): CElement[] {
343+
protected mergeParagraphs(items: CElement[]): CElement[] {
329344
const merged: CElement[] = [];
330345
let toMerge: ContentElementType<'text'>[] = [];
331346

0 commit comments

Comments
 (0)