File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
services/content-api/parsers Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 11import { VaccineType } from "@src/models/vaccine" ;
22import { Overview as StyledOverview } from "@src/services/content-api/types" ;
3- import { fixupHtmlFragment } from "@src/utils/html" ;
3+ import { linksOpenCorrectly } from "@src/utils/html" ;
44import { JSX } from "react" ;
55
66const Overview = ( props : { overview : StyledOverview | undefined ; vaccineType : VaccineType } ) : JSX . Element => {
77 const element = props . overview ? (
88 props . overview . containsHtml ? (
99 < div
1010 data-testid = "overview-text"
11- dangerouslySetInnerHTML = { { __html : fixupHtmlFragment ( props . overview . content ) || "" } }
11+ dangerouslySetInnerHTML = { { __html : linksOpenCorrectly ( props . overview . content ) || "" } }
1212 />
1313 ) : (
1414 < p data-testid = "overview-text" > { props . overview . content } </ p >
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import {
1616 VaccinePageSection ,
1717 VaccinePageSubsection ,
1818} from "@src/services/content-api/types" ;
19- import { fixupHtmlFragment } from "@src/utils/html" ;
19+ import { linksOpenCorrectly } from "@src/utils/html" ;
2020import sanitiseHtml from "@src/utils/sanitise-html" ;
2121import { InsetText , WarningCallout } from "nhsuk-react-components" ;
2222import React , { JSX } from "react" ;
@@ -184,7 +184,7 @@ function styleCallout(callout: HeadingWithTypedContent | undefined): StyledPageS
184184 component : (
185185 < div
186186 data-testid = "callout-html"
187- dangerouslySetInnerHTML = { { __html : fixupHtmlFragment ( callout . content ) || "" } }
187+ dangerouslySetInnerHTML = { { __html : linksOpenCorrectly ( callout . content ) || "" } }
188188 />
189189 ) ,
190190 } ;
Original file line number Diff line number Diff line change 11import { load as loadHtml } from "cheerio" ;
22
3- export function fixupHtmlFragment ( fragment : string ) {
3+ /**
4+ * Update HTML fragment to ensure that anchor tags have the target="_blank"
5+ * attribute, so links open in a new window.
6+ * * @param {string } fragment - the original HTML fragment.
7+ * * @returns {string } The HTML fragment with fixed anchor tags.
8+ */
9+ export function linksOpenCorrectly ( fragment : string ) {
410 const $ = loadHtml ( fragment , null , false ) ;
511 $ ( "a" ) . attr ( "target" , "_blank" ) ;
612 return $ . html ( ) ;
You can’t perform that action at this time.
0 commit comments