mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Permit 1 column tables with less delimiters
This commit is contained in:
parent
ae13290221
commit
00e51ee424
@ -835,8 +835,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'];
|
||||
@ -852,7 +863,7 @@ class Parsedown
|
||||
|
||||
if ($dividerCell === '')
|
||||
{
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
$alignment = null;
|
||||
@ -881,6 +892,11 @@ class Parsedown
|
||||
|
||||
$headerCells = explode('|', $header);
|
||||
|
||||
if (count($headerCells) !== count($alignments))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($headerCells as $index => $headerCell)
|
||||
{
|
||||
$headerCell = trim($headerCell);
|
||||
@ -933,7 +949,6 @@ class Parsedown
|
||||
|
||||
return $Block;
|
||||
}
|
||||
}
|
||||
|
||||
protected function blockTableContinue($Line, array $Block)
|
||||
{
|
||||
@ -942,7 +957,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();
|
||||
|
||||
@ -953,7 +968,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);
|
||||
|
||||
|
@ -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>
|
@ -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
|
Loading…
Reference in New Issue
Block a user