Skip to content

Commit ca5e2a3

Browse files
authored
Merge pull request #83 from Financial-Times/layout-slot-hack
Handle nested layoutslots published by Spark
2 parents 6bda5b8 + e2d39ff commit ca5e2a3

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

libraries/from-bodyxml/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ export let defaultTransformers = {
344344
return { type: "__LIFT_CHILDREN__" };
345345
}
346346
if (div.attributes.class === "n-content-layout__slot") {
347+
348+
// this is a bit of a hack, but some Spark explainers double up the layout-slot divs
349+
// so we need to flatten them out before proceeding
350+
// https://github.com/Financial-Times/cp-content-pipeline/blob/f9deff5227f6f5d3d0dfd5e3eabee6599c86aba5/packages/schema/src/resolvers/content-tree/tagMappings.ts#L359
351+
div.children = div.children.flatMap((child) => {
352+
if (isXElement(child) && child.name === "div") {
353+
return child.children || [];
354+
} else {
355+
return [child];
356+
}
357+
});
347358
return /** @type { ContentTree.transit.LayoutSlot } */ ({
348359
type: "layout-slot",
349360
});
@@ -432,7 +443,7 @@ export function fromXast(bodyxast, transformers = defaultTransformers) {
432443
value: xmlnode.value,
433444
};
434445
} else {
435-
return { type: "__UNKNOWN__" , data: xmlnode };
446+
return { type: "__UNKNOWN__", data: xmlnode };
436447
}
437448
})(bodyxast);
438449
}

0 commit comments

Comments
 (0)