Summary: Simplify Advanced Directive Syntax
Version: 2.5
Status: working but still testing
Categories: Markup Tables

This recipe does not work with PHP 5.5.0 or newer because the preg_replace e modifier is no longer supported. To fix this change the Markup function call:

        # "(?<!\\[)\\["  is a Negative Lookbehind  - so it does not interfere with links which use "[[" 
        # Negative Lookbehind - "(?<!a)b" matches b that is not preceded by a, a not part of the match
        '/(?<!\\[)\\[(table(?:end)?|caption[rlc]?|row#|row(?:end)?|![rlc]?|#[rlc]?|[rci]#[rlc]?|i[cr]#[rlc]?|r|l|c| |\\]|[^\\]]*)(\\s.*?)?\\]/i',
        "SimplifiedAdvancedTableDirectives(\$m[1], PQA(PSS(\$m[2])))"
        ) ;

Questions answered by this recipe

  • Is there an easier way to use table directives?
  • Ordinary tables allow for center, left, and right justified text, is there an easy way to do this with page directives?

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.


This recipe will make table directives much much easier to use - they will be easier to understand and typing them in will be easier. Another recipe that will enhance SimplifiedAdvancedTableDirectives SourceCodeHorizontalLines.

Table Directives code that looks like this:

(:table border=1:)
(:head align=center:)animal
(:head align=center:)food
(:cellnr align=center:)cat
(:cell align=center:)catfood
(:cellnr align=right:)bird
(:cell align=right:)birdfood

can look like this (this example uses recipe SourceCodeHorizontalLines):

[table border=1]


Copy AdvancedTableDirectives.phpΔ and SimplifiedAdvancedTableDirectives.phpΔ to your cookbook directory. (AdvancedTableDirectives is required to use this recipe).

In your config.php enter:


or in your farmconfig.php enter:



Any attributes will work within the SimplifiedAdvancedTableDirectives. Automatic zebra formatting (see FormattingTables) as well as any other table functions will work.

[table]    = (:table:)
[tableend] = (:tableend:)

[caption]  = (:caption:)
[captionc] = (:caption style="text-align:center:)
[captionr] = (:caption style="text-align:right:)
[captionl] = (:caption style="text-align:left:)

[!]        = (:head:)
[!c]       = (:head align=center:)
[!r]       = (:head align=right:)
[!l]       = (:head align=left:)

[row]      = (:row:)

[]            = (:cell:)
[ colspan=2]  = (:cell colspan=2:) <- notice space before attributes
[c]           = (:cell align=center:)
[r]           = (:cell align=right:)
[l]           = (:cell align=left:)

Cell with row number
[r#]       = (:cellr#:)
[r#c]      = (:cellr# align=center:)
[r#r]      = (:cellr# align=right:)
[r#l]      = (:cellr# align=left:)

Cell with column number
[c#]       = (:cellc#:)
[c#c]      = (:cellc# align=center:)
[c#r]      = (:cellc# align=right:)
[c#l]      = (:cellc# align=left:)
[#] [#r] [#l] [#c] (these also show a cell with column number)

Cell with auto-incrementing number - reset to 1 with new table
[i#]      = (:celli#:)
[i#c]     = (:celli# align=center:)
[i#r]     = (:celli# align=right:)
[i#l]     = (:celli# align=left:)

Cell with auto-incrementing column number - reset to 1 with new row or table
[ic#]     = (:cellic#:)
[ic#c]    = (:cellic# align=center:)
[ic#r]    = (:cellic# align=right:)
[ic#l]    = (:cellic# align=left:)

Cell with auto-incrementing row number - reset to 1 with new table
[ir#]     = (:cellir#:)
[ir#c]    = (:cellir# align=center:)
[ir#r]    = (:cellir# align=right:)
[ir#l]    = (:cellir# align=left:)

Automatic zebra formatting (mostly used for coloring) can be applied as well. In this example the table header row will have a lightblue background and the other table rows will have alternating lightgreen and lightyellow background colors.

Put into config.php:
$TableRowIndexMax = 2;
$TableRowAttrFmt  = "class='row\$TableRowIndex'" ;
$TableCellAttrFmt = "class='col\$TableCellCount'";
Put into cascading style sheet:
table th      { background-color:#99ccff; }
table tr.row1 { background-color:#ffff99 ; }
table tr.row2 { background-color:#ccffcc; }
table td      { line-height: 12px; }

For more information about formatting tables see FormattingTables.

Release Notes

  • Version 2.4 - working but still testing
  • Version 2.3 - test version
  • Version 2.2 - cleaner code, executes only for specific actions
  • Version 2.1 - small tweaks
  • Version 2 - should be much faster


Horizontal alignment of numbered rows
Normal table cells are aligned to left by default. When I want to number rows (use [row#]) then all cells are aligned to center (<tr> gets 'align=center' attribute). It means that if I want to align normal cells to the left as usual, I have to specify it explicitly. I think that <tr> should not have 'align=center' attribute and better alignment of numbered cell is right (ciphers at the same level would be in the same "column"). In HTML, instead of <tr align='center' class='rowind2'><td align='center' >1</td> it should be <tr class='rowind2'><td align='right'>1</td> Roman 2006-08-21

I will have to fix this. Thanks for finding it!
This has been fixed. This is a design change. It was trying to specify cell attributes from a row. Now they must be done separately. [row#] has been deprecated. Replace it with "[row] and [r#]". For right justification use "[row] [r#r]".

Vertical alignment
Cells of pmwiki core advanced tables are vertically aligned to top (they have valign='top' attribute). When I installed your recipe, some tables (mostly layout tables) did not look good because your advanced tables don't have valign='top'. So I had to put td { vertical-align:top; } to my CSS. If you want to be compatible with pmwiki core tables you should also add valign='top' attribute. If not, you should mention it in documentation because it affects all users who want switch to your recipe. Roman 2006-08-21

I will have to look at this further. I was more viewing it as raw tables, not necessarily to be compatible with PMWiki. I might likely do this though.
This has been updated to be compatible with PMWiki. Note that the update was in AdvancedTableDirectives which is a prerequisite for this recipe. There were recently updates to this recipe too.

Some attributes not interpreted
Some table attributes are not interpreted when put in the first position. E.g. instead of [colspan=2] I have to write [ colspan=2]. Roman 2006-08-21

A space is needed because it interprets the first "c" meaning to center. I do not know regular expressions well enough to differentiate between "[c" and "[colspan" and "c colspan". The same is true for "[r" and "[l" and "[!c" and "[!r" and "[!l" and "[!".
[row#] has been deprecated but will remain in code for backward compatibility
[rowend] has been deprecated because it is automatic

Additional table tags at end of page
When I add a table with the SATD markup, I get additional <table end> </table> tags wrapped around the last item on the page (a WikiTrail implemented through a group footer). It is fine in FF, but in IE it breaks some of the CSS attributes. If I use the (:tableend:) instead of [tableend] it is fine--no extra tags.

I could not duplicate this behavior. I would suggest you update to the latest version of AdvancedTableDirectives and SimplifiedAdvancedTableDirectives. I can see nowhere in the code this could be happening now. If the problem persists please contact me via guru [snail] gnuzoo [period] org
Updated to newest code and problem is resolved. I should have done that in the first place--I didn't realize that my files were outdated. GNUZoo rules.

Incompatible with MarkupExtensions
I'm trying to use the footnotes feature of MarkupExtensions (the [^#^] notation, explicitly), but it seems to be clashing with the [...] notations of S.A.T.D. I looked in SimpleAdvancedTableDirectives.php, and I noticed that inside [...], you seem to be checking for #, ^, or [. Why the last two, why not just check for #?

I will filter for this in the next version of SimplifiedAdvancedTableDirectives which should be out soon. BTW, the "^" character is a regular expression anchor to the beginning of the line, not to the character "^". Thanks

Clashes with use of single square-brackets elsewhere
We had/have a lot of content that uses square brackets, and SATD was replacing them with the default cell and quoted attrs stuff. There's no version number in the php source comments, so I don't know if I have the latest. Anyway, I tweaked the regex, and had a lot more success with the following...

'/(?<!\\[)\\[(table(?:end)?|caption[rlc]?|row#|row(?:end)?|![rlc]?|#[rlc]?|[rci]#[rlc]?|i[cr]#[rlc]?|r|l|c| |\\s+[^\\]]+?)?(\\s.*?)?\\]/ie'

Continued clashes with use of single square-brackets elsewhere
I'm sold on the ease of SATD tables, but found it substituting for every use of single square-brackets (e.g. busname[bitnumber]). The regex above was identical to what was already in the SATD.php code. So figuring I only needed SATD substitution at the beginning of lines, I just added a caret...

'/^(?<!\\[)\\[(table(?:end)?|caption[rlc]?|row#|row(?:end)?|![rlc]?|#[rlc]?|[rci]#[rlc]?|i[cr]#[rlc]?|r|l|c| |\\s+[^\\]]+?)?(\\s.*?)?\\]/ie'

I'm open to a less ham-fisted solution if anyone has one, but so far this simple change is allowing us to use SATD without breaking non-SATD use of single square-brackets.

See Also


User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.