diff --git a/openmetadata-ui/src/main/resources/ui/src/components/common/rich-text-editor/RichTextEditorPreviewer.tsx b/openmetadata-ui/src/main/resources/ui/src/components/common/rich-text-editor/RichTextEditorPreviewer.tsx index 96c1bbcdde1..56278f26270 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/common/rich-text-editor/RichTextEditorPreviewer.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/common/rich-text-editor/RichTextEditorPreviewer.tsx @@ -14,8 +14,10 @@ import classNames from 'classnames'; import React, { useEffect, useState } from 'react'; import ReactMarkdown, { PluggableList } from 'react-markdown'; +import { Link } from 'react-router-dom'; import rehypeRaw from 'rehype-raw'; import gfm from 'remark-gfm'; +import { isValidUrl } from '../../../utils/CommonUtils'; /*eslint-disable */ const RichTextEditorPreviewer = ({ @@ -51,6 +53,27 @@ const RichTextEditorPreviewer = ({ ); }, + a: ({ node, children, ...props }) => { + if (!isValidUrl(props.href as string)) { + return {children}; + } else { + let link = ''; + const href = props.href; + if ( + href?.indexOf('http://') == 0 || + href?.indexOf('https://') == 0 + ) { + link = href; + } else { + link = `https://${href}`; + } + return ( + + {children} + + ); + } + }, }} remarkPlugins={[gfm] as unknown as PluggableList | undefined} rehypePlugins={[[rehypeRaw, { allowDangerousHtml: false }]]} diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/CommonUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/CommonUtils.tsx index ea195167910..e73985f2275 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/CommonUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/CommonUtils.tsx @@ -305,3 +305,12 @@ export const getImages = (imageUri: string) => { 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); +};