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