Skip to content

Commit 424814d

Browse files
authored
Merge branch 'michelf:lib' into lib
2 parents fc9a199 + 98b12b8 commit 424814d

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

Michelf/MarkdownExtra.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $
229229
}
230230

231231
// Split on components
232-
preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches);
232+
preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr ?? '', $matches);
233233
$elements = $matches[0];
234234

235235
// Handle classes and IDs (only first ID taken into account)
@@ -499,7 +499,7 @@ protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
499499
$parsed .= $parts[0]; // Text before current tag.
500500

501501
// If end of $text has been reached. Stop loop.
502-
if (count($parts) < 3) {
502+
if ($parts === false || count($parts) < 3) {
503503
$text = "";
504504
break;
505505
}
@@ -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)