PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / team-updraft / lib-onboarding-wizard / Wizard / Onboarding / src / utils / html.tsx

html.tsx in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/team-updraft/lib-onboarding-wizard/Wizard/Onboarding/src/utils/html.tsx

24 lines 718 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import * as DOMPurify from "isomorphic-dompurify";
2
3 export const isLikelyHtml = (s: string) => /<[^>]+>/.test(s);
4
5 const sanitizeHtml = (dirty: string, custom?: (dirty: string) => string) => {
6 if (custom) {
7 return custom(dirty);
8 }
9 return DOMPurify.sanitize(dirty, {
10 ADD_ATTR: ['target', 'rel', 'class', 'style'],
11 });
12 };
13
14 const HtmlBlock = ({ html }: { html: string }) => (
15 <span dangerouslySetInnerHTML={{ __html: html }} />
16 );
17
18 export const renderPossiblyHtml = (value: string, sanitize?: (dirty: string) => string) => {
19 if (isLikelyHtml(value)) {
20 const clean = sanitizeHtml(value, sanitize);
21 return <HtmlBlock html={clean} />;
22 }
23 return <>{value}</>;
24 };