Skip to content

Commit 2a5b440

Browse files
remove html from primary heading for carousel and horizontal cards
1 parent 6a64656 commit 2a5b440

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

dotcom-rendering/src/model/enhanceProductElement.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { JSDOM } from 'jsdom';
12
import type {
23
FEElement,
34
ProductBlockElement,
@@ -13,6 +14,7 @@ const enhanceProductBlockElement = (
1314
...element,
1415
content: elementsEnhancer(element.content),
1516
lowestPrice: getLowestPrice(element.productCtas),
17+
primaryHeadingText: getHeadingText(element.primaryHeadingHtml),
1618
});
1719

1820
/**
@@ -72,3 +74,15 @@ export const enhanceProductElement =
7274
(elementsEnhancer: ElementsEnhancer) =>
7375
(elements: FEElement[]): FEElement[] =>
7476
elements.flatMap(enhance(elementsEnhancer));
77+
78+
const getHeadingText = (headingHtml: string): string => {
79+
return removeTrailingColon(extractText(headingHtml));
80+
};
81+
82+
const removeTrailingColon = (text: string): string => {
83+
return text.replace(/\s*:\s*$/, '');
84+
};
85+
86+
const extractText = (html: string): string => {
87+
return JSDOM.fragment(html).textContent?.trim() ?? '';
88+
};

dotcom-rendering/src/types/content.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ export interface ProductBlockElement {
480480
image?: ProductImage;
481481
secondaryHeadingHtml: string;
482482
primaryHeadingHtml: string;
483+
primaryHeadingText?: string;
483484
customAttributes: ProductCustomAttribute[];
484485
content: FEElement[];
485486
h2Id?: string;

0 commit comments

Comments
 (0)