I there a way to make img tags render as top level elements
See original GitHub issuecurrently even if the markdown file has just an img, it will render as so: <p><img/></p>
Is there a way to make img’s top level block components?
so I would get from a markdown file with a couple of pargraph’s and an img in the middle the following html:
<p>some text/markdown</p>
<p>some text</p>
<img/>
<p>some text</p>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Top Results From Across the Web
<img>: The Image Embed element - HTML - MDN Web Docs
The HTML element embeds an image into the document.
Read more >HTML Tags Guide To Adding Images To Your Web Documents »
Using the <img> tag. The <img> element is the most straight-forward way of displaying a static image on a page. You should normally...
Read more >The picture element - web.dev
You can specify multiple source elements inside a picture element, each one with its own srcset attribute. The browser then executes the first...
Read more >CSS I want a div to be on top of everything - Stack Overflow
In order for z-index to work, you'll need to give the element a position:absolute or a position:relative property. Once you do that, your...
Read more >A 4-Minute Guide to the Img src Attribute in HTML
That's why it's important to understand how the image element and source attribute work in HTML. It can come in handy when you're...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The following hack works (inspired by @coreyward’s approach).
It removes nesting altogether when a
p
tag has anImage
child.I have a similar issue, only I’m using the overrides to replace the
img
prop with a React component (Gatsby Image) and that’s creating invalid markup (p > div
). For now I’m sidestepping the issue with this approach/hack:Effectively I’m checking the type of the children (bad since React expects
children
to be treated as opaque) and if it’s not a string render adiv
element. This has been working for the project I need it on, but I suspect there are more than a few pitfalls I haven’t run into yet.It would be great to get this as an option, or for the library to expose a function to an overridden element that would let it determine the type of the parent/ancestor.