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
--- /dev/null
+++ b/src/markup/engine/__tests__/remarkup/table-with-long-header.txt
@@ -0,0 +1,8 @@
+|x|
+||--
+~~~~~~~~~~
+
+~~~~~~~~~~
+| x |
diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php
--- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php
+++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupSimpleTableBlockRule.php
@@ -73,7 +73,14 @@
// 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';
}
}
}