ImprovedTableParser

Annotated pages/HelpOnImprovedTableParser

46:b81620a4d583
2020-02-16 Paul Boddie Fixed handling of boolean attributes presented inadvertently to the formatter.
paul@23 1
#format wiki
paul@23 2
#language en
paul@23 3
paul@23 4
== ImprovedTableParser ==
paul@23 5
paul@23 6
The !ImprovedTableParser extension for !MoinMoin offers support for an alternative table syntax that is not as restrictive as the [[HelpOnTables|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.
paul@23 7
paul@23 8
=== The Improved Table Syntax ===
paul@23 9
paul@23 10
The principal syntax rules are described as follows.
paul@23 11
paul@23 12
==== Making a Table ====
paul@23 13
paul@23 14
To make a table, make a [[HelpOnParsers|section]] and use a `#!table` declaration to indicate that it represents a table:
paul@23 15
paul@23 16
{{{{
paul@23 17
{{{#!table
paul@23 18
...
paul@23 19
}}}
paul@23 20
}}}}
paul@23 21
paul@23 22
The result:
paul@23 23
paul@23 24
{{{#!table
paul@23 25
...
paul@23 26
}}}
paul@23 27
paul@23 28
==== Adding Rows ====
paul@23 29
paul@23 30
Rows are separated using the `==` marker at the start of a line. Starting a new line does not by itself start a new row:
paul@23 31
paul@23 32
{{{{
paul@23 33
{{{#!table
paul@23 34
Row #1
paul@23 35
and still row #1
paul@23 36
==
paul@23 37
Row #2
paul@23 38
}}}
paul@23 39
}}}}
paul@23 40
paul@23 41
The result:
paul@23 42
paul@23 43
{{{#!table
paul@23 44
Row #1
paul@23 45
and still row #1
paul@23 46
==
paul@23 47
Row #2
paul@23 48
}}}
paul@23 49
paul@23 50
==== Adding Columns ====
paul@23 51
paul@23 52
Columns are separated using the `||` marker:
paul@23 53
paul@23 54
{{{{
paul@23 55
{{{#!table
paul@23 56
Column #1 || Column #2
paul@23 57
}}}
paul@23 58
}}}}
paul@23 59
paul@23 60
The result:
paul@23 61
paul@23 62
{{{#!table
paul@23 63
Column #1 || Column #2
paul@23 64
}}}
paul@23 65
paul@23 66
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:
paul@23 67
paul@23 68
{{{{
paul@23 69
{{{#!table
paul@23 70
Already in column #1
paul@23 71
|| Now in column #2
paul@24 72
until the next row or the end of the table
paul@23 73
}}}
paul@23 74
}}}}
paul@23 75
paul@23 76
The result:
paul@23 77
paul@23 78
{{{#!table
paul@23 79
Already in column #1
paul@23 80
|| Now in column #2
paul@23 81
until the next row or the end of the table
paul@23 82
}}}
paul@23 83
paul@33 84
==== Indented Column Text and Line Continuation ====
paul@33 85
paul@32 86
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:
paul@32 87
paul@33 88
{{{{
paul@33 89
{{{#!table
paul@33 90
First column || Second column
paul@33 91
                ...this should be part of the same paragraph,
paul@33 92
                but isn't until now.
paul@33 93
}}}
paul@33 94
}}}}
paul@33 95
paul@33 96
The result is as follows:
paul@33 97
paul@32 98
{{{#!table
paul@32 99
First column || Second column
paul@33 100
                ...this should be part of the same paragraph,
paul@33 101
                but isn't until now.
paul@32 102
}}}
paul@32 103
paul@33 104
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.
paul@33 105
paul@33 106
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:
paul@33 107
paul@33 108
{{{{
paul@33 109
{{{#!table
paul@33 110
First column || Second column
paul@33 111
             .. ...this should be part of the same paragraph, and it now is,
paul@33 112
             .. as is this text.
paul@33 113
}}}
paul@33 114
}}}}
paul@33 115
paul@33 116
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.
paul@33 117
paul@33 118
The result is this:
paul@32 119
paul@32 120
{{{#!table
paul@32 121
First column || Second column
paul@33 122
             .. ...this should be part of the same paragraph, and it now is,
paul@33 123
             .. as is this text.
paul@32 124
}}}
paul@32 125
paul@23 126
==== Styles and Formatting ====
paul@23 127
paul@23 128
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 [[HelpOnTables|default syntax for tables]] being supported.
paul@23 129
paul@23 130
Table-specific options are prefixed with `table` (`tablestyle` and `tableclass` apply to the given table):
paul@23 131
paul@23 132
{{{{
paul@23 133
{{{#!table
paul@23 134
<tablestyle="width: 80%"> '''Heading'''
paul@23 135
==
paul@23 136
Data
paul@23 137
}}}
paul@23 138
}}}}
paul@23 139
paul@23 140
The result:
paul@23 141
paul@23 142
{{{#!table
paul@23 143
<tablestyle="width: 80%"> '''Heading'''
paul@23 144
==
paul@23 145
Data
paul@23 146
}}}
paul@23 147
paul@23 148
Row-specific options are prefixed with `row` (`rowstyle` and `rowclass` apply to the given row):
paul@23 149
paul@23 150
{{{{
paul@23 151
{{{#!table
paul@23 152
<rowstyle="background-color: #f99"> Red cell
paul@23 153
==
paul@23 154
<rowstyle="background-color: #9f9"> Green cell
paul@23 155
}}}
paul@23 156
}}}}
paul@23 157
paul@23 158
The result:
paul@23 159
paul@23 160
{{{#!table
paul@23 161
<rowstyle="background-color: #f99"> Red cell
paul@23 162
==
paul@23 163
<rowstyle="background-color: #9f9"> Green cell
paul@23 164
}}}
paul@23 165
paul@23 166
General options are given verbatim (`style`, `class`, `rowspan`, `colspan`).
paul@23 167
paul@23 168
{{{{
paul@23 169
{{{#!table
paul@23 170
<style="background-color: #f99"> Red cell || <rowspan=2 style="background-color: #99f"> Shared cell
paul@23 171
==
paul@23 172
<style="background-color: #9f9"> Green cell
paul@23 173
}}}
paul@23 174
}}}}
paul@23 175
paul@23 176
The result:
paul@23 177
paul@23 178
{{{#!table
paul@23 179
<style="background-color: #f99"> Red cell || <rowspan=2 style="background-color: #99f"> Shared cell
paul@23 180
==
paul@23 181
<style="background-color: #9f9"> Green cell
paul@23 182
}}}
paul@23 183
paul@23 184
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.
paul@23 185
paul@23 186
=== A Simple Example ===
paul@23 187
paul@23 188
Here is a short example of a table using the features described above:
paul@23 189
paul@23 190
{{{{
paul@23 191
{{{#!table
paul@23 192
<tablestyle="width:80%" style="text-align:center" colspan=3> '''Heading'''
paul@23 193
==
paul@23 194
cell 1 || cell 2 || cell 3
paul@23 195
==
paul@23 196
<rowspan=2> spanning rows
paul@23 197
|| <colspan=2 style="background-color: #E0E0FF;"> spanning 2 columns
paul@23 198
==
paul@23 199
<rowstyle="background-color: #FFFFE0;"> cell 2 || cell 3
paul@23 200
}}}
paul@23 201
}}}}
paul@23 202
paul@23 203
And here is the result:
paul@23 204
paul@23 205
{{{#!table
paul@23 206
<tablestyle="width:80%" style="text-align:center" colspan=3> '''Heading'''
paul@23 207
==
paul@23 208
cell 1 || cell 2 || cell 3
paul@23 209
==
paul@23 210
<rowspan=2> spanning rows
paul@23 211
|| <colspan=2 style="background-color: #E0E0FF;"> spanning 2 columns
paul@23 212
==
paul@23 213
<rowstyle="background-color: #FFFFE0;"> cell 2 || cell 3
paul@23 214
}}}
paul@23 215
paul@23 216
=== An Advanced Example ===
paul@23 217
paul@23 218
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:
paul@23 219
paul@23 220
{{{{
paul@23 221
{{{#!table
paul@23 222
== Proper Heading! ==
paul@23 223
||
paul@23 224
== Another Heading! ==
paul@23 225
==
paul@23 226
 * First
paul@23 227
 * Second
paul@23 228
 * Third
paul@23 229
||
paul@23 230
 * Gold
paul@23 231
 * Silver
paul@23 232
 * Bronze
paul@23 233
}}}
paul@23 234
}}}}
paul@23 235
paul@23 236
The result:
paul@23 237
paul@23 238
{{{#!table
paul@23 239
== Proper Heading! ==
paul@23 240
||
paul@23 241
== Another Heading! ==
paul@23 242
==
paul@23 243
 * First
paul@23 244
 * Second
paul@23 245
 * Third
paul@23 246
||
paul@23 247
 * Gold
paul@23 248
 * Silver
paul@23 249
 * Bronze
paul@23 250
}}}
paul@23 251
paul@23 252
Note that the usual restrictions around these features still apply, so headings, for example, must appear on a separate line.
paul@23 253
paul@23 254
=== A More Advanced Example ===
paul@23 255
paul@23 256
Consider the following table:
paul@23 257
paul@23 258
||<rowstyle="background-color: #7f7"> System || RAM || RAM<<BR>>(official expansion limit) || ROM || Year of introduction || Price on introduction (GBP) ||
paul@23 259
|| BBC Microcomputer Model B ||<colspan="2"> 32K || 32K || 1981 || 335 ||
paul@23 260
|| Acorn Electron ||<colspan="2"> 32K || 32K || 1983 || 199 ||
paul@23 261
|| Commodore 64 ||<colspan="2"> 64K || 20K ||<rowspan=2> 1982 || 399 ||
paul@23 262
|| Sinclair ZX Spectrum 48K ||<colspan="2"> 48K || 16K || 175 ||
paul@23 263
|| Amstrad CPC464 ||<colspan="2"> 64K || 32K || 1984 || 249 (green screen), 349 (colour) ||
paul@23 264
|| Amstrad CPC6128 ||<colspan="2"> 128K || 48K || 1985 || 299 (colour) ||
paul@23 265
|| Sinclair ZX81 || 1K || 16K || 8K || 1981 || 70 (assembled), 50 (kit) ||
paul@45 266
|| VIC-20 || 5K || 32K || 16K || 1980 || 199 ||
paul@23 267
paul@23 268
Here is how it is written in the default table syntax:
paul@23 269
paul@23 270
{{{
paul@23 271
||<rowstyle="background-color: #7f7"> System || RAM || RAM<<BR>>(official expansion limit) || ROM || Year of introduction || Price on introduction (GBP) ||
paul@23 272
|| BBC Microcomputer Model B ||<colspan="2"> 32K || 32K || 1981 || 335 ||
paul@23 273
|| Acorn Electron ||<colspan="2"> 32K || 32K || 1983 || 199 ||
paul@23 274
|| Commodore 64 ||<colspan="2"> 64K || 20K ||<rowspan=2> 1982 || 399 ||
paul@23 275
|| Sinclair ZX Spectrum 48K ||<colspan="2"> 48K || 16K || 175 ||
paul@23 276
|| Amstrad CPC464 ||<colspan="2"> 64K || 32K || 1984 || 249 (green screen), 349 (colour) ||
paul@23 277
|| Amstrad CPC6128 ||<colspan="2"> 128K || 48K || 1985 || 299 (colour) ||
paul@23 278
|| Sinclair ZX81 || 1K || 16K || 8K || 1981 || 70 (assembled), 50 (kit) ||
paul@45 279
|| VIC-20 || 5K || 32K || 16K || 1980 || 199 ||
paul@23 280
}}}
paul@23 281
paul@23 282
Although the lines are not too long, it is somewhat difficult to interpret and edit the text.
paul@23 283
paul@24 284
Here is how the above table can be written in the improved syntax:
paul@23 285
paul@23 286
{{{{
paul@23 287
{{{#!table
paul@23 288
<rowstyle="background-color: #7f7"> System
paul@23 289
|| RAM
paul@23 290
|| RAM<<BR>>(official expansion limit)
paul@23 291
|| ROM
paul@23 292
|| Year of introduction
paul@23 293
|| Price on introduction (GBP)
paul@23 294
==
paul@23 295
BBC Microcomputer Model B
paul@23 296
||<colspan="2"> 32K
paul@23 297
|| 32K
paul@23 298
|| 1981
paul@23 299
|| 335
paul@23 300
==
paul@23 301
Acorn Electron
paul@23 302
||<colspan="2"> 32K
paul@23 303
|| 32K
paul@23 304
|| 1983
paul@23 305
|| 199
paul@23 306
==
paul@23 307
Commodore 64
paul@23 308
||<colspan="2"> 64K
paul@23 309
|| 20K
paul@23 310
||<rowspan=2> 1982
paul@23 311
|| 399
paul@23 312
==
paul@23 313
Sinclair ZX Spectrum 48K
paul@23 314
||<colspan="2"> 48K
paul@23 315
|| 16K
paul@23 316
|| 175
paul@23 317
==
paul@23 318
Amstrad CPC464
paul@23 319
||<colspan="2"> 64K
paul@23 320
|| 32K
paul@23 321
|| 1984
paul@23 322
|| 249 (green screen), 349 (colour)
paul@23 323
==
paul@23 324
Amstrad CPC6128
paul@23 325
||<colspan="2"> 128K
paul@23 326
|| 48K
paul@23 327
|| 1985
paul@23 328
|| 299 (colour)
paul@23 329
==
paul@23 330
Sinclair ZX81 || 1K || 16K || 8K || 1981
paul@23 331
|| 70 (assembled), 50 (kit)
paul@23 332
==
paul@23 333
VIC-20 || 5K || 32K || 16K || 1980
paul@45 334
|| 199
paul@23 335
}}}
paul@23 336
}}}}
paul@23 337
paul@23 338
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:
paul@23 339
paul@23 340
{{{#!table
paul@23 341
<rowstyle="background-color: #7f7"> System
paul@23 342
|| RAM
paul@23 343
|| RAM<<BR>>(official expansion limit)
paul@23 344
|| ROM
paul@23 345
|| Year of introduction
paul@23 346
|| Price on introduction (GBP)
paul@23 347
==
paul@23 348
BBC Microcomputer Model B
paul@23 349
||<colspan="2"> 32K
paul@23 350
|| 32K
paul@23 351
|| 1981
paul@23 352
|| 335
paul@23 353
==
paul@23 354
Acorn Electron
paul@23 355
||<colspan="2"> 32K
paul@23 356
|| 32K
paul@23 357
|| 1983
paul@23 358
|| 199
paul@23 359
==
paul@23 360
Commodore 64
paul@23 361
||<colspan="2"> 64K
paul@23 362
|| 20K
paul@23 363
||<rowspan=2> 1982
paul@23 364
|| 399
paul@23 365
==
paul@23 366
Sinclair ZX Spectrum 48K
paul@23 367
||<colspan="2"> 48K
paul@23 368
|| 16K
paul@23 369
|| 175
paul@23 370
==
paul@23 371
Amstrad CPC464
paul@23 372
||<colspan="2"> 64K
paul@23 373
|| 32K
paul@23 374
|| 1984
paul@23 375
|| 249 (green screen), 349 (colour)
paul@23 376
==
paul@23 377
Amstrad CPC6128
paul@23 378
||<colspan="2"> 128K
paul@23 379
|| 48K
paul@23 380
|| 1985
paul@23 381
|| 299 (colour)
paul@23 382
==
paul@23 383
Sinclair ZX81 || 1K || 16K || 8K || 1981
paul@23 384
|| 70 (assembled), 50 (kit)
paul@23 385
==
paul@23 386
VIC-20 || 5K || 32K || 16K || 1980
paul@45 387
|| 199
paul@23 388
}}}
paul@23 389
paul@23 390
=== Adding Table Sorting ===
paul@23 391
paul@23 392
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.
paul@23 393
paul@23 394
 headers:: indicates the number of rows which are headers, describing non-sortable data
paul@24 395
 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
paul@23 396
 sortcolumns:: describes the initial sorting or ordering of the table data; the syntax is the same as `columntypes`
paul@23 397
 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
paul@23 398
paul@23 399
To the above table, we can change the declaration as follows:
paul@23 400
paul@23 401
{{{{
paul@23 402
{{{#!table headers=1 columntypes='2n,1nd,0,3n,4n,5n' sortcolumns='4n' name=computers
paul@23 403
}}}}
paul@23 404
paul@23 405
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.
paul@23 406
paul@23 407
The result is as follows:
paul@23 408
paul@23 409
{{{#!table headers=1 columntypes='2n,1nd,0,3n,4n,5n' sortcolumns='4n' name=computers
paul@23 410
<rowstyle="background-color: #7f7"> System
paul@23 411
|| RAM
paul@23 412
|| RAM<<BR>>(official expansion limit)
paul@23 413
|| ROM
paul@23 414
|| Year of introduction
paul@23 415
|| Price on introduction (GBP)
paul@23 416
==
paul@23 417
BBC Microcomputer Model B
paul@23 418
||<colspan="2"> 32K
paul@23 419
|| 32K
paul@23 420
|| 1981
paul@23 421
|| 335
paul@23 422
==
paul@23 423
Acorn Electron
paul@23 424
||<colspan="2"> 32K
paul@23 425
|| 32K
paul@23 426
|| 1983
paul@23 427
|| 199
paul@23 428
==
paul@23 429
Commodore 64
paul@23 430
||<colspan="2"> 64K
paul@23 431
|| 20K
paul@23 432
||<rowspan=2> 1982
paul@23 433
|| 399
paul@23 434
==
paul@23 435
Sinclair ZX Spectrum 48K
paul@23 436
||<colspan="2"> 48K
paul@23 437
|| 16K
paul@23 438
|| 175
paul@23 439
==
paul@23 440
Amstrad CPC464
paul@23 441
||<colspan="2"> 64K
paul@23 442
|| 32K
paul@23 443
|| 1984
paul@23 444
|| 249 (green screen), 349 (colour)
paul@23 445
==
paul@23 446
Amstrad CPC6128
paul@23 447
||<colspan="2"> 128K
paul@23 448
|| 48K
paul@23 449
|| 1985
paul@23 450
|| 299 (colour)
paul@23 451
==
paul@23 452
Sinclair ZX81 || 1K || 16K || 8K || 1981
paul@23 453
|| 70 (assembled), 50 (kit)
paul@23 454
==
paul@23 455
VIC-20 || 5K || 32K || 16K || 1980
paul@45 456
|| 199
paul@23 457
}}}
paul@23 458
paul@23 459
By pointing to the header cells, a pop-up dialogue allows the sorting criteria to be edited.
paul@23 460
paul@23 461
 * Where a column is already being used to sort the data, it will appear in the list of sort columns.
paul@23 462
 * 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.)
paul@23 463
 * 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.
paul@23 464
 * The sort direction for a column can be changed by selecting the highlighted arrow next to its name.