Skip to content

Commit

Permalink
Update TextBlockComponent.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielCliftonGuardian committed Jun 5, 2023
1 parent e305c76 commit a754636
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions dotcom-rendering/src/web/components/TextBlockComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,10 @@ const styles = (format: ArticleFormat) => css`
`;

const buildElementTree =
(
html: string,
format: ArticleFormat,
isFirstParagraph: boolean,
forceDropCap?: boolean,
) =>
(html: string, format: ArticleFormat, showDropCaps: boolean) =>
(node: Node, key: number): ReactNode => {
const showDropCaps = shouldShowDropCaps(
html,
format,
isFirstParagraph,
forceDropCap,
);
const children = Array.from(node.childNodes).map(
buildElementTree(html, format, isFirstParagraph, forceDropCap),
buildElementTree(html, format, showDropCaps),
);

switch (node.nodeName) {
Expand Down Expand Up @@ -324,14 +313,19 @@ export const TextBlockComponent = ({
isFirstParagraph,
forceDropCap,
}: Props) => {
const showDropCaps = shouldShowDropCaps(
html,
format,
isFirstParagraph,
forceDropCap,
);
const fragment = parseHtml(sanitise(html, sanitiserOptions));
return jsx(Fragment, {
children: Array.from(fragment.childNodes).map(
buildElementTree(
sanitise(html, sanitiserOptions),
format,
isFirstParagraph,
forceDropCap,
showDropCaps,
),
),
});
Expand Down

0 comments on commit a754636

Please sign in to comment.