investigating Max-width for img tags

TiG
TiG
@tig
4 years ago
184 posts
We have users dropping in large images within comments (and discussions/blogs) which sometimes go past the maximum width of the text area (and thus are truncated). The natural solution would be to inject style="max-width:100%;" for the img tag.

Unfortunately the html_purifier (called via the update form) strips max-width. I have attempted dissuade html_purifier but ran into the finalization problem discussed years ago on this forum (with no resolution). My guess is that it is still a nightmare to try to influence html_purifier attributes.

So basically I am looking for a suggestion. The question essentially is: how can one get style="max-width:100%;" to remain in effect for img tags that are edited (and thus filtered)?


--
TiG

updated by @tig: 04/29/20 04:34:33AM
nate
@nate
4 years ago
911 posts
max-width:100% is an illegal rule anyway. You have to use px. You should be able to just edit your CSS file. Use one of the comment classes or IDs and then write the rule for img. For example
.comment_page_section div img { max-width: 200px}

updated by @nate: 01/22/20 07:04:53AM
TiG
TiG
@tig
4 years ago
184 posts
Thanks for responding Nate.

CSS for presentation would indeed work as a fix. I will probably resort to that if there is no way to more surgically (i.e. acting only when necessary) address the problem in the stored content. My preference is to prevent max-width from being filtered out so that I can programmatically inject it where necessary (selectively).

As a side point, max-width:100% is legal and accomplishes exactly what I seek.

Thanks.


--
TiG
brian
@brian
4 years ago
10,136 posts
TiG:
We have users dropping in large images within comments (and discussions/blogs) which sometimes go past the maximum width of the text area (and thus are truncated). The natural solution would be to inject style="max-width:100%;" for the img tag.

Unfortunately the html_purifier (called via the update form) strips max-width. I have attempted dissuade html_purifier but ran into the finalization problem discussed years ago on this forum (with no resolution). My guess is that it is still a nightmare to try to influence html_purifier attributes.

So basically I am looking for a suggestion. The question essentially is: how can one get style="max-width:100%;" to remain in effect for img tags that are edited (and thus filtered)?


max-width should be an allowed parameter on img tags - I can check that out.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags