Skip to content

Commit

Permalink
Add custom component for markdown with new-tab links
Browse files Browse the repository at this point in the history
That way instead of having to do a Typescript cast every time we want to
render Markdown that opens links in a new tab, we can do the cast once
and just call a different component. We've done this already for the
lexbox frontend code in src/, so we'll do the same thing for the viewer.
  • Loading branch information
rmunn committed Dec 6, 2024
1 parent 023f83c commit fd453fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions frontend/viewer/src/lib/about/AboutDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import { mdiInformationVariantCircle } from '@mdi/js';
import { Button, Dialog, Toggle } from 'svelte-ux';
import type { Readable } from 'svelte/store';
import Markdown from 'svelte-exmarkdown';
import NewTabLinkRenderer from './NewTabLinkRenderer.svelte';
import { onMount, type Component } from 'svelte';
import NewTabLinkMarkdown from '../markdown/NewTabLinKMarkdown.svelte';
import { onMount } from 'svelte';
export let text: Readable<string>;
Expand All @@ -26,7 +25,7 @@
</Button>
<Dialog {open} on:close={toggleOff} class="w-[700px]">
<div class="m-6 prose">
<Markdown md={$text} plugins={[{ renderer: { a: NewTabLinkRenderer as unknown as Component } }]} />
<NewTabLinkMarkdown md={$text} />
</div>
<div class="flex-grow"></div>
<div slot="actions">
Expand Down
10 changes: 10 additions & 0 deletions frontend/viewer/src/lib/markdown/NewTabLinKMarkdown.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import Markdown, {type ComponentsMap} from 'svelte-exmarkdown';
import type {Component} from 'svelte';
import NewTabLinkRenderer from './NewTabLinkRenderer.svelte';
export let md: string;
const renderer: ComponentsMap = { a: NewTabLinkRenderer as unknown as Component };
</script>

<Markdown {md} plugins={[{ renderer: renderer }]} />

0 comments on commit fd453fb

Please sign in to comment.