AutoFileName
AutoFileName copied to clipboard
Add support for single quotes and fix edge cases that cause duplicate attributes and incorrect ordering.
I uncovered a couple of edge case bugs while working with the plugin. I would normally split all of this up, but the solution for one issue also solved the other and I inadvertently noticed and fixed a third issue along the way.
Issue 1. Trying to insert a tag that already has a single dimension attribute can cause duplicate attributes and/or incorrect order preference.
Settings: "afn_template_languages": false, "afn_insert_width_first": true
<img src="img/wg-logo.png" width="55" class='logo'>
becomes:
<img src="img/wg-logo.png" height="62" width="311" class='logo'>
If you set "afn_template_languages": true
, it's a little worse:
img src="images/gmlmd-nav-offers.jpg" width="83"
becomes:
img src="images/gmlmd-nav-offers.jpg" width="83" height="25" width="83"
Issue 2. Incorrectly replaces dimensions in sibling tags (extract_scope
selects more than just the current tag).
Settings: afn_template_languages: false
<img src="img/first.png" width="666"><img src="img/auto_completing_this_img.png">
becomes:
<img src="img/first.png" width="311"><img src="img/auto_completing_this_img.png" height="62">
In the example, you can see dimensions in the first image were incorrectly changed when auto-completing the second image.
Issue 3. Dimension attributes with single quotes are not replaced
e.g. <img width='555' height='555' src="...">
Changes:
- Added
get_tag_scope
to specifically select ONLY the image tag in question, matching on what's autocompleted in the src attribute value because extract_scope bites off too much and captures sibling tags. - Added
clear_dimensions
to wipe out any existing dimensions before inserting new ones. Seemed to be the easiest way to solve duplicate dimensions and ordering issues. - Modified
insert_dimension
to only do an insert - replacing is unnecessary because we are clearing attributes in the tag first.