mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-18 14:06:59 +00:00
* Fix: Fixing #2306 Links in team description is considered as a page. * Adding isValidURl util * Checking falsy condition first
This commit is contained in:
parent
845b62d48d
commit
cd65037ac7
@ -14,8 +14,10 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import ReactMarkdown, { PluggableList } from 'react-markdown';
|
import ReactMarkdown, { PluggableList } from 'react-markdown';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import rehypeRaw from 'rehype-raw';
|
import rehypeRaw from 'rehype-raw';
|
||||||
import gfm from 'remark-gfm';
|
import gfm from 'remark-gfm';
|
||||||
|
import { isValidUrl } from '../../../utils/CommonUtils';
|
||||||
|
|
||||||
/*eslint-disable */
|
/*eslint-disable */
|
||||||
const RichTextEditorPreviewer = ({
|
const RichTextEditorPreviewer = ({
|
||||||
@ -51,6 +53,27 @@ const RichTextEditorPreviewer = ({
|
|||||||
</ul>
|
</ul>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
a: ({ node, children, ...props }) => {
|
||||||
|
if (!isValidUrl(props.href as string)) {
|
||||||
|
return <span>{children}</span>;
|
||||||
|
} else {
|
||||||
|
let link = '';
|
||||||
|
const href = props.href;
|
||||||
|
if (
|
||||||
|
href?.indexOf('http://') == 0 ||
|
||||||
|
href?.indexOf('https://') == 0
|
||||||
|
) {
|
||||||
|
link = href;
|
||||||
|
} else {
|
||||||
|
link = `https://${href}`;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<Link to={{ pathname: link }} target="_blank">
|
||||||
|
{children}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
remarkPlugins={[gfm] as unknown as PluggableList | undefined}
|
remarkPlugins={[gfm] as unknown as PluggableList | undefined}
|
||||||
rehypePlugins={[[rehypeRaw, { allowDangerousHtml: false }]]}
|
rehypePlugins={[[rehypeRaw, { allowDangerousHtml: false }]]}
|
||||||
|
@ -305,3 +305,12 @@ export const getImages = (imageUri: string) => {
|
|||||||
|
|
||||||
return imagesObj;
|
return imagesObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isValidUrl = (href: string) => {
|
||||||
|
const regex = new RegExp(
|
||||||
|
// eslint-disable-next-line no-useless-escape
|
||||||
|
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g
|
||||||
|
);
|
||||||
|
|
||||||
|
return href.match(regex);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user