aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/Parsedown.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-11-04 09:45:54 +0100
committerThomas Lange <code@nerdmind.de>2017-11-04 09:45:54 +0100
commit78c5974cd34559d0130d8be509935e2c992cd9ca (patch)
tree4837c6a22adc822eea467e9a04b2e1254b3add0a /core/namespace/Parsedown.php
parent29ead287180d2bc21cc5a5e70298827e1970aee3 (diff)
downloadblog-78c5974cd34559d0130d8be509935e2c992cd9ca.tar.gz
blog-78c5974cd34559d0130d8be509935e2c992cd9ca.tar.xz
blog-78c5974cd34559d0130d8be509935e2c992cd9ca.zip
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
Diffstat (limited to 'core/namespace/Parsedown.php')
-rw-r--r--core/namespace/Parsedown.php31
1 files changed, 10 insertions, 21 deletions
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;