1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Merge pull request #584 from aidantwoods/fix/tables

Permit 1 column tables with less delimiters
This commit is contained in:
Aidan Woods
2018-03-27 23:18:41 +01:00
committed by GitHub
3 changed files with 163 additions and 100 deletions

View File

@ -836,8 +836,19 @@ class Parsedown
return;
}
if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
if (
strpos($Block['element']['text'], '|') === false
and strpos($Line['text'], '|') === false
and strpos($Line['text'], ':') === false
) {
return;
}
if (chop($Line['text'], ' -:|') !== '')
{
return;
}
$alignments = array();
$divider = $Line['text'];
@ -853,7 +864,7 @@ class Parsedown
if ($dividerCell === '')
{
continue;
return;
}
$alignment = null;
@ -882,6 +893,11 @@ class Parsedown
$headerCells = explode('|', $header);
if (count($headerCells) !== count($alignments))
{
return;
}
foreach ($headerCells as $index => $headerCell)
{
$headerCell = trim($headerCell);
@ -934,7 +950,6 @@ class Parsedown
return $Block;
}
}
protected function blockTableContinue($Line, array $Block)
{
@ -943,7 +958,7 @@ class Parsedown
return;
}
if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
if (count($Block['alignments']) === 1 or $Line['text'][0] === '|' or strpos($Line['text'], '|'))
{
$Elements = array();
@ -954,7 +969,9 @@ class Parsedown
preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
foreach ($matches[0] as $index => $cell)
$cells = array_slice($matches[0], 0, count($Block['alignments']));
foreach ($cells as $index => $cell)
{
$cell = trim($cell);

View File

@ -35,3 +35,35 @@
</tr>
</tbody>
</table>
<hr />
<table>
<thead>
<tr>
<th style="text-align: left;">header 1</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">cell 1.1</td>
</tr>
<tr>
<td style="text-align: left;">cell 2.1</td>
</tr>
</tbody>
</table>
<hr />
<table>
<thead>
<tr>
<th>header 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>cell 1.1</td>
</tr>
<tr>
<td>cell 2.1</td>
</tr>
</tbody>
</table>

View File

@ -9,3 +9,17 @@ header 1 | header 2
:------- | --------
cell 1.1 | cell 1.2
cell 2.1 | cell 2.2
---
header 1
:-------
cell 1.1
cell 2.1
---
header 1
-------|
cell 1.1
cell 2.1