mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add hard and soft breaks
This commit is contained in:
@@ -2,11 +2,8 @@
|
||||
|
||||
namespace Erusev\Parsedown\Components\Inlines;
|
||||
|
||||
use Erusev\Parsedown\AST\Handler;
|
||||
use Erusev\Parsedown\AST\StateRenderable;
|
||||
use Erusev\Parsedown\Components\Inline;
|
||||
use Erusev\Parsedown\Html\Renderables\Container;
|
||||
use Erusev\Parsedown\Html\Renderables\Element;
|
||||
use Erusev\Parsedown\Html\Renderables\Text;
|
||||
use Erusev\Parsedown\Parsedown;
|
||||
use Erusev\Parsedown\Parsing\Excerpt;
|
||||
@@ -45,34 +42,11 @@ final class PlainText implements Inline
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Handler<Container>
|
||||
* @return Text
|
||||
*/
|
||||
public function stateRenderable(Parsedown $_)
|
||||
{
|
||||
return new Handler(
|
||||
/** @return Container */
|
||||
function (State $_) {
|
||||
$Renderables = [];
|
||||
$text = $this->text;
|
||||
|
||||
$text = \preg_replace('/(?<![ \t])[ ]\n/', "$1\n", $text);
|
||||
|
||||
while (\preg_match('/(?:[ ]*+[\\\]|[ ]{2,}+)\n/', $text, $matches, \PREG_OFFSET_CAPTURE)) {
|
||||
$offset = \intval($matches[0][1]);
|
||||
$before = \substr($text, 0, $offset);
|
||||
$after = \substr($text, $offset + \strlen($matches[0][0]));
|
||||
$Renderables[] = new Text($before);
|
||||
$Renderables[] = Element::selfClosing('br', []);
|
||||
$Renderables[] = new Text("\n");
|
||||
|
||||
$text = $after;
|
||||
}
|
||||
|
||||
$Renderables[] = new Text($text);
|
||||
|
||||
return new Container($Renderables);
|
||||
}
|
||||
);
|
||||
return new Text($this->text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user