Skip to content

Commit

Permalink
feat(markdown): refacto table thead tbody
Browse files Browse the repository at this point in the history
  • Loading branch information
zellerbaptiste committed Dec 10, 2024
1 parent db34d21 commit e4acbe6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/dsfr-doc-publisher/src/node/gfm/table-cell-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Node } from '../node.js';

class TableCellNode extends Node {
constructor (data) {
const level = data?.level === 'thead' ? 'th' : 'td';
super(data, level);
const tagName = data?.isThead ? 'th' : 'td';
super(data, tagName);
if (this.data?.align !== 'left') this.attributes.addClass(`fr-cell--${this.data.align}`);
}
}
Expand Down
14 changes: 13 additions & 1 deletion packages/dsfr-doc-publisher/src/node/gfm/table-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ class TableNode extends Node {
constructor (data) {
data.children = data.children.map((child, index) => ({
...child,
level: index === 0 ? 'thead' : undefined,
isThead: index === 0,
align: data?.align || null
}));
super(data, `table`);
}

async renderChildren () {
if (!this._children.length) return;

let html = `<thead>${await this._children[0].render()}</thead>`;
html += `<tbody>`;
for (const child of this._children.slice(1)) {
html += await child.render();
}
html += `</tbody>`;
return html;
}

async render () {
return `
<div class="fr-table">
Expand Down
2 changes: 1 addition & 1 deletion packages/dsfr-doc-publisher/src/node/gfm/table-row-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TableRowNode extends Node {
constructor (data) {
data.children = data.children.map((child, index) => ({
...child,
level: data.level || undefined,
isThead: data.isThead,
align: data?.align ? data.align[index] : null
}));
super(data, `tr`);
Expand Down
7 changes: 6 additions & 1 deletion packages/dsfr-doc-publisher/src/node/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ class Node extends Renderable {
return descendants;
}

async render () {
async renderChildren () {
let html = '';
for (const child of this._children) {
html += await child.render();
}
return html;
}

async render () {
const html = await this.renderChildren();

if (!this.tagName) return html;

Expand Down

0 comments on commit e4acbe6

Please sign in to comment.