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

Track whitespace left on blank lines to match CommonMark

Test changes copy pasted to match CommonMark reference parser
This commit is contained in:
Aidan Woods
2019-01-28 19:13:57 +00:00
parent 49dd8b113d
commit f47ba7aa34
17 changed files with 106 additions and 59 deletions

View File

@@ -85,19 +85,15 @@ final class FencedCode implements ContinuableBlock
$newCode = $this->code;
if ($Context->previousEmptyLines() > 0) {
$newCode .= \str_repeat("\n", $Context->previousEmptyLines());
}
$newCode .= $Context->previousEmptyLinesText();
if (($len = \strspn($Context->line()->text(), $this->marker)) >= $this->openerLength
&& \chop(\substr($Context->line()->text(), $len), ' ') === ''
) {
$newCode = \substr($newCode, 1);
return new self($newCode, $this->infostring, $this->marker, $this->openerLength, true);
}
$newCode .= "\n" . $Context->line()->rawLine();
$newCode .= $Context->line()->rawLine() . "\n";
return new self($newCode, $this->infostring, $this->marker, $this->openerLength, false);
}

View File

@@ -8,6 +8,7 @@ use Erusev\Parsedown\Components\ContinuableBlock;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\Parsing\Line;
use Erusev\Parsedown\State;
final class IndentedCode implements ContinuableBlock
@@ -44,7 +45,7 @@ final class IndentedCode implements ContinuableBlock
return null;
}
return new self($Context->line()->ltrimBodyUpto(4));
return new self($Context->line()->ltrimBodyUpto(4) . "\n");
}
/**
@@ -59,11 +60,19 @@ final class IndentedCode implements ContinuableBlock
$newCode = $this->code;
$offset = $Context->line()->indentOffset();
if ($Context->previousEmptyLines() > 0) {
$newCode .= \str_repeat("\n", $Context->previousEmptyLines());
foreach (\explode("\n", $Context->previousEmptyLinesText()) as $line) {
$newCode .= (new Line($line, $offset))->ltrimBodyUpto(4) . "\n";
}
$newCode = \substr($newCode, 0, -1);
}
return new self($newCode . "\n" . $Context->line()->ltrimBodyUpto(4));
$newCode .= $Context->line()->ltrimBodyUpto(4) . "\n";
return new self($newCode);
}
/**