Merge pull request #393 from iwill/lib

Add id and class attr for table
This commit is contained in:
Michel Fortin 2023-10-24 08:55:54 -04:00 committed by GitHub
commit 51613168d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1154,6 +1154,7 @@ class MarkdownExtra extends \Michelf\Markdown {
[|] .* \n # Row content. [|] .* \n # Row content.
)* )*
) )
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
(?=\n|\Z) # Stop at final double newline. (?=\n|\Z) # Stop at final double newline.
}xm', }xm',
array($this, '_doTable_leadingPipe_callback'), $text); array($this, '_doTable_leadingPipe_callback'), $text);
@ -1178,6 +1179,7 @@ class MarkdownExtra extends \Michelf\Markdown {
.* [|] .* \n # Row content .* [|] .* \n # Row content
)* )*
) )
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
(?=\n|\Z) # Stop at final double newline. (?=\n|\Z) # Stop at final double newline.
}xm', }xm',
array($this, '_DoTable_callback'), $text); array($this, '_DoTable_callback'), $text);
@ -1194,10 +1196,11 @@ class MarkdownExtra extends \Michelf\Markdown {
$head = $matches[1]; $head = $matches[1];
$underline = $matches[2]; $underline = $matches[2];
$content = $matches[3]; $content = $matches[3];
$id_class = $matches[4] ?? null;
$content = preg_replace('/^ *[|]/m', '', $content); $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));
} }
/** /**
@ -1223,7 +1226,8 @@ class MarkdownExtra extends \Michelf\Markdown {
$head = $matches[1]; $head = $matches[1];
$underline = $matches[2]; $underline = $matches[2];
$content = $matches[3]; $content = $matches[3];
$attr = []; $id_class = $matches[4] ?? null;
$attr = [];
// Remove any tailing pipes for each line. // Remove any tailing pipes for each line.
$head = preg_replace('/[|] *$/m', '', $head); $head = preg_replace('/[|] *$/m', '', $head);
@ -1251,7 +1255,8 @@ class MarkdownExtra extends \Michelf\Markdown {
$attr = array_pad($attr, $col_count, ''); $attr = array_pad($attr, $col_count, '');
// Write column headers. // 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 .= "<thead>\n";
$text .= "<tr>\n"; $text .= "<tr>\n";
foreach ($headers as $n => $header) { foreach ($headers as $n => $header) {