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

Implement Paragraph

This commit is contained in:
Aidan Woods 2019-01-20 02:31:18 +00:00
parent b53971e656
commit 18e239fba1
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 78 additions and 30 deletions

View File

@ -0,0 +1,78 @@
<?php
namespace Erusev\Parsedown\Components\Blocks;
use Erusev\Parsedown\AST\Handler;
use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Components\ContinuableBlock;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
final class Paragraph implements ContinuableBlock
{
use ContinuableBlockDefaultInterrupt, BlockAcquisition;
/** @var string */
private $text;
/**
* @param string $text
*/
public function __construct($text)
{
$this->text = $text;
}
/**
* @param Context $Context
* @param Block|null $Block
* @param State|null $State
* @return static
*/
public static function build(
Context $Context,
Block $Block = null,
State $State = null
) {
return new self($Context->line()->text());
}
/**
* @param Context $Context
* @return self|null
*/
public function continue(Context $Context)
{
if ($this->interrupted) {
return null;
}
return new self($this->text . "\n" . $Context->line()->text());
}
/** @return string */
public function text()
{
return $this->text;
}
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
return new Element(
'p',
[],
$State->applyTo($Parsedown->lineElements($this->text))
);
}
);
}
}

View File

@ -288,36 +288,6 @@ class Parsedown
return \method_exists($this, 'block' . $Type . 'Complete');
}
#
# ~
#
protected function paragraph(Context $Context)
{
return [
'type' => 'Paragraph',
'element' => [
'name' => 'p',
'handler' => [
'function' => 'lineElements',
'argument' => $Context->line()->text(),
'destination' => 'elements',
],
],
];
}
protected function paragraphContinue(Context $Context, array $Block)
{
if (isset($Block['interrupted'])) {
return;
}
$Block['element']['handler']['argument'] .= "\n".$Context->line()->text();
return $Block;
}
#
# Inline Elements
#