tdast-util-to-html-table
tdast utility to serialize tdast to html table.
Install
npm install tdast-util-to-html-table
Use
Use with a tdast table node,
; const tdast = type: 'table' children: type: 'row' index: 0 children: type: 'column' index: 0 value: 'col0' type: 'column' index: 1 value: 'col1' type: 'column' index: 2 value: 'col2' type: 'row' index: 1 children: type: 'cell' columnIndex: 0 rowIndex: 1 value: 'row1col0' type: 'cell' columnIndex: 1 rowIndex: 1 value: 'row1col1' type: 'cell' columnIndex: 2 rowIndex: 1 value: 'row1col2' type: 'row' index: 2 children: type: 'cell' columnIndex: 0 rowIndex: 2 value: 'row2col0' type: 'cell' columnIndex: 1 rowIndex: 2 value: 'row2col1' type: 'cell' columnIndex: 2 rowIndex: 2 value: 'row2col2' ; console;
yields a serialized HTML table.
col0col1col2row1col0row1col1row1col2row2col0row2col1row2col2
Easily use this HTML table with any HTML content!
API
toHtmlTable(tdast[, options])
Interface
;
Serializes a tdast Table
node into a HTML table.
Uses tdast-util-to-hast-table
under the hood to transform the tdast Table
node into a hast table node, then applies hast-util-to-html
to serialize the hast node into a HTML string.
The HTML table is created with semantic table
, thead
, tbody
, tr
, th
, td
elements For more details, please refer to tdast-util-to-hast-table
for behaviors of transformed nodes.
It is convenient to use tdastscript
to create tdast trees, and the serialized HTML of tdast-util-to-html-table
is compatible with similar hast trees created via hastscript
, as shown in the example below:
Example
;;;; const tdast = ; const hast = ; const tdastHtml = ;const hastHtml = ; ;
Related interfaces