fix: open markdown links in user's default browser

Closes #54
This commit is contained in:
2026-01-21 18:01:21 -08:00
committed by Naomi Carrigan
parent 947e56ef41
commit ab3f6700f6
+14 -1
View File
@@ -2,6 +2,7 @@
import { marked } from "marked";
import hljs from "highlight.js";
import { onMount } from "svelte";
import { openUrl } from "@tauri-apps/plugin-opener";
interface Props {
content: string;
@@ -75,6 +76,15 @@
}
}
function handleLinkClick(event: MouseEvent) {
const target = event.target as HTMLElement;
const anchor = target.closest("a");
if (anchor?.href) {
event.preventDefault();
openUrl(anchor.href);
}
}
onMount(() => {
if (containerElement) {
containerElement.querySelectorAll("pre code:not(.hljs)").forEach((block) => {
@@ -87,7 +97,10 @@
<div
bind:this={containerElement}
class="markdown-content"
onclick={handleSpoilerClick}
onclick={(e) => {
handleSpoilerClick(e);
handleLinkClick(e);
}}
onkeydown={handleSpoilerKeydown}
role="presentation"
>