diff --git a/src/transformers/portable-text-transformer/portable-text-transformer.ts b/src/transformers/portable-text-transformer/portable-text-transformer.ts index ba79420..7e5ff81 100644 --- a/src/transformers/portable-text-transformer/portable-text-transformer.ts +++ b/src/transformers/portable-text-transformer/portable-text-transformer.ts @@ -126,9 +126,10 @@ const mergeSpansAndMarks: MergePortableTextItemsFunction = (itemsToMerge) => { * * in this case, a link can have multiple child nodes if some of its text is styled. * as a result, keeping a counter for the link's children and decrementing it with each subsequent span occurrence - * is required so that the link mark doesn't extend beyond its scope. + * is required so that the link mark doesn't extend beyond its scope. links array is reset when the counter reaches zero. */ - item.marks = [...marks, ...(linkChildCount > 0 ? links : [])]; + links = linkChildCount > 0 ? links : []; + item.marks = [...marks, ...links]; // ensures the child count doesn't go below zero linkChildCount = Math.max(0, linkChildCount - 1); mergedItems.push(item); diff --git a/tests/transfomers/portable-text-transformer/__snapshots__/portable-text-transformer.spec.ts.snap b/tests/transfomers/portable-text-transformer/__snapshots__/portable-text-transformer.spec.ts.snap index b86f426..3860738 100644 --- a/tests/transfomers/portable-text-transformer/__snapshots__/portable-text-transformer.spec.ts.snap +++ b/tests/transfomers/portable-text-transformer/__snapshots__/portable-text-transformer.spec.ts.snap @@ -12227,3 +12227,61 @@ exports[`portable text transformer transforms table with input