protected function doTables($text)
{
#
# Form HTML tables.
#
$less_than_tab = $this->tab_width - 1;
#
# Find tables with leading pipe.
#
# | Header 1 | Header 2
# | -------- | --------
# | Cell 1 | Cell 2
# | Cell 3 | Cell 4
#
$text = preg_replace_callback('
{
^ # Start of a line
[ ]{0,' . $less_than_tab . '} # Allowed whitespace.
[|] # Optional leading pipe (present)
(.+) \\n # $1: Header row (at least one pipe)
[ ]{0,' . $less_than_tab . '} # Allowed whitespace.
[|] ([ ]*[-:]+[-| :]*) \\n # $2: Header underline
( # $3: Cells
(?>
[ ]* # Allowed whitespace.
[|] .* \\n # Row content.
)*
)
(?=\\n|\\Z) # Stop at final double newline.
}xm', array($this, '_doTable_leadingPipe_callback'), $text);
#
# Find tables without leading pipe.
#
# Header 1 | Header 2
# -------- | --------
# Cell 1 | Cell 2
# Cell 3 | Cell 4
#
$text = preg_replace_callback('
{
^ # Start of a line
[ ]{0,' . $less_than_tab . '} # Allowed whitespace.
(\\S.*[|].*) \\n # $1: Header row (at least one pipe)
[ ]{0,' . $less_than_tab . '} # Allowed whitespace.
([-:]+[ ]*[|][-| :]*) \\n # $2: Header underline
( # $3: Cells
(?>
.* [|] .* \\n # Row content
)*
)
(?=\\n|\\Z) # Stop at final double newline.
}xm', array($this, '_DoTable_callback'), $text);
return $text;
}