Handle absolute markdown links with leading slash

This commit also handles relative linking when there is no path yet.
Aka not having `/tree/..` in the URL.
This commit is contained in:
Sebastian Martinez
2024-04-04 22:24:53 +02:00
parent 7420c7ade6
commit 0c46e67f88
10 changed files with 75 additions and 57 deletions
+4 -1
View File
@@ -3,6 +3,7 @@
import markdown from "@app/lib/markdown";
import { twemoji } from "@app/lib/utils";
import { activeUnloadedRouteStore } from "@app/lib/router";
import { Renderer } from "@app/lib/markdown";
export let content: string;
@@ -13,7 +14,9 @@
const render = (content: string): string =>
dompurify.sanitize(
markdown.parseInline(content, {
renderer: new Renderer(undefined, stripEmphasizedStyling),
renderer: new Renderer($activeUnloadedRouteStore, {
stripEmphasizedStyling,
}),
}) as string,
);
</script>
+5 -4
View File
@@ -11,6 +11,7 @@
import ErrorModal from "@app/modals/ErrorModal.svelte";
import markdown from "@app/lib/markdown";
import { Renderer } from "@app/lib/markdown";
import { activeUnloadedRouteStore } from "@app/lib/router";
import { highlight } from "@app/lib/syntax";
import {
isUrl,
@@ -22,8 +23,6 @@
import { mimes } from "@app/lib/file";
export let content: string;
// If present, resolve all relative links with respect to this URL
export let linkBaseUrl: string | undefined = undefined;
export let path: string = "/";
export let rawPath: string;
// If present, means we are in a preview context,
@@ -63,7 +62,7 @@
}
/**
* Do internal navigation on for clicks on anchor elements if possible
* Do internal navigation for clicks on anchor elements if possible
*/
function navigateInternalOnAnchor(event: MouseEvent) {
if (router.useDefaultNavigation(event)) {
@@ -94,7 +93,9 @@
function render(content: string): string {
return dompurify.sanitize(
markdown.parse(content, {
renderer: new Renderer(linkBaseUrl, false),
renderer: new Renderer($activeUnloadedRouteStore, {
stripEmphasizedStyling: false,
}),
breaks,
}) as string,
);