Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
Support multiple escaped pipes in table cells
Browse files Browse the repository at this point in the history
e.g.

foo|bar
---|---
`\|\|`| The logical-or operator
  • Loading branch information
fredemmott committed Aug 31, 2018
1 parent 84e5c10 commit 581c301
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/render/MarkdownRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use type Facebook\Markdown\Blocks\TableExtensionColumnAlignment;
use namespace HH\Lib\{C, Math, Str, Vec};

/** Re-create Markdwon from the AST */
/** Re-create Markdown from the AST */
class MarkdownRenderer extends Renderer<string> {
private ?string $outContext = null;

Expand Down
3 changes: 2 additions & 1 deletion src/unparsed-blocks/TableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ private static function consumeRow(
$parts[] = Str\slice($first, $start);
break;
}
if ($end >> 1 && $first[$end - 1] === '\\') {

while ($end !== null && $end > 1 && $first[(int) $end - 1] === '\\') {
$end = Str\search($first, '|', $end + 1);
}

Expand Down
10 changes: 9 additions & 1 deletion tests/EdgeCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public function getManualExamples(
return [
tuple("- foo\n\n", "<ul>\n<li>foo</li>\n</ul>\n"),
tuple("- foo\n\n\n", "<ul>\n<li>foo</li>\n</ul>\n"),
tuple(
"foo|bar\n---|---\n`\|\|`|herp\n",
"<table>\n<thead>\n".
"<tr>\n<th>foo</th>\n<th>bar</th>\n</tr>\n".
"</thead>\n<tbody>\n".
"<tr>\n<td><code>||</code></td>\n<td>herp</td>\n</tr>".
"</tbody></table>\n"
),
// Already covered in the spec, but emphasizing here as they
// illustrate correct binding for the next problme
tuple('**foo*', "<p>*<em>foo</em></p>\n"),
Expand Down Expand Up @@ -59,7 +67,7 @@ public function testManualExample(
'unnamed',
$in,
$expected_html,
null,
/* extension = */ 'table',
);
}

Expand Down

0 comments on commit 581c301

Please sign in to comment.