Skip to content

Commit 5161316

Browse files
authored
Merge pull request #393 from iwill/lib
Add id and class attr for table
2 parents eb176f1 + b9604e3 commit 5161316

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Michelf/MarkdownExtra.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ protected function doTables($text) {
11541154
[|] .* \n # Row content.
11551155
)*
11561156
)
1157+
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
11571158
(?=\n|\Z) # Stop at final double newline.
11581159
}xm',
11591160
array($this, '_doTable_leadingPipe_callback'), $text);
@@ -1178,6 +1179,7 @@ protected function doTables($text) {
11781179
.* [|] .* \n # Row content
11791180
)*
11801181
)
1182+
('.$this->id_class_attr_catch_re.')? # $4 = id/class attributes
11811183
(?=\n|\Z) # Stop at final double newline.
11821184
}xm',
11831185
array($this, '_DoTable_callback'), $text);
@@ -1194,10 +1196,11 @@ protected function _doTable_leadingPipe_callback($matches) {
11941196
$head = $matches[1];
11951197
$underline = $matches[2];
11961198
$content = $matches[3];
1199+
$id_class = $matches[4] ?? null;
11971200

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

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

12031206
/**
@@ -1223,7 +1226,8 @@ protected function _doTable_callback($matches) {
12231226
$head = $matches[1];
12241227
$underline = $matches[2];
12251228
$content = $matches[3];
1226-
$attr = [];
1229+
$id_class = $matches[4] ?? null;
1230+
$attr = [];
12271231

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

12531257
// Write column headers.
1254-
$text = "<table>\n";
1258+
$table_attr_str = $this->doExtraAttributes('table', $id_class, null, []);
1259+
$text = "<table$table_attr_str>\n";
12551260
$text .= "<thead>\n";
12561261
$text .= "<tr>\n";
12571262
foreach ($headers as $n => $header) {

0 commit comments

Comments
 (0)