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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user