# Markdown rendering issue with image surrounded with HTML

**URL:** https://meta.discourse.org/t/markdown-rendering-issue-with-image-surrounded-with-html/152801
**Category:** Bug
**Created:** [May 26, 2020, 5:21pm UTC](https://meta.discourse.org/t/markdown-rendering-issue-with-image-surrounded-with-html/152801 "2020-05-26T17:21:21Z")
**Posts on this page:** 1
**Showing post:** 28

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [August 11, 2021, 11:29am UTC](https://meta.discourse.org/t/markdown-rendering-issue-with-image-surrounded-with-html/152801/28 "2021-08-11T11:29:48Z")

</div>

> [@angus](#):
>
> Yes, put more simply, perhaps the code could support downloading hotlinked images without requiring a conversion of the `img` to markdown.

Yeah, I think this is probably the best option. I did make a start on it back in June 2020, but it ended up being a lot of work, and I had to move on to other projects. I had a couple of approaches to allowing `upload://` URLs in `<img` tags… neither is perfect. From my notes:

* * *

### Implementation 1:

In the markdown pipeline, parse the content of each html\_block (by slightly abusing the `xss.js` library), and process any image tags with upload:// src attributes.

Pros: all in the markdown pipeline, only does this processing on html\_block tokens

Cons: kinda misusing the `xss.js` sanitizer. It might not be a perfect HTML5 parser

[https://github.com/davidtaylorhq/discourse/commit/39b14af21bcc0cb442a23c45b09ddfa095c06174](https://github.com/davidtaylorhq/discourse/commit/39b14af21bcc0cb442a23c45b09ddfa095c06174)

This option could be improved by using a standards-compliant javascript DOM implementation (e.g. jsdom) on the server, but that seems pretty heavyweight.

### Implementation 2:

Allow upload:// src attributes all the way through the markdown pipeline, then replace them later. On the client, this is actually pretty simple - we were already replacing upload:// urls asynchronously after cooking. On the server, this does an extra processing step using Nokogiri.

Pros: parser is HTML5 standards compliant

Cons: different implementation on client/server, makes pipeline slightly more complex

[https://github.com/davidtaylorhq/discourse/commit/2ae1dafeca20fdd8717fbed0eb3b6c0fa0fe0644](https://github.com/davidtaylorhq/discourse/commit/2ae1dafeca20fdd8717fbed0eb3b6c0fa0fe0644)

* * *

I think option 2 is probably the way to go. We’ll then need to update the pull\_hotlinked\_images job to maintain `<img` tags, without replacing them with Markdown. I hope I can find time to get back to this soon 🤞

---

_[View the full topic](https://meta.discourse.org/t/markdown-rendering-issue-with-image-surrounded-with-html/152801)._
