-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathTextSummary.jsx
More file actions
31 lines (28 loc) · 1013 Bytes
/
TextSummary.jsx
File metadata and controls
31 lines (28 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React from "react";
import { convertToReactComponent } from "@patternfly/ast-helpers";
import { Content } from "@patternfly/react-core";
// convert summary text from string to jsx, remove links
export const SummaryComponent = ({ id, itemsData }) => {
const itemDasherized = id.split(" ").join("-").toLowerCase();
const summary = itemsData?.[itemDasherized]?.summary;
if (!summary) {
return null;
}
// Remove anchor tags to avoid <a> in summary nested within <a> of Link card/datalistitem
const summaryNoLinks = summary.replace(/<Link[^>]*>([^<]+)<\/Link>/gm, "$1");
const { code } = convertToReactComponent(`<>${summaryNoLinks}</>`);
const getSummaryComponent = new Function("React", code);
return getSummaryComponent(React);
};
export const TextSummary = ({ id, itemsData }) => {
if (!id) {
return null;
}
return (
<Content isEditorial>
<Content component="p">
<SummaryComponent id={id} itemsData={itemsData} />
</Content>
</Content>
);
};