fix: [code-1139]: fix relative link support (#822)

rkapoor10-patch-1
Calvin Lee 2023-11-27 19:06:44 +00:00 committed by Harness
parent 4fc38bca65
commit 5b16c72d4a
1 changed files with 7 additions and 1 deletions

View File

@ -125,7 +125,13 @@ export function MarkdownViewer({ source, className, maxHeight, darkMode }: Markd
// Test if the link is relative to the current page.
// If true, rewrite it to point to the correct location
if (new URL(window.location.href + '/' + href).origin === window.location.origin) {
properties.href = (refRootHref + '/~/' + href).replace(/^\/ng\//, '/')
const currentPath = window.location.href.split('~/')[1]
properties.href = (
refRootHref +
'/~/' +
(currentPath && !currentPath.includes(href) ? currentPath.replace('/README.md', '') + '/' : '') +
href
).replace(/^\/ng\//, '/')
}
} catch (_exception) {
// eslint-disable-line no-empty