Skip to content

Commit

Permalink
feat: also wrap pictures in p
Browse files Browse the repository at this point in the history
  • Loading branch information
buuhuu committed Feb 13, 2024
1 parent f0bee40 commit c8f9169
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions blocks/cards/cards.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
margin: 16px;
}

.cards .cards-card-image p {
margin: 0;
}

.cards .cards-card-image {
line-height: 0;
}
Expand Down
13 changes: 6 additions & 7 deletions scripts/aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,13 @@ function decorateBlock(block) {
blockWrapper.classList.add(`${shortBlockName}-wrapper`);
const section = block.closest('.section');
if (section) section.classList.add(`${shortBlockName}-container`);
// wrap plain text and inline elements in a <p>
block.querySelectorAll(':scope > div > div').forEach((cell) => {
if (cell.textContent.trim()) {
const firstChild = cell.firstElementChild;
if (!firstChild || ['STRONG', 'EM', 'A'].includes(firstChild.tagName)) {
const p = document.createElement('p');
p.append(...cell.childNodes);
cell.replaceChildren(p);
}
const firstChild = cell.firstElementChild;
if (!firstChild || ['STRONG', 'EM', 'A', 'PICTURE'].includes(firstChild.tagName)) {
const p = document.createElement('p');
p.append(...cell.childNodes);
cell.replaceChildren(p);
}
});
}
Expand Down

0 comments on commit c8f9169

Please sign in to comment.