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
+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,
);