aboutsummaryrefslogtreecommitdiff
path: root/doc/lua-filters.md
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2020-09-21 00:48:31 +0200
committerGitHub <noreply@github.com>2020-09-20 15:48:31 -0700
commitacbea6b8c610dba4b63c0f6063c51b26ab9d2b76 (patch)
tree2140ee75afafc3d87ca3d50c4cd989efec221a51 /doc/lua-filters.md
parentb2decdfd1370b5291a6c1be758d4e0bfeaf9fcc7 (diff)
downloadpandoc-acbea6b8c610dba4b63c0f6063c51b26ab9d2b76.tar.gz
Lua filters: add SimpleTable for backwards compatibility (#6575)
A new type `SimpleTable` is made available to Lua filters. It is similar to the `Table` type in pandoc versions before 2.10; conversion functions from and to the new Table type are provided. Old filters using tables now require minimal changes and can use, e.g., if PANDOC_VERSION > {2,10,1} then pandoc.Table = pandoc.SimpleTable end and function Table (tbl) tbl = pandoc.utils.to_simple_table(tbl) … return pandoc.utils.from_simple_table(tbl) end to work with the current pandoc version.
Diffstat (limited to 'doc/lua-filters.md')
-rw-r--r--doc/lua-filters.md115
1 files changed, 115 insertions, 0 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index 1cdad7391..cc728eeec 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -1744,6 +1744,36 @@ table into a List.
A pandoc log message. Objects have no fields, but can be
converted to a string via `tostring`.
+## SimpleTable {#type-simpletable}
+
+A simple table is a table structure which resembles the old (pre
+pandoc 2.10) Table type. Bi-directional conversion from and to
+[Tables](#type-table) is possible with the
+[`pandoc.utils.to_simple_table`](#pandoc.utils.to_simple_table)
+and
+[`pandoc.utils.from_simple_table`](#pandoc.utils.from_simple_table)
+function, respectively. Instances of this type can also be created
+directly with the [`pandoc.SimpleTable`](#pandoc.simpletable)
+constructor.
+
+Fields:
+
+`caption`:
+: [List] of [Inlines]
+
+`aligns`:
+: column alignments ([List] of [Alignments](#type-alignment))
+
+`widths`:
+: column widths; a ([List] of numbers)
+
+`headers`:
+: table header row ([List] of lists of [Blocks])
+
+`rows`:
+: table rows ([List] of rows, where a row is a list of lists of
+ [Blocks])
+
## Version {#type-version}
A version object. This represents a software version like
@@ -1816,6 +1846,8 @@ Usage:
[Pandoc]: #type-pandoc
[Para]: #type-para
[Rows]: #type-row
+[SimpleTable]: #type-simpletable
+[Table]: #type-table
[TableBody]: #type-tablebody
[TableFoot]: #type-tablefoot
[TableHead]: #type-tablehead
@@ -2491,6 +2523,51 @@ format, and functions to filter and modify a subtree.
Returns: [ListAttributes](#type-listattributes) object
+## Legacy types
+
+[`SimpleTable (caption, aligns, widths, headers, rows)`]{#pandoc.simpletable}
+
+: Creates a simple table resembling the old (pre pandoc 2.10)
+ table type.
+
+ Parameters:
+
+ `caption`:
+ : [List] of [Inlines]
+
+ `aligns`:
+ : column alignments ([List] of [Alignments](#type-alignment))
+
+ `widths`:
+ : column widths; a ([List] of numbers)
+
+ `headers`:
+ : table header row ([List] of lists of [Blocks])
+
+ `rows`:
+ : table rows ([List] of rows, where a row is a list of lists
+ of [Blocks])
+
+ Returns: [SimpleTable] object
+
+ Usage:
+
+ local caption = "Overview"
+ local aligns = {pandoc.AlignDefault, pandoc.AlignDefault}
+ local widths = {0, 0} -- let pandoc determine col widths
+ local headers = {"Language", "Typing"}
+ local rows = {
+ {{pandoc.Plain "Haskell"}, {pandoc.Plain "static"}},
+ {{pandoc.Plain "Lua"}, {pandoc.Plain "Dynamic"}},
+ }
+ simple_table = pandoc.SimpleTable(
+ caption,
+ aligns,
+ widths,
+ headers,
+ rows
+ )
+
## Constants
[`AuthorInText`]{#pandoc.authorintext}
@@ -2753,6 +2830,26 @@ Returns:
- Whether the two objects represent the same element (boolean)
+### from\_simple\_table {#pandoc.utils.from_simple_table}
+
+`from_simple_table (table)`
+
+Creates a [Table] block element from a [SimpleTable]. This is
+useful for dealing with legacy code which was written for pandoc
+versions older than 2.10.
+
+Returns:
+
+- table block element ([Table])
+
+Usage:
+
+ local simple = pandoc.SimpleTable(table)
+ -- modify, using pre pandoc 2.10 methods
+ simple.caption = pandoc.SmallCaps(simple.caption)
+ -- create normal table block again
+ table = pandoc.utils.from_simple_table(simple)
+
### make\_sections {#pandoc.utils.make_sections}
`make_sections (number_sections, base_level, blocks)`
@@ -2872,6 +2969,24 @@ Usage:
local pandoc_birth_year = to_roman_numeral(2006)
-- pandoc_birth_year == 'MMVI'
+### to\_simple\_table {#pandoc.utils.to_simple_table}
+
+`to_simple_table (table)`
+
+Creates a [SimpleTable] out of a [Table] block.
+
+Returns:
+
+- a simple table object ([SimpleTable])
+
+Usage:
+
+ local simple = pandoc.utils.to_simple_table(table)
+ -- modify, using pre pandoc 2.10 methods
+ simple.caption = pandoc.SmallCaps(simple.caption)
+ -- create normal table block again
+ table = pandoc.utils.from_simple_table(simple)
+
# Module pandoc.mediabag
The `pandoc.mediabag` module allows accessing pandoc's media