-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly handles classes on markdown images
- Loading branch information
1 parent
ce4597b
commit f1e44d9
Showing
5 changed files
with
13 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
--- | ||
import type { ImageMetadata } from "astro"; | ||
import type { HTMLAttributes } from "astro/types"; | ||
import md from "markdown-it"; | ||
import type { Props as ImageProps } from "./Image.astro"; | ||
import Image from "./Image.astro"; | ||
type Props = Omit<ImageProps, "src"> & { | ||
type Props = Omit<ImageProps, "src" | "slot"> & { | ||
src: Promise<{ default: ImageMetadata }>; | ||
caption?: string; | ||
figureProps: HTMLAttributes<"figure">; | ||
}; | ||
let { alt, caption } = Astro.props; | ||
let { alt, caption, src, figureProps, ...props } = Astro.props; | ||
if (caption) { | ||
caption = md({}).renderInline(caption); | ||
} | ||
const src = (await Astro.props.src).default; | ||
const resolvedSrc = (await src).default; | ||
--- | ||
|
||
<figure> | ||
<a href={src.src}> | ||
<Image src={src} alt={alt} /> | ||
<figure {...figureProps ?? {}}> | ||
<a href={resolvedSrc.src}> | ||
<Image src={resolvedSrc} alt={alt} {...props} /> | ||
</a> | ||
{caption && <figcaption set:html={caption} />} | ||
</figure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters