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