From fbc3604077334f84dc6f364266399ac17f748e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=CC=81ng?= Date: Thu, 27 Apr 2023 18:52:40 +0800 Subject: [PATCH 1/2] Add id and class attr for table. --- Michelf/MarkdownExtra.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index e620f9e..638e30d 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -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); @@ -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); @@ -1194,10 +1196,11 @@ protected function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; + $id_class = $matches[4]; $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 @@ protected function _doTable_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; - $attr = []; + $id_class = $matches[4]; + $attr = []; // Remove any tailing pipes for each line. $head = preg_replace('/[|] *$/m', '', $head); @@ -1251,7 +1255,8 @@ protected function _doTable_callback($matches) { $attr = array_pad($attr, $col_count, ''); // Write column headers. - $text = "\n"; + $table_attr_str = $this->doExtraAttributes('table', $id_class, null, []); + $text = "
\n"; $text .= "\n"; $text .= "\n"; foreach ($headers as $n => $header) { From b9604e39bdcbab223f0008c50cc9702d5a8799bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=CC=81ng?= Date: Thu, 27 Apr 2023 19:18:08 +0800 Subject: [PATCH 2/2] Try to fix unit test error. --- Michelf/MarkdownExtra.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 638e30d..f814cde 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -1196,7 +1196,7 @@ protected function _doTable_leadingPipe_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; - $id_class = $matches[4]; + $id_class = $matches[4] ?? null; $content = preg_replace('/^ *[|]/m', '', $content); @@ -1226,7 +1226,7 @@ protected function _doTable_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; - $id_class = $matches[4]; + $id_class = $matches[4] ?? null; $attr = []; // Remove any tailing pipes for each line. @@ -1256,7 +1256,7 @@ protected function _doTable_callback($matches) { // Write column headers. $table_attr_str = $this->doExtraAttributes('table', $id_class, null, []); - $text = "
\n"; + $text = "\n"; $text .= "\n"; $text .= "\n"; foreach ($headers as $n => $header) {