Skip to content

Commit

Permalink
Merge pull request #393 from iwill/lib
Browse files Browse the repository at this point in the history
Add id and class attr for table
  • Loading branch information
michelf authored Oct 24, 2023
2 parents eb176f1 + b9604e3 commit 5161316
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Michelf/MarkdownExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ protected function doTables($text) {
[|] .* \n # Row content.
)*
)
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
(?=\n|\Z) # Stop at final double newline.
}xm',
array($this, '_doTable_leadingPipe_callback'), $text);
Expand All @@ -1178,6 +1179,7 @@ protected function doTables($text) {
.* [|] .* \n # Row content
)*
)
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
(?=\n|\Z) # Stop at final double newline.
}xm',
array($this, '_DoTable_callback'), $text);
Expand All @@ -1194,10 +1196,11 @@ protected function _doTable_leadingPipe_callback($matches) {
$head = $matches[1];
$underline = $matches[2];
$content = $matches[3];
$id_class = $matches[4] ?? null;

$content = preg_replace('/^ *[|]/m', '', $content);

return $this->_doTable_callback(array($matches[0], $head, $underline, $content));
return $this->_doTable_callback(array($matches[0], $head, $underline, $content, $id_class));
}

/**
Expand All @@ -1223,7 +1226,8 @@ protected function _doTable_callback($matches) {
$head = $matches[1];
$underline = $matches[2];
$content = $matches[3];
$attr = [];
$id_class = $matches[4] ?? null;
$attr = [];

// Remove any tailing pipes for each line.
$head = preg_replace('/[|] *$/m', '', $head);
Expand Down Expand Up @@ -1251,7 +1255,8 @@ protected function _doTable_callback($matches) {
$attr = array_pad($attr, $col_count, '');

// Write column headers.
$text = "<table>\n";
$table_attr_str = $this->doExtraAttributes('table', $id_class, null, []);
$text = "<table$table_attr_str>\n";
$text .= "<thead>\n";
$text .= "<tr>\n";
foreach ($headers as $n => $header) {
Expand Down

0 comments on commit 5161316

Please sign in to comment.