Handle absolute markdown links with leading slash

This commit is contained in:
Sebastian Martinez
2024-03-29 11:54:54 +01:00
committed by Rūdolfs Ošiņš
parent d6f3d17805
commit 2efd0ad58e
9 changed files with 68 additions and 56 deletions
+1 -3
View File
@@ -179,11 +179,9 @@
<div class="column-right">
{#if blobResult.ok}
<BlobComponent
{path}
{baseUrl}
projectId={project.id}
{peer}
{revision}
{path}
blob={blobResult.blob}
highlighted={blobResult.highlighted}
rawPath={rawPath(tree.lastCommit.id)} />
+1 -29
View File
@@ -7,7 +7,6 @@
import * as Syntax from "@app/lib/syntax";
import { isImagePath, isMarkdownPath, isSvgPath } from "@app/lib/utils";
import { lineNumbersGutter } from "@app/lib/syntax";
import { routeToPath } from "@app/lib/router";
import Button from "@app/components/Button.svelte";
import CommitButton from "@app/views/projects/components/CommitButton.svelte";
@@ -20,8 +19,6 @@
export let baseUrl: BaseUrl;
export let projectId: string;
export let peer: string | undefined;
export let revision: string | undefined;
export let path: string;
export let blob: Blob;
export let highlighted: Syntax.Root | undefined;
@@ -53,31 +50,6 @@
$: enablePreview = isMarkdown || isSvg;
$: preview = enablePreview && selectedLineId === undefined;
let linkBaseUrl: string | undefined;
$: {
if (!path || path === "/") {
// For the default root path, the `tree/<revision>` portion is omitted
// from the URL. This means that links cannot be resolved with respect
// to the current location. To work around this we provide path that
// results a fully expanded URL with which we can resolve all links in the
// Markdown.
linkBaseUrl = new URL(
routeToPath({
resource: "project.source",
project: projectId,
node: baseUrl,
peer,
revision,
path: "README.md",
}),
window.origin,
).href;
} else {
linkBaseUrl = undefined;
}
}
afterUpdate(() => {
for (const item of document.getElementsByClassName("highlight")) {
item.classList.remove("highlight");
@@ -217,7 +189,7 @@
{:else if preview && blob.content}
{#if isMarkdown}
<div style:padding="2rem">
<Markdown {rawPath} {path} {linkBaseUrl} content={blob.content} />
<Markdown content={blob.content} {rawPath} {path} />
</div>
{:else if isSvg}
<div style:margin="1rem 0" style:text-align="center">