See here for primary reference
Try:
$ pandoc -t native
| table |
|-------|
| cell |
(Ctrl-D to send EOF)
Pandoc prints:
[Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)]
(TableHead ("",[],[])
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "table"]]]])
[(TableBody ("",[],[]) (RowHeadColumns 0)
[]
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "cell"]]]])]
(TableFoot ("",[],[])
[])]
From 2.11.4
:
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignLeft , ColWidthDefault ) ]
(TableHead
( "" , [] , [] )
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "Header" ] ]
]
])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "Cell" ] ]
]
]
]
(TableFoot ( "" , [] , [] ) [])
]
local tablex = require("pl.tablex") -- PenLight
local function debug(string)
io.stderr:write(string .. "\n")
end
- a list whose size is 2. sometimes items are named, mostly unnamed
tbl.caption
- a Pair of (List of Blocks) (aka.
long
) and (List of Inlines) (aka.short
) - Seems no
short
caption syntax available yet. it can be omitted
{
long={Para, ...}
, short={Str, ...} -- can work without this line
}
- a List of Pair of Alignment and Column width
-t native
showsColWidthDefault
which is not (yet) available for Lua filters. when a pair contains Alignments only, Pandoc considers/applies default Column width.- float value also allowed (why not!)
- "ColWidth" class exists but constructor for Lua seems not available (yet)
{
{pandoc.AlignDefault},
{pandoc.AlignLeft, 0.1},
...
}
local function merge_colspecs(colspecs, widths)
for idx, _ in ipairs(colspecs) do
table.insert(colspecs[idx], widths[idx])
end
return colspecs
end
- List of
attributes
,alignment
, number ofrow/colspan
and (List of Blocks) - no spanning syntax available yet. just set them
1
.
{
attr = { "", {}, {} }, -- not sure if pandoc.Attr() is allowed
alignment = pandoc.AlignDefault,
row_span = 1,
col_span = 1,
contents = pandoc.List({Para, ...})
}
- Pair of
attributes
and (List of Cells)
{
{"", {}, {}}, -- not sure if pandoc.Attr() is allowed
{Cell, ...}
}
- Pair of attributes and (List of Rows)
- multi-row header/footer seems allowed but (markdown) syntax seems not available (yet)
{
{"", {}, {}}, -- not sure if pandoc.Attr() is allowed
{Row, ...}
}
- List of Rows
- List of List of
attribute
,head
,body
androw_head_columns
table.bodies = { { attr = empty_attr,
head = { },
body = rows,
row_head_columns = 0 } }
- List of
caption
,colspecs
,head
,bodies
andfoot
(applies Caption, Colspec, Head, Bodies and Foot, respectively)
tbl.{attr,bodies,caption,colspecs,foot,head,tag,clone,show,walk}
- construct Table from scratch using structures above didn't work for me. instead use
pandoc.read()
to read a template table and override by your content.
local table_template = [==[
| table |
|-------|
| cell |
: caption
]==]
local my_table = pandoc.read(table_template, "markdown").blocks[1]
local table = my_table:clone()
table.head = { empty_attr, { header } }
--pretty.dump(table.head)
table.caption = { long = { pandoc.Plain(caption) } }
--pretty.dump(table.caption)
table.colspecs = tablex.zip(alignment, widths)
--pretty.dump(table.colspecs)
table.bodies = { { attr = empty_attr,
head = { },
body = rows,
row_head_columns = 0 } }
--pretty.dump(table.bodies)