diff --git a/src/markup/engine/__tests__/remarkup/table-with-long-header.txt b/src/markup/engine/__tests__/remarkup/table-with-long-header.txt new file mode 100644 index 0000000..84b5cb8 --- /dev/null +++ b/src/markup/engine/__tests__/remarkup/table-with-long-header.txt @@ -0,0 +1,8 @@ +|x| +||-- +~~~~~~~~~~ +
+ +
x
+~~~~~~~~~~ +| x | diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php index 58ad3d5..72aae08 100644 --- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php @@ -1,89 +1,96 @@ cells // instead of cells. // If it has other types of cells, it's always a content row. // If it has only empty cells, it's an empty row. if (strlen($cell)) { if (preg_match('/^--+\z/', $cell)) { $any_header = true; } else { $any_content = true; } } $cells[] = array('type' => 'td', 'content' => $this->applyRules($cell)); } $is_header = ($any_header && !$any_content); if (!$is_header) { $rows[] = array('type' => 'tr', 'content' => $cells); } else if ($rows) { // Mark previous row with headings. foreach ($cells as $i => $cell) { if ($cell['content']) { - $rows[last_key($rows)]['content'][$i]['type'] = 'th'; + $last_key = last_key($rows); + if (!isset($rows[$last_key]['content'][$i])) { + // If this row has more cells than the previous row, there may + // not be a cell above this one to turn into a . + continue; + } + + $rows[$last_key]['content'][$i]['type'] = 'th'; } } } } if (!$rows) { return $this->applyRules($text); } return $this->renderRemarkupTable($rows); } }