aboutsummaryrefslogtreecommitdiff
path: root/src/lib/MarkdownLink.svelte
blob: a4c62112d9099fb805af084d7abecfe50f740bf9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script lang="ts">
  interface Props {
    href: string;
    text: string;
  }

  let { href = $bindable(), text }: Props = $props();

  try {
    let url = new URL(href);

    switch (url.protocol) {
      case 'javascript:':
        href = '#';
        break;

      default:
        break;
    }
  } catch (error) {
    href = '#';
  }
</script>

<a {href} target="_blank">{text}</a>