Skip to content

Commit

Permalink
Only add space between classes if preexisting class is present (#1124)
Browse files Browse the repository at this point in the history
* Only add space between classes if preexisting class is present

* Adapt expected output for layout test
  • Loading branch information
schlessera committed Jan 11, 2021
1 parent 881ffbd commit ba1a176
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/optimizer/lib/transformers/ApplyLayout.js
Expand Up @@ -48,7 +48,8 @@ function getAttributeOrNull(element, name) {
}

function addClass(node, value) {
node.attribs.class = hasAttribute(node, 'class') ? node.attribs.class + ' ' + value : value;
const existingClass = hasAttribute(node, 'class') ? node.attribs.class.trim() : '';
node.attribs.class = existingClass.length > 0 ? existingClass + ' ' + value : value;
}

function apply(layout, width, height, node) {
Expand Down
Expand Up @@ -7,10 +7,10 @@
<i-amphtml-sizer style="display:block;padding-top:33.3333%"></i-amphtml-sizer>
</amp-img>
<!-- Auto adds responsive attribute if height, width and sizes -->
<amp-ad class=" i-amphtml-layout-responsive i-amphtml-layout-size-defined" type="taboola" data-block-on-consent="_till_responded" width="300" height="250" data-publisher="..." data-mode="thumbnails-a-amp" data-placement="Mobile Below Article Thumbnails AMP" data-article="auto" data-target_type="mix" layout="responsive" i-amphtml-layout="responsive">
<amp-ad class="i-amphtml-layout-responsive i-amphtml-layout-size-defined" type="taboola" data-block-on-consent="_till_responded" width="300" height="250" data-publisher="..." data-mode="thumbnails-a-amp" data-placement="Mobile Below Article Thumbnails AMP" data-article="auto" data-target_type="mix" layout="responsive" i-amphtml-layout="responsive">
<i-amphtml-sizer style="display:block;padding-top:83.3333%"></i-amphtml-sizer>
<!-- Auto adds responsive attribute if height, width and heights -->
<amp-ad class=" i-amphtml-layout-responsive i-amphtml-layout-size-defined" type="taboola" data-block-on-consent="_till_responded" width="300" height="250" data-publisher="..." data-mode="thumbnails-a-amp" data-placement="Mobile Below Article Thumbnails AMP" data-article="auto" data-target_type="mix" layout="responsive" i-amphtml-layout="responsive" id="i-amp-0">
<amp-ad class="i-amphtml-layout-responsive i-amphtml-layout-size-defined" type="taboola" data-block-on-consent="_till_responded" width="300" height="250" data-publisher="..." data-mode="thumbnails-a-amp" data-placement="Mobile Below Article Thumbnails AMP" data-article="auto" data-target_type="mix" layout="responsive" i-amphtml-layout="responsive" id="i-amp-0">
<i-amphtml-sizer style="display:block;padding-top:83.3333%"></i-amphtml-sizer>
</amp-ad>
</amp-ad>
Expand Down

0 comments on commit ba1a176

Please sign in to comment.