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:
Alexis Sellier
2022-03-21 12:39:39 +01:00
parent ec9e4fd16d
commit 8e77f9f5ae
4 changed files with 72 additions and 5 deletions
+7 -1
View File
@@ -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}
+4 -1
View File
@@ -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>