Skip to content

Commit

Permalink
The Parsedown library has been patched to prevent tab indentations fr…
Browse files Browse the repository at this point in the history
…om being converted to spaces:

For example, if you had used the markdown syntax for displaying source code in your post, Parsedown had replaced your semantically correct tab indentations with hard spaces. This behavior meant that the code that was displayed after parsing was no longer exactly the code you inserted into the content editor. If someone had copied source code from your post into his IDE, then your tab indentations were gone because of the spaces.

That's why I hacked the Parsedown library and created a patch:
erusev/parsedown#508
  • Loading branch information
Nerdmind committed Nov 4, 2017
1 parent 29ead28 commit 78c5974
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions core/namespace/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,6 @@ protected function lines(array $lines)
continue;
}

if (strpos($line, "\t") !== false)
{
$parts = explode("\t", $line);

$line = $parts[0];

unset($parts[0]);

foreach ($parts as $part)
{
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;

$line .= str_repeat(' ', $shortage);
$line .= $part;
}
}

$indent = 0;

while (isset($line[$indent]) and $line[$indent] === ' ')
Expand Down Expand Up @@ -298,9 +281,12 @@ protected function blockCode($Line, $Block = null)
return;
}

if ($Line['indent'] >= 4)
$conditionA = $Line['indent'] >= 4;
$conditionB = substr($Line['body'], 0, 1) === "\t";

if (($conditionA and $remove = 4) or ($conditionB and $remove = 1))
{
$text = substr($Line['body'], 4);
$text = substr($Line['body'], $remove);

$Block = array(
'element' => array(
Expand All @@ -319,7 +305,10 @@ protected function blockCode($Line, $Block = null)

protected function blockCodeContinue($Line, $Block)
{
if ($Line['indent'] >= 4)
$conditionA = $Line['indent'] >= 4;
$conditionB = substr($Line['body'], 0, 1) === "\t";

if (($conditionA and $remove = 4) or ($conditionB and $remove = 1))
{
if (isset($Block['interrupted']))
{
Expand All @@ -330,7 +319,7 @@ protected function blockCodeContinue($Line, $Block)

$Block['element']['text']['text'] .= "\n";

$text = substr($Line['body'], 4);
$text = substr($Line['body'], $remove);

$Block['element']['text']['text'] .= $text;

Expand Down

0 comments on commit 78c5974

Please sign in to comment.