Skip to content

Commit 7f9991d

Browse files
replacing my regex with a function already in DCR
1 parent 6ace9c1 commit 7f9991d

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

dotcom-rendering/src/components/InlineProductCard.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { ArticleFormat } from '../lib/articleFormat';
1111
import { palette } from '../palette';
1212
import { Picture } from './Picture';
1313
import { ProductLinkButton } from './ProductLinkButton';
14+
import { stripHtmlFromString } from './TextBlockComponent';
1415

1516
export type Statistics = {
1617
name: string;
@@ -101,8 +102,6 @@ const ProductInfoContainer = ({ children }: { children: ReactNode }) => (
101102
<div css={productInfoContainer}>{children}</div>
102103
);
103104

104-
const stripHtml = (html: string) => html.replace(/<[^>]+>/g, '');
105-
106105
export const InlineProductCard = ({
107106
format,
108107
brandName,
@@ -136,7 +135,7 @@ export const InlineProductCard = ({
136135
</ProductInfoContainer>
137136
<ButtonContainer>
138137
<ProductLinkButton
139-
label={stripHtml(primaryCTA)}
138+
label={stripHtmlFromString(primaryCTA)}
140139
url={primaryUrl}
141140
cssOverrides={css`
142141
width: 100%;
@@ -147,7 +146,7 @@ export const InlineProductCard = ({
147146
cssOverrides={css`
148147
width: 100%;
149148
`}
150-
label={stripHtml(secondaryCTA)}
149+
label={stripHtmlFromString(secondaryCTA)}
151150
url={secondaryUrl}
152151
priority={'tertiary'}
153152
/>

dotcom-rendering/src/components/TextBlockComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const isOpenQuote = (t: string): boolean => {
4343
].includes(t);
4444
};
4545

46-
const stripHtmlFromString = (html: string): string => {
46+
export const stripHtmlFromString = (html: string): string => {
4747
// https://stackoverflow.com/questions/822452/strip-html-from-text-javascript is
4848
// a good discussion on how this can be done. Of the two approaches, regex and
4949
// DOM, both have unikely failure scenarios but the impact for failure with DOM

0 commit comments

Comments
 (0)