ImprovedTableParser
The ImprovedTableParser extension for MoinMoin offers support for an alternative table syntax that is not as restrictive as the default syntax for tables in terms of the way tables are written as Wiki text, and in terms of the formatting possibilities available. For example, the default syntax insists that table rows are written on a single line - this can be challenging for rows with many columns or containing a lot of content - whereas the improved syntax allows each column to appear on one or many lines.
The Improved Table Syntax
The principal syntax rules are described as follows.
Making a Table
To make a table, make a section and use a #!table declaration to indicate that it represents a table:
{{{#!table ... }}}
The result:
... |
Adding Rows
Rows are separated using the == marker at the start of a line. Starting a new line does not by itself start a new row:
{{{#!table Row #1 and still row #1 == Row #2 }}}
The result:
Row #1 and still row #1 |
Row #2 |
Adding Columns
Columns are separated using the || marker:
{{{#!table Column #1 || Column #2 }}}
The result:
Column #1 | Column #2 |
Since there is no need to indicate the start of a table or of a row, since tables are confined to sections and rows are explicitly separated, the initial and final || markers are not used:
{{{#!table Already in column #1 || Now in column #2 until the next row or the end of the table }}}
The result:
Already in column #1 | Now in column #2 until the next row or the end of the table |
Indented Column Text and Line Continuation
Sometimes it can be convenient to present a table in a formatted fashion, with alignment of column content even when viewed as plain text. However, this can present problems with indentation:
{{{#!table First column || Second column ...this should be part of the same paragraph, but isn't until now. }}}
The result is as follows:
First column | Second column
|
Note how MoinMoin lost one of the dots on the second line of the second column's text. This is a feature of the Wiki text parser.
To achieve the desired effect, a line continuation syntax is available that prevents MoinMoin from treating the second and subsequent lines as indented paragraph text:
{{{#!table First column || Second column .. ...this should be part of the same paragraph, and it now is, .. as is this text. }}}
Note that the .. marker must be the first non-space characters on a line: it is not a column separator, and does not therefore provide a way of writing column content side by side.
The result is this:
First column | Second column ...this should be part of the same paragraph, and it now is, as is this text. |
Styles and Formatting
Style and formatting options are placed at the start of a row or column inside < and > markers, with the options corresponding to HTML attributes as described for the default syntax for tables being supported.
Table-specific options are prefixed with table (tablestyle and tableclass apply to the given table):
{{{#!table <tablestyle="width: 80%"> '''Heading''' == Data }}}
The result:
Heading |
Data |
Row-specific options are prefixed with row (rowstyle and rowclass apply to the given row):
{{{#!table <rowstyle="background-color: #f99"> Red cell == <rowstyle="background-color: #9f9"> Green cell }}}
The result:
Red cell |
Green cell |
General options are given verbatim (style, class, rowspan, colspan).
{{{#!table <style="background-color: #f99"> Red cell || <rowspan=2 style="background-color: #99f"> Shared cell == <style="background-color: #9f9"> Green cell }}}
The result:
Red cell | Shared cell |
Green cell |
Note that the short options in the default syntax are not supported. It is therefore necessary to write span and justification attributes out in full.
A Simple Example
Here is a short example of a table using the features described above:
{{{#!table <tablestyle="width:80%" style="text-align:center" colspan=3> '''Heading''' == cell 1 || cell 2 || cell 3 == <rowspan=2> spanning rows || <colspan=2 style="background-color: #E0E0FF;"> spanning 2 columns == <rowstyle="background-color: #FFFFE0;"> cell 2 || cell 3 }}}
And here is the result:
Heading | ||
cell 1 | cell 2 | cell 3 |
spanning rows | spanning 2 columns | |
cell 2 | cell 3 |
An Advanced Example
Since table cells can be described on more than one line, a wider range of Wiki syntax can be used to populate tables. For example, headings and lists can be added to tables:
{{{#!table == Proper Heading! == || == Another Heading! == == * First * Second * Third || * Gold * Silver * Bronze }}}
The result:
Proper Heading! |
Another Heading! |
|
|
Note that the usual restrictions around these features still apply, so headings, for example, must appear on a separate line.
A More Advanced Example
Consider the following table:
System |
RAM |
RAM |
ROM |
Year of introduction |
Price on introduction (GBP) |
BBC Microcomputer Model B |
32K |
32K |
1981 |
335 |
|
Acorn Electron |
32K |
32K |
1983 |
199 |
|
Commodore 64 |
64K |
20K |
1982 |
399 |
|
Sinclair ZX Spectrum 48K |
48K |
16K |
175 |
||
Amstrad CPC464 |
64K |
32K |
1984 |
249 (green screen), 349 (colour) |
|
Amstrad CPC6128 |
128K |
48K |
1985 |
299 (colour) |
|
Sinclair ZX81 |
1K |
16K |
8K |
1981 |
70 (assembled), 50 (kit) |
VIC-20 |
5K |
32K |
16K |
1980 |
200 (estimated) |
Here is how it is written in the default table syntax:
||<rowstyle="background-color: #7f7;"> System || RAM || RAM<<BR>>(official expansion limit) || ROM || Year of introduction || Price on introduction (GBP) || || BBC Microcomputer Model B ||<colspan=2> 32K || 32K || 1981 || 335 || || Acorn Electron ||<colspan=2> 32K || 32K || 1983 || 199 || || Commodore 64 ||<colspan=2> 64K || 20K ||<rowspan=2> 1982 || 399 || || Sinclair ZX Spectrum 48K ||<colspan=2> 48K || 16K || 175 || || Amstrad CPC464 ||<colspan=2> 64K || 32K || 1984 || 249 (green screen), 349 (colour) || || Amstrad CPC6128 ||<colspan=2> 128K || 48K || 1985 || 299 (colour) || || Sinclair ZX81 || 1K || 16K || 8K || 1981 || 70 (assembled), 50 (kit) || || VIC-20 || 5K || 32K || 16K || 1980 || 200 (estimated) ||
Although the lines are not too long, it is somewhat difficult to interpret and edit the text.
Here is how the above table can be written in the improved syntax:
{{{#!table <rowstyle="background-color: #7f7"> System || RAM || RAM<<BR>>(official expansion limit) || ROM || Year of introduction || Price on introduction (GBP) == BBC Microcomputer Model B ||<colspan="2"> 32K || 32K || 1981 || 335 == Acorn Electron ||<colspan="2"> 32K || 32K || 1983 || 199 == Commodore 64 ||<colspan="2"> 64K || 20K ||<rowspan=2> 1982 || 399 == Sinclair ZX Spectrum 48K ||<colspan="2"> 48K || 16K || 175 == Amstrad CPC464 ||<colspan="2"> 64K || 32K || 1984 || 249 (green screen), 349 (colour) == Amstrad CPC6128 ||<colspan="2"> 128K || 48K || 1985 || 299 (colour) == Sinclair ZX81 || 1K || 16K || 8K || 1981 || 70 (assembled), 50 (kit) == VIC-20 || 5K || 32K || 16K || 1980 || 200 (estimated) }}}
Without the restriction of putting everything in a row on one line, the table can be written in a way that is as concise or as verbose as you like. Here is the result:
System | RAM | RAM (official expansion limit) |
ROM | Year of introduction | Price on introduction (GBP) |
BBC Microcomputer Model B | 32K | 32K | 1981 | 335 | |
Acorn Electron | 32K | 32K | 1983 | 199 | |
Commodore 64 | 64K | 20K | 1982 | 399 | |
Sinclair ZX Spectrum 48K | 48K | 16K | 175 | ||
Amstrad CPC464 | 64K | 32K | 1984 | 249 (green screen), 349 (colour) | |
Amstrad CPC6128 | 128K | 48K | 1985 | 299 (colour) | |
Sinclair ZX81 | 1K | 16K | 8K | 1981 | 70 (assembled), 50 (kit) |
VIC-20 | 5K | 32K | 16K | 1980 | 200 (estimated) |
Adding Table Sorting
In addition to a more flexible syntax, ImprovedTableParser also allows the contents of tables to be described so that they can be manipulated and shown according to different sorting or ordering criteria. This is done by adding some directives to the table declaration.
- headers
- indicates the number of rows which are headers, describing non-sortable data
- columntypes
describes the kind of data in each column along with how the column data should be ordered (ascending or descending) by default if chosen as a sort column; the syntax is reminiscent of the Unix sort utility, but column numbering starts at 0 instead of 1
- sortcolumns
describes the initial sorting or ordering of the table data; the syntax is the same as columntypes
- name
the HTML id attribute or anchor given to the table so that when the ordering is changed, the browser will refresh the page and can jump to the table's position
To the above table, we can change the declaration as follows:
{{{#!table headers=1 columntypes='2n,1nd,0,3n,4n,5n' sortcolumns='4n' name=computers
This indicates that the first row is not sortable data (headers=1), that the column types for all but the first column (0) are numeric (n) and that the second column (1) should be presented in descending order by default (d), that the initial view will sort the data according to the fifth column (4) by treating its cells as if they provide numeric data. Finally, the table has an anchor called computers associated with it.
The result is as follows:
Amstrad CPC6128 | 128K | 48K | 1985 | 299 (colour) | |
Amstrad CPC464 | 64K | 32K | 1984 | 249 (green screen), 349 (colour) | |
Acorn Electron | 32K | 32K | 1983 | 199 | |
Sinclair ZX Spectrum 48K | 48K | 16K | 1982 | 175 | |
Commodore 64 | 64K | 20K | 1982 | 399 | |
Sinclair ZX81 | 1K | 16K | 8K | 1981 | 70 (assembled), 50 (kit) |
BBC Microcomputer Model B | 32K | 32K | 1981 | 335 | |
VIC-20 | 5K | 32K | 16K | 1980 | 200 (estimated) |
By pointing to the header cells, a pop-up dialogue allows the sorting criteria to be edited.
- Where a column is already being used to sort the data, it will appear in the list of sort columns.
- By opening the dialogue over a sort column, the column can be removed from the criteria by selecting it in the list. (It will appear crossed out when pointed to.)
- A column can be moved or inserted into the criteria by pointing to another column or the space at the end of the list. The column should appear at its new position and can be inserted by selecting the region next to which (or within which) the new column appears, or by selecting the arrows in the new column indicator.
- The sort direction for a column can be changed by selecting the highlighted arrow next to its name.