Skip to content

Commit

Permalink
fix: populated image src in markdown
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Oct 3, 2024
1 parent 2fba746 commit 66cca8a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
28 changes: 28 additions & 0 deletions apps/renderer/src/components/ui/markdown/renderers/InlineImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { cn } from "~/lib/utils"
import { useEntryContentContext } from "~/modules/entry-content/hooks"

import { Media } from "../../media"
import { usePopulatedFullUrl } from "../utils"

export const MarkdownInlineImage = (
props: React.ImgHTMLAttributes<HTMLImageElement> & {
proxy?: {
width: number
height: number
}
},
) => {
const { feedId } = useEntryContentContext()
const populatedUrl = usePopulatedFullUrl(feedId, props.src)
return (
<Media
type="photo"
{...props}
src={populatedUrl}
mediaContainerClassName={cn("inline max-w-full rounded-md")}
popper
className="inline"
showFallback
/>
)
}
18 changes: 5 additions & 13 deletions apps/renderer/src/lib/parse-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ShikiHighLighter } from "~/components/ui/code-highlighter"
import { MarkdownBlockImage, MarkdownLink, MarkdownP } from "~/components/ui/markdown/renderers"
import { BlockError } from "~/components/ui/markdown/renderers/BlockErrorBoundary"
import { createHeadingRenderer } from "~/components/ui/markdown/renderers/Heading"
import { MarkdownInlineImage } from "~/components/ui/markdown/renderers/InlineImage"
import { Media } from "~/components/ui/media"

function markInlineImage(node?: Element) {
Expand Down Expand Up @@ -208,19 +209,10 @@ const Img: Components["img"] = ({ node, ...props }) => {
proxy: { height: 0, width: 700 },
}

if (node?.properties.inline) {
return createElement(Media, {
type: "photo",
...nextProps,

mediaContainerClassName: tw`max-w-full inline rounded-md`,
popper: true,
className: tw`inline`,
showFallback: true,
})
}

return createElement(MarkdownBlockImage, nextProps)
return createElement(
node?.properties.inline ? MarkdownInlineImage : MarkdownBlockImage,
nextProps,
)
}

function extractCodeFromHtml(htmlString: string) {
Expand Down

0 comments on commit 66cca8a

Please sign in to comment.