Enforce attribute order? April 08, 2008 08:19PM |
Registered: 11 years ago Posts: 4 |
I'm using HTMLpurifier in combination with FCKeditor, and PEAR's Text_Diff to power a proprietary, HTML-based wiki solution.
Unfortunately, FCK has a nasty habit of reversing attribute order on tags. So
<a href="x" title="j">
becomes
<a title="j" href="x">
after editing in FCK; editing again gets you back to
<a href="x" title="j">
.
This results in text_diff seeing a change on every tag with more than 1 attribute, on every wiki edit, meaning wiki diffs are unreadable.
My question is this: how hard would it be to have HTML purifier enforce an arbitrary attribute order? (e.g., alphabetical, so that 'href' always comes before 'title')
Re: Enforce attribute order? April 08, 2008 08:54PM |
Admin Registered: 12 years ago Posts: 3,123 |
That's... weird. O.o
Try this patch:
Index: HTMLPurifier/Generator.php =================================================================== --- HTMLPurifier/Generator.php (revision 1646) +++ HTMLPurifier/Generator.php (working copy) @@ -141,6 +141,7 @@ */ public function generateAttributes($assoc_array_of_attributes, $element) { $html = ''; + ksort($assoc_array_of_attributes); foreach ($assoc_array_of_attributes as $key => $value) { if (!$this->_xhtml) { // remove namespaced attributes
I'll add proper support for it in 3.1.0.
Re: Enforce attribute order? June 23, 2008 08:48PM |
Registered: 11 years ago Posts: 4 |
Re: Enforce attribute order? June 23, 2008 10:01PM |
Admin Registered: 12 years ago Posts: 3,123 |
Re: Enforce attribute order? June 24, 2008 10:37PM |
Admin Registered: 12 years ago Posts: 3,123 |
Committed as 24f6db6. You'll need to use the %Output.SortAttr directive.