mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Implement Paragraph
This commit is contained in:
parent
b53971e656
commit
18e239fba1
78
src/Components/Blocks/Paragraph.php
Normal file
78
src/Components/Blocks/Paragraph.php
Normal 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))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -288,36 +288,6 @@ class Parsedown
|
|||||||
return \method_exists($this, 'block' . $Type . 'Complete');
|
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
|
# Inline Elements
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user