tdast-util-to-hast-table
tdast utility to transform tdast to a hast table node.
Install
npm install tdast-util-to-hast-table
Use
Given 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' ;
transform into a compatible hast table node:
; ;
API
toHastTable(tdast[, options])
Interface
;
Transforms a tdast Table
node into a hast table node. A summary of transformation behaviors is listed below:
hast.table
fromtdast.Table
hast.tr
fromtdast.Row
hast.th
fromtdast.Column
hast.td
fromtdast.Cell
hast.thead
from infering iftdast.Row
has column nodes, and assigns the firsthast.tr
node inhast.thead
.hast.tbody
from rendering alltdast.Row
that do not have column nodes ashast.tr
nodes inhast.tbody
.
Unist properties such as data
and position
is copied over during the transformation, which allows for useful manipulation in hast.
It is convenient to use tdastscript to create tdast trees, and tdast-util-to-hast-table
will transform them into compatible hast trees created through hastscript, as shown in the example below:
Example
;;; const tdast = ; ;
Related interfaces