Needs review
Project:
YUI Rich Text Editor
Version:
5.x-2.6-96
Component:
Code
Priority:
Minor
Category:
Bug report
Assigned:
Reporter:
Created:
6 Aug 2008 at 09:46 UTC
Updated:
23 Jan 2009 at 05:20 UTC
Jump to comment: Most recent file
When you use the YUI editor to resize an image, it uses inline styles to do the work
<img style="width: 100px; height: 70px;" alt="" src="/files_saw/images/my_image.jpg" />
but the Drupal HTML filter removes this style information upon output.
There are security reasons to remove inline styles apparently, so the easiest quick fix might be to write an input format filter, applied before the Drupal HTML filter that converts the inline css to html tags which will then get through the Drupal HTML filter.
<img width=100px height=70px alt="" src="/files_saw/images/my_image.jpg" />
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | imagecache.patch | 7.95 KB | chrisyates |
| #4 | yui_editor_hacked_about.zip | 31.28 KB | muhleder |
Comments
Comment #1
jeffcd commentedThis could be a bit tricky to handle. I will look and see if there is a setting to force the editor not to use style tags and update accordingly.
Comment #2
muhleder commentedYes, I did have a look at making a custom filter that would turn the style tags into html attributes, but it was getting a bit complicated with all the css properties that can be applied using the yui editor.
I did manage to hack the core html filter to allow styles. You have to alter Line 1489 to add width: height: etc to allowed 'protocols' in attribute value and Line 1387 to allow 'style' attribute through. Not the best way of going about things but it could be a start for someone to make a custom filter that allows styles through. The problem is that you also need to prevent css expressions because IE will run javascript through them, which is a security hole. So some sort of regex to remove expression(*) would be required to run through the inline style at a minimum. Not sure if there are any other issues with allowing inline styles.
I ended up modifying the module javascript to link up to imagecache, have to hard code the file path and imagecache presets, not sure how that could be set using an admin interface in drupal, but I think it's quite nice for the end users, they get the images auto-resized on upload, and have a drop down box to pick small, medium or large. Used a bit of css to hide the size inputs on the image editor for now, I'm pretty sure that they can be switched off using the javascript.
Javascript function to replace yui_img_uploader function from the module's javascript
Comment #3
miche1. HTML Filter stripping out "style" attributes.
-- I am working on a module that is a filter to use with YUI. It closely replicates the standard HTML Filter.
2. Image size pre-sets
-- I am interested in the above javascript, but didn't have any luck with it working. Has anyone else tried it?
Comment #4
muhleder commentedHere's a zipped copy of the module as it's being used. It has a load of other hacks applied I think, pretty much all in yui_editor.js
The values yui_small etc in the select need to match your imagecache preset names.
I quite like the ease of use, but I think it could do with some error handling, have had a report of it working intermittently under IE.
Comment #5
muhleder commentedDon't know if you've seen this, but someone's having a go at putting a filter together that allows inline style.
http://groups.drupal.org/node/15979
Comment #6
michemuhleder, thanks for the link!
Comment #7
les limHere's the link to the project referenced in #5:
http://drupal.org/project/wysiwyg_filter
looks like there's only a 6.x release at the moment.
Comment #8
chrisyates commented@muhleder - I modified your code in yui_editor.js and yui_editor.module to allow for dynamically querying imagecache presets as well as file upload directories. I just need to finish the js detection of imagecache's existance, and I'll post up some code shortly. This is for version 5.x-2.6-96.
Comment #9
chrisyates commentedOk, here's my patch against 5.x-2.6-96.
Note that I've done some of the modifications to yui_editor.js in jQuery, as I'm not familiar with YUI's ajax methods, and jQuery is available out of the box on Drupal 5 anyway.
EDIT: I've got an extraneous console.log that needs to be removed.