From 78c5974cd34559d0130d8be509935e2c992cd9ca Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sat, 4 Nov 2017 09:45:54 +0100 Subject: The Parsedown library has been patched to prevent tab indentations from 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: https://github.com/erusev/parsedown/issues/508 --- core/namespace/Parsedown.php | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'core/namespace/Parsedown.php') diff --git a/core/namespace/Parsedown.php b/core/namespace/Parsedown.php index f5dd0fa..ec7bdde 100644 --- a/core/namespace/Parsedown.php +++ b/core/namespace/Parsedown.php @@ -131,23 +131,6 @@ class Parsedown 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] === ' ') @@ -298,9 +281,12 @@ class Parsedown 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( @@ -319,7 +305,10 @@ class Parsedown 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'])) { @@ -330,7 +319,7 @@ class Parsedown $Block['element']['text']['text'] .= "\n"; - $text = substr($Line['body'], 4); + $text = substr($Line['body'], $remove); $Block['element']['text']['text'] .= $text; -- cgit v1.2.3