diff --git a/Michelf/Markdown.php b/Michelf/Markdown.php index 088b7cdd..db955308 100644 --- a/Michelf/Markdown.php +++ b/Michelf/Markdown.php @@ -2512,21 +2512,25 @@ protected function doTables($text) { # $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) + ^ # Start of a line + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. + [|] # Optional leading pipe (present) + (.+?) # $1: Header row (at least one pipe) + (?:'.$this->id_class_attr_catch_re.')? # $2: Extra table attributes + [ ]*\n # Allowed whitespace and newline. - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - [|] ([ ]*[-:]+[-| :]*) \n # $2: Header underline + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. + [|] ([ ]*[-:]+[-| :]*) # $3: Header underline + (?:'.$this->id_class_attr_catch_re.')? # $4: Extra header row attributes + [ ]*\n # Allowed whitespace and newline. - ( # $3: Cells + ( # $5: Cells (?> - [ ]* # Allowed whitespace. - [|] .* \n # Row content. + [ ]* # Allowed whitespace. + [|] .* \n # Row content. )* ) - (?=\n|\Z) # Stop at final double newline. + (?=\n|\Z) # Stop at final double newline. }xm', array(&$this, '_doTable_leadingPipe_callback'), $text); @@ -2540,19 +2544,23 @@ protected function doTables($text) { # $text = preg_replace_callback(' { - ^ # Start of a line - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - (\S.*[|].*) \n # $1: Header row (at least one pipe) + ^ # Start of a line + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. + (\S.*[|].*?) # $1: Header row (at least one pipe) + (?:'.$this->id_class_attr_catch_re.')? # $2: Extra table attributes + [ ]*\n # Allowed whitespace and newline. - [ ]{0,'.$less_than_tab.'} # Allowed whitespace. - ([-:]+[ ]*[|][-| :]*) \n # $2: Header underline + [ ]{0,'.$less_than_tab.'} # Allowed whitespace. + ([-:]+[ ]*[|][-| :]*) # $3: Header underline + (?:'.$this->id_class_attr_catch_re.')? # $4: Extra header row attributes + [ ]*\n # Allowed whitespace and newline. - ( # $3: Cells + ( # $5: Cells (?> - .* [|] .* \n # Row content + .* [|] .* \n # Row content )* ) - (?=\n|\Z) # Stop at final double newline. + (?=\n|\Z) # Stop at final double newline. }xm', array(&$this, '_DoTable_callback'), $text); @@ -2560,13 +2568,15 @@ protected function doTables($text) { } protected function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; - $underline = $matches[2]; - $content = $matches[3]; + $tableAttrs = $matches[2]; + $underline = $matches[3]; + $headAttrs = $matches[4]; + $content = $matches[5]; # Remove leading pipe for each row. $content = preg_replace('/^ *[|]/m', '', $content); - return $this->_doTable_callback(array($matches[0], $head, $underline, $content)); + return $this->_doTable_callback(array($matches[0], $head, $tableAttrs, $underline, $headAttrs, $content)); } protected function _doTable_makeAlignAttr($alignname) { @@ -2578,9 +2588,11 @@ protected function _doTable_makeAlignAttr($alignname) } protected function _doTable_callback($matches) { $head = $matches[1]; - $underline = $matches[2]; - $content = $matches[3]; - + $tableAttrs = $matches[2]; + $underline = $matches[3]; + $headAttrs = $matches[4]; + $content = $matches[5]; + # Remove any tailing pipes for each line. $head = preg_replace('/[|] *$/m', '', $head); $underline = preg_replace('/[|] *$/m', '', $underline); @@ -2606,10 +2618,16 @@ protected function _doTable_callback($matches) { $col_count = count($headers); $attr = array_pad($attr, $col_count, ''); + # Process extra table attributes + $tableAttrStr = $this->doExtraAttributes(null, $tableAttrs); + + # Process extra header row attributes + $headAttrStr = $this->doExtraAttributes(null, $headAttrs); + # Write column headers. - $text = "
".$this->runSpanGamut(trim($header))." | \n"; $text .= "
---|
".$this->runSpanGamut(trim($cell))." | \n"; $text .= "