Add an ID or CLASS to an image (within a post)

Correct, <div> tags also have very specific properties that are whitelisted. Those can be found here:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/white-lister.js.es6#L141-L152

That file - it is the same one from my earlier post - contains all the whitelisted markup allowed in the composer so have a look around to see what is allowed. Anything not on that list will be stripped out to prevent abuse.

The <html> tag has a CSS class added to it to when the user is not logged in. That class is anon. You can use that class to selectively show the banners. So something like this in your post:

<div data-theme-banners>
  <a href="#">
    <img src="foo">
  </a> 
</div>

and this in your theme

html:not(.anon) .cooked [data-theme-banners] {
  display: none;
}

and that would ensure that the element is only visible to users who are not logged in.

3 Likes