denoland / deno-gfm

Server-side GitHub Flavored Markdown rendering for Deno
https://jsr.io/@deno/gfm
MIT License
228 stars 37 forks source link

How to embed image? #103

Closed ooker777 closed 10 months ago

ooker777 commented 10 months ago

On static folder I have a cover.png image. In routes/index.tsx I have:

import { CSS, render } from "https://deno.land/x/gfm/mod.ts";

const body = render(`# Hello, world!
![](../static/cover.png)
![](./static/cover.png)
![](/static/cover.png)
![](static/cover.png)
`);

export default function a() {
    return <main dangerouslySetInnerHTML={{ __html: body }}>
    {body}
    </main>
} 

There is no image. Why is that?

deer commented 10 months ago

You asked the same question in the SaaSKit discord a few days ago but did not respond to either of the two people who answered you.

All of those are valid markdown, in the sense that they produce an img tag. In the future, please provide more details. Although it's now clear to me that you're using Fresh. The static files documentation says:

Fresh automatically serves static assets placed in a static/ directory in the project root.

So if you want to access your /static/cover.png file, the request (in your browser or wherever) should be to http://localhost:8000/cover.png. Then your markdown needs to be something like:

![you should always provide alt text](/cover.png)
ooker777 commented 10 months ago

Thanks. At the time of testing I was surprised that this simple feature didn't work correctly, so my confidence in believing that this is a bug not a lack of my knowledge raised... I have no idea what I was thinking...

deer commented 10 months ago

Sorry, it's not super clear whether this solved your problem. If so, please close the issue. If not, I'm happy to debug further.