Skip to content

Commit

Permalink
MWPW-164755:Add <br> when copying multiple blocks (#3684)
Browse files Browse the repository at this point in the history
* MWPW-164755:Add <br> when copying multiple blocks

* MWPW-164755: Update mocks

* MWPW-164755: Add <br> after every element in the container

* MWPW-164755: Remove string from blob

Co-authored-by: Okan Sahin <[email protected]>

---------

Co-authored-by: Okan Sahin <[email protected]>
  • Loading branch information
zagi25 and mokimo authored Feb 18, 2025
1 parent a814ee9 commit 88c0568
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions libs/blocks/library-config/lists/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export function getHtml(container, path) {

const isBlock = element.nodeName === 'DIV' && element.className;
const content = isBlock ? getTable(element) : element.outerHTML;
return `${acc}${content}`;
const brTop = !acc || acc.endsWith('<br>') ? '' : BLOCK_SPACING;
return `${acc}${brTop}${content}${BLOCK_SPACING}`;
}, '');
}

Expand Down Expand Up @@ -283,7 +284,7 @@ export default async function loadBlocks(blocks, list, query, type) {
const containerHtml = getHtml(container, block.path);
e.target.classList.add('copied');
setTimeout(() => { e.target.classList.remove('copied'); }, 3000);
const blob = new Blob([`${BLOCK_SPACING}${containerHtml}${BLOCK_SPACING}`], { type: 'text/html' });
const blob = new Blob([containerHtml], { type: 'text/html' });
createCopy(blob);
});
item.append(name, copy);
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/library-config/mocks/blocks/chart/docx.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<table border="1" style="width: 100%"><tr><th colspan="1">chart (area, green, border)</th></tr><tr><td style="width: 100%">
<h3 id="lorem-ipsum-dolor-sit-amet-consectetuer-adipiscing-elit">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</h3>
</td></tr><tr><td style="width: 100%">Revenue dollars: 2020 vs 2021 forecasted vs 2021 actuals.</td></tr><tr><td style="width: 100%"><a href="https://main--milo--adobecom.hlx.page/docs/library/blocks/chart_data/areachart.json">https://main--milo--adobecom.hlx.page/docs/library/blocks/chart_data/areachart.json</a></td></tr><tr><td style="width: 100%">Footnote lorem ipsum dolor sit amet, consectetuer adipiscing elit.</td></tr></table>
</td></tr><tr><td style="width: 100%">Revenue dollars: 2020 vs 2021 forecasted vs 2021 actuals.</td></tr><tr><td style="width: 100%"><a href="https://main--milo--adobecom.hlx.page/docs/library/blocks/chart_data/areachart.json">https://main--milo--adobecom.hlx.page/docs/library/blocks/chart_data/areachart.json</a></td></tr><tr><td style="width: 100%">Footnote lorem ipsum dolor sit amet, consectetuer adipiscing elit.</td></tr></table><br>
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<table border="1" style="width: 100%"><tr><th colspan="1">carousel (lightbox)</th></tr><tr><td style="width: 100%">Carousel lightbox</td></tr></table><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">style</td><td style="width: 50%">xxl spacing</td></tr></table><p>---</p><h3 id="avocado-surprise">Avocado surprise</h3><p>
<table border="1" style="width: 100%"><tr><th colspan="1">carousel (lightbox)</th></tr><tr><td style="width: 100%">Carousel lightbox</td></tr></table><br><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">style</td><td style="width: 50%">xxl spacing</td></tr></table><br><p>---</p><br><h3 id="avocado-surprise">Avocado surprise</h3><br><p>
<picture>
<source type="image/webp" srcset="/test/blocks/library-config/mocks/media_1.png?width=2000&amp;format=webply&amp;optimize=medium" media="(min-width: 600px)">
<source type="image/webp" srcset="/test/blocks/library-config/mocks/media_1.png?width=750&amp;format=webply&amp;optimize=medium">
<source type="image/png" srcset="/test/blocks/library-config/mocks/media_1.png?width=2000&amp;format=png&amp;optimize=medium" media="(min-width: 600px)">
<img loading="lazy" alt="" type="image/png" src="https://main--milo--adobecom.hlx.page/media_1.png?width=750&amp;format=png&amp;optimize=medium" width="200" height="147">
</picture>
</p><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">carousel</td><td style="width: 50%">Carousel lightbox</td></tr><tr><td style="width: 50%">style</td><td style="width: 50%">Center</td></tr></table><p>---</p><h3 id="cabage-surprise">Cabage surprise</h3><p>
</p><br><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">carousel</td><td style="width: 50%">Carousel lightbox</td></tr><tr><td style="width: 50%">style</td><td style="width: 50%">Center</td></tr></table><br><p>---</p><br><h3 id="cabage-surprise">Cabage surprise</h3><br><p>
<picture>
<source type="image/webp" srcset="/test/blocks/library-config/mocks/media_1.png?width=2000&amp;format=webply&amp;optimize=medium" media="(min-width: 600px)">
<source type="image/webp" srcset="/test/blocks/library-config/mocks/media_1.png?width=750&amp;format=webply&amp;optimize=medium">
<source type="image/png" srcset="/test/blocks/library-config/mocks/media_1.png?width=2000&amp;format=png&amp;optimize=medium" media="(min-width: 600px)">
<img loading="lazy" alt="" type="image/png" src="https://main--milo--adobecom.hlx.page/media_1.png?width=750&amp;format=png&amp;optimize=medium" width="200" height="147">
</picture>
</p><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">carousel</td><td style="width: 50%">Carousel lightbox</td></tr><tr><td style="width: 50%">style</td><td style="width: 50%">Center</td></tr></table><p>---</p>
</p><br><table border="1" style="width: 100%"><tr><th colspan="2">section-metadata</th></tr><tr><td style="width: 50%">carousel</td><td style="width: 50%">Carousel lightbox</td></tr><tr><td style="width: 50%">style</td><td style="width: 50%">Center</td></tr></table><br><p>---</p><br>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<table border="1" style="width: 100%"><tr><th colspan="1">carousel (container0)</th></tr><tr><td style="width: 100%">Carousel container</td></tr></table>
<table border="1" style="width: 100%"><tr><th colspan="1">carousel (container0)</th></tr><tr><td style="width: 100%">Carousel container</td></tr></table><br>
2 changes: 1 addition & 1 deletion test/blocks/library-config/mocks/blocks/marquee/docx.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ <h2 id="heading-xl-marquee-standard-medium-left">Heading XL Marquee standard med
<source type="image/png" srcset="/test/blocks/library-config/mocks/media_1.png?width=2000&amp;format=png&amp;optimize=medium" media="(min-width: 600px)">
<img loading="lazy" alt="" type="image/png" src="https://main--milo--adobecom.hlx.page/media_1.png?width=750&amp;format=png&amp;optimize=medium" width="199" height="100">
</picture>
</td></tr></table>
</td></tr></table><br>
2 changes: 1 addition & 1 deletion test/blocks/library-config/mocks/blocks/text/docx.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<h3 id="text">Text</h3>
<p>Kick things off with hundreds of premium and free presets you can access with your Lightroom subscription.</p>
<p><em><a href="bookmark://nada">Learn more</a></em> <a href="bookmark://thing">Explore the premium collection</a></p>
</td></tr></table>
</td></tr></table><br>

0 comments on commit 88c0568

Please sign in to comment.