From a148d2977026911daab97c54639695c3d1ce4fe5 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Fri, 15 May 2020 09:54:20 +0200 Subject: [PATCH] Correct mixing concepts, Link instead of a for internal links, adjust regex --- .../src/MarkdownLinkRenderer.tsx | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx b/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx index 2e512fde51..3b97bcedef 100644 --- a/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx +++ b/scm-ui/ui-components/src/MarkdownLinkRenderer.tsx @@ -21,15 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -import React, { ReactNode } from "react"; -import { withRouter, RouteComponentProps } from "react-router-dom"; +import React, { FC, ReactNode } from "react"; +import { Link, useLocation } from "react-router-dom"; import { withContextPath } from "./urls"; -type Props = RouteComponentProps & { +type Props = { children: ReactNode; href: string; }; +const regex = new RegExp("[a-z]:"); + /** * Handle local SCM-Manager and external links * @@ -40,8 +42,7 @@ export function correctLocalLink(pathname: string, link: string) { return pathname; } - // Leave uris unchanged which start with schemes - const regex = new RegExp(".:"); + // Leave uris unchanged which start with schemes or fragment if (link.match(regex) || link.startsWith("#")) { return link; } @@ -73,9 +74,15 @@ export function correctLocalLink(pathname: string, link: string) { return base + path; } -function MarkdownLinkRenderer(props: Props) { - const compositeUrl = correctLocalLink(withContextPath(props.location.pathname), props.href); - return {props.children}; -} -export default withRouter(MarkdownLinkRenderer); +const MarkdownLinkRenderer: FC = ({ children, href }) => { + const location = useLocation(); + const compositeUrl = correctLocalLink(withContextPath(location.pathname), href); + + if (compositeUrl.match(regex)) { + return {children}; + } + return {children}; +}; + +export default MarkdownLinkRenderer;