Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed img tag if transformation fails. #204

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Pass/ImgTagTransformPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function pass()
$has_height_and_width = $this->setResponsiveImgHeightAndWidth($el);
if (!$has_height_and_width) {
$this->addActionTaken(new ActionTakenLine('img', ActionTakenType::IMG_COULD_NOT_BE_CONVERTED, $lineno, $context_string));
$el->remove();
continue;
}
if ($this->isPixel($el)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ Transformations made from HTML tags to AMP custom tags

AMP-HTML Validation Issues and Fixes
-------------------------------------
FAIL

<img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/non-existent-image1234.jpg"> on line 14
- The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'?
[code: MANDATORY_TAG_ANCESTOR_WITH_HINT category: DISALLOWED_HTML_WITH_AMP_EQUIVALENT see: https://www.ampproject.org/docs/reference/amp-img.html]
ACTION TAKEN: img tag was removed due to validation issues.
PASS

COMPONENT NAMES WITH JS PATH
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/test-data/fragment-html/img-test-fragment.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- should transform to amp-img with fixed layout, preserving the width and height -->
<img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/%22Birdcatcher%22_with_jockey_up.jpg" width="125" height="96">

<!-- nonexistent image, should refuse to convert to amp-img and keep it as it is -->
<!-- nonexistent image, should refuse to convert to amp-img and not include a tag -->
<img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/non-existent-image1234.jpg">

<!-- should provide layout and height width and make layout responsive -->
Expand Down
10 changes: 3 additions & 7 deletions tests/test-data/fragment-html/img-test-fragment.html.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<!-- should transform to amp-img with fixed layout, preserving the width and height -->
<amp-img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/%22Birdcatcher%22_with_jockey_up.jpg" width="125" height="96" layout="fixed"></amp-img>

<!-- nonexistent image, should refuse to convert to amp-img and keep it as it is -->
<img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/non-existent-image1234.jpg">
<!-- nonexistent image, should refuse to convert to amp-img and not include a tag -->


<!-- should provide layout and height width and make layout responsive -->
<amp-img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/%22Birdcatcher%22_with_jockey_up.jpg" layout="responsive" width="625" height="480"></amp-img>
Expand Down Expand Up @@ -38,7 +38,7 @@ Line 5:
Line 6: <!-- should transform to amp-img with fixed layout, preserving the width and height -->
Line 7: <img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/%22Birdcatcher%22_with_jockey_up.jpg" width="125" height="96">
Line 8:
Line 9: <!-- nonexistent image, should refuse to convert to amp-img and keep it as it is -->
Line 9: <!-- nonexistent image, should refuse to convert to amp-img and not include a tag -->
Line 10: <img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/non-existent-image1234.jpg">
Line 11:
Line 12: <!-- should provide layout and height width and make layout responsive -->
Expand Down Expand Up @@ -84,10 +84,6 @@ AMP-HTML Validation Issues and Fixes
-------------------------------------
FAIL

<img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/non-existent-image1234.jpg"> on line 10
- The tag 'img' may only appear as a descendant of tag 'noscript'. Did you mean 'amp-img'?
[code: MANDATORY_TAG_ANCESTOR_WITH_HINT category: DISALLOWED_HTML_WITH_AMP_EQUIVALENT see: https://www.ampproject.org/docs/reference/amp-img.html]

<amp-img src="https://upload.wikimedia.org/wikipedia/commons/e/ee/%22Birdcatcher%22_with_jockey_up.jpg"> on line 13
- The implied layout 'CONTAINER' is not supported by tag 'amp-img'.
[code: IMPLIED_LAYOUT_INVALID category: AMP_LAYOUT_PROBLEM see: https://www.ampproject.org/docs/reference/amp-img.html]
Expand Down