mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 06:10:44 +08:00
Load images in markdown documents
This loads images asynchronously inside markdown documents. Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -48,6 +48,12 @@
|
||||
return state.blob;
|
||||
};
|
||||
|
||||
// Get an image blob based on a relative path.
|
||||
const getImage = async (imagePath: string): Promise<proj.Blob> => {
|
||||
const finalPath = utils.canonicalize(imagePath, path);
|
||||
return project.getBlob(commit, finalPath, { highlight: false });
|
||||
};
|
||||
|
||||
const onSelect = async ({ detail: newPath }: { detail: string }) => {
|
||||
// Ensure we don't spend any time in a "loading" state. This means
|
||||
// the loading spinner won't be shown, and instead the blob will be
|
||||
@@ -159,7 +165,7 @@
|
||||
<Loading small center />
|
||||
{:then blob}
|
||||
{#if utils.isMarkdownPath(blob.path)}
|
||||
<Readme content={blob.content} />
|
||||
<Readme content={blob.content} {getImage} />
|
||||
{:else}
|
||||
<Blob line={browser.line} {blob} />
|
||||
{/if}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<script lang="ts">
|
||||
import Markdown from '@app/Markdown.svelte';
|
||||
import type * as proj from '@app/project';
|
||||
|
||||
export let content: string;
|
||||
export let getImage: (path: string) => Promise<proj.Blob>;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -12,5 +15,5 @@
|
||||
</style>
|
||||
|
||||
<article>
|
||||
<Markdown {content} />
|
||||
<Markdown {content} {getImage} />
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user