Skip to content

Commit

Permalink
table added
Browse files Browse the repository at this point in the history
  • Loading branch information
omprakashgupta1995 committed Oct 9, 2024
1 parent 58fad71 commit 08f5f2c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions blocks/boards/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function buildCell(rowIndex) {
}

export default async function decorate(block) {
block.classList.add('code');
block.parentElement.classList.add('code-wrapper');
const table = document.createElement('table');
const div = document.createElement('div');
const thead = document.createElement('thead');
const tbody = document.createElement('tbody');

Expand All @@ -21,15 +24,30 @@ export default async function decorate(block) {

[...block.children].forEach((child, i) => {
const row = document.createElement('tr');
if (header && i === 0) thead.append(row);
else tbody.append(row);
// if (header && i === 0) thead.append(row);
// else
tbody.append(row);
// [...child.children].forEach((col) => {
[...child.firstElementChild.firstElementChild.children].forEach((col) => {
[...child.firstElementChild?.firstElementChild?.children]?.forEach((col) => {
const cell = buildCell(header ? i : i + 1);
cell.innerHTML = col.innerHTML;
if (col.innerHTML.includes('img') && col.textContent.trim()) {
col.remove();
const p = document.createElement('p');
const span = document.createElement('span');
span.append(col.textContent.trim());
p.append(col.querySelector('img'))
p.append(span)
cell.append(p);
} else if (col.innerHTML.includes('img')) {
col.remove();
cell.append(col.querySelector('img'));
} else {
cell.innerHTML = col.innerHTML;
}
row.append(cell);
});
});
block.innerHTML = '';
block.append(table);
div.append(table);
block.append(div);
}

0 comments on commit 08f5f2c

Please sign in to comment.