Add support for single quotes and fix edge cases that cause duplicate attributes and incorrect ordering.#55
Open
manafire wants to merge 1 commit intoliamcain:st3from
Open
Add support for single quotes and fix edge cases that cause duplicate attributes and incorrect ordering.#55manafire wants to merge 1 commit intoliamcain:st3from
manafire wants to merge 1 commit intoliamcain:st3from
Conversation
… attributes and incorrect ordering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_scopeselects 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:
get_tag_scopeto 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.clear_dimensionsto wipe out any existing dimensions before inserting new ones. Seemed to be the easiest way to solve duplicate dimensions and ordering issues.insert_dimensionto only do an insert - replacing is unnecessary because we are clearing attributes in the tag first.