Skip to content

Commit e2d39ff

Browse files
authored
Merge branch 'main' into layout-slot-hack
2 parents cc8f2f3 + 6bda5b8 commit e2d39ff

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

libraries/from-bodyxml/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let ContentType = {
77
video: "http://www.ft.com/ontology/content/Video",
88
content: "http://www.ft.com/ontology/content/Content",
99
article: "http://www.ft.com/ontology/content/Article",
10+
customCodeComponent: "http://www.ft.com/ontology/content/CustomCodeComponent",
1011
};
1112

1213
/**
@@ -292,6 +293,21 @@ export let defaultTransformers = {
292293
title: content.attributes.dataTitle ?? "",
293294
};
294295
},
296+
/**
297+
* @type {Transformer<ContentTree.transit.CustomCodeComponent>}
298+
*/
299+
[ContentType.customCodeComponent](content) {
300+
const id = content.attributes.url ?? "";
301+
const uuid = id.split("/").pop();
302+
return {
303+
type: "custom-code-component",
304+
id: uuid ?? "",
305+
layoutWidth: toValidLayoutWidth(
306+
content.attributes["data-layout-width"] || ""
307+
),
308+
children: null,
309+
};
310+
},
295311
/**
296312
* @type {Transformer<ContentTree.transit.Recommended>}
297313
*/
@@ -311,7 +327,7 @@ export let defaultTransformers = {
311327
* ContentTree.transit.Layout |
312328
* ContentTree.transit.LayoutSlot |
313329
* { type: "__LIFT_CHILDREN__"} |
314-
* { type: "__UNKNOWN__"}
330+
* { type: "__UNKNOWN__", data?: any}
315331
* >}
316332
*/
317333
div(div) {
@@ -343,7 +359,7 @@ export let defaultTransformers = {
343359
type: "layout-slot",
344360
});
345361
}
346-
return { type: "__UNKNOWN__", data: div };
362+
return { type: "__UNKNOWN__", data: div };
347363
},
348364
experimental() {
349365
return { type: "__LIFT_CHILDREN__" };
@@ -439,7 +455,7 @@ export function fromXast(bodyxast, transformers = defaultTransformers) {
439455
* @returns {string}
440456
*/
441457
function removeWhitespaceBeforeBodyTag(xml) {
442-
return xml.replace("</p> </body>", "</p></body>");
458+
return xml.replace(/<\/p>\s+<\/body>/gi, '</p></body>');
443459
}
444460

445461
/** @param {string} bodyxml */

0 commit comments

Comments
 (0)