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

We don't need to pass a Parsedown instance down

Since Parsedown is instancible from State, we only
need to carry that down.
This commit is contained in:
Aidan Woods 2019-01-25 21:39:37 +00:00
parent b89bd0e3c2
commit 11da347aa1
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
28 changed files with 53 additions and 69 deletions

View File

@ -9,5 +9,5 @@ interface Component
/**
* @return StateRenderable
*/
public function stateRenderable(Parsedown $Parsedown);
public function stateRenderable();
}

View File

@ -97,15 +97,15 @@ final class BlockQuote implements ContinuableBlock
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
'blockquote',
[],
$State->applyTo($Parsedown->lines($this->Lines))
$State->applyTo((new Parsedown($State))->lines($this->Lines))
);
}
);

View File

@ -9,7 +9,6 @@ use Erusev\Parsedown\Components\ContinuableBlock;
use Erusev\Parsedown\Configurables\SafeMode;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -73,7 +72,7 @@ final class Comment implements ContinuableBlock
/**
* @return Handler<Text|RawHtml>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Text|RawHtml */

View File

@ -7,7 +7,6 @@ use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Components\ContinuableBlock;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -106,7 +105,7 @@ final class FencedCode implements ContinuableBlock
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element('pre', [], [new Element(
'code',

View File

@ -76,15 +76,15 @@ final class Header implements Block
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
'h' . \strval($this->level),
[],
$State->applyTo($Parsedown->line($this->text))
$State->applyTo((new Parsedown($State))->line($this->text))
);
}
);

View File

@ -7,7 +7,6 @@ use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Components\ContinuableBlock;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -70,7 +69,7 @@ final class IndentedCode implements ContinuableBlock
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element(
'pre',

View File

@ -10,7 +10,6 @@ use Erusev\Parsedown\Configurables\SafeMode;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -71,7 +70,7 @@ final class Markup implements ContinuableBlock
/**
* @return Handler<Element|RawHtml>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element|RawHtml */

View File

@ -62,15 +62,15 @@ final class Paragraph implements ContinuableBlock
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
'p',
[],
$State->applyTo($Parsedown->line($this->text))
$State->applyTo((new Parsedown($State))->line($this->text))
);
}
);

View File

@ -7,7 +7,6 @@ use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Components\StateUpdatingBlock;
use Erusev\Parsedown\Configurables\DefinitionBook;
use Erusev\Parsedown\Html\Renderables\Invisible;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -69,7 +68,7 @@ final class Reference implements StateUpdatingBlock
/**
* @return Invisible
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Invisible;
}

View File

@ -5,7 +5,6 @@ namespace Erusev\Parsedown\Components\Blocks;
use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Block;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Context;
use Erusev\Parsedown\State;
@ -43,7 +42,7 @@ final class Rule implements Block
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return Element::selfClosing('hr', []);
}

View File

@ -58,15 +58,15 @@ final class SetextHeader implements Block
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
'h' . \strval($this->level),
[],
$State->applyTo($Parsedown->line($this->text))
$State->applyTo((new Parsedown($State))->line($this->text))
);
}
);

View File

@ -276,11 +276,11 @@ final class TList implements ContinuableBlock
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
$this->type,
(
@ -290,12 +290,12 @@ final class TList implements ContinuableBlock
),
\array_map(
/** @return Element */
function (Lines $Lines) use ($State, $Parsedown) {
function (Lines $Lines) use ($State) {
if ($this->isLoose && $Lines->trailingBlankLines() === 0) {
$Lines = $Lines->appendingBlankLines(1);
}
$Renderables = $State->applyTo($Parsedown->lines($Lines));
$Renderables = $State->applyTo((new Parsedown($State))->lines($Lines));
if (! $Lines->containsBlankLines()
and isset($Renderables[0])

View File

@ -165,11 +165,11 @@ final class Table implements ContinuableBlock
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element('table', [], [
new Element('thead', [], [new Element('tr', [], \array_map(
/**
@ -177,11 +177,11 @@ final class Table implements ContinuableBlock
* @param _Alignment|null $alignment
* @return Element
*/
function ($cell, $alignment) use ($Parsedown, $State) {
function ($cell, $alignment) use ($State) {
return new Element(
'th',
isset($alignment) ? ['style' => "text-align: $alignment;"] : [],
$State->applyTo($Parsedown->line($cell))
$State->applyTo((new Parsedown($State))->line($cell))
);
},
$this->headerCells,
@ -192,18 +192,18 @@ final class Table implements ContinuableBlock
* @param array<int, string> $cells
* @return Element
*/
function ($cells) use ($Parsedown, $State) {
function ($cells) use ($State) {
return new Element('tr', [], \array_map(
/**
* @param string $cell
* @param _Alignment|null $alignment
* @return Element
*/
function ($cell, $alignment) use ($Parsedown, $State) {
function ($cell, $alignment) use ($State) {
return new Element(
'td',
isset($alignment) ? ['style' => "text-align: $alignment;"] : [],
$State->applyTo($Parsedown->line($cell))
$State->applyTo((new Parsedown($State))->line($cell))
);
},
$cells,

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -54,7 +53,7 @@ final class Code implements Inline
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element('code', [], [new Text($this->text)]);
}

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -60,7 +59,7 @@ final class Email implements Inline
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element('a', ['href' => $this->url], [new Text($this->text)]);
}

View File

@ -72,15 +72,15 @@ final class Emphasis implements Inline
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
$this->type,
[],
$State->applyTo($Parsedown->line($this->text))
$State->applyTo((new Parsedown($State))->line($this->text))
);
}
);

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -45,7 +44,7 @@ final class EscapeSequence implements Inline
/**
* @return RawHtml
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new RawHtml($this->html);
}

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -76,7 +75,7 @@ final class HardBreak implements Inline
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return Element::selfClosing('br', []);
}

View File

@ -54,15 +54,15 @@ final class Image implements Inline
/**
* @return Handler<Element|Text>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element|Text */
function (State $State) use ($Parsedown) {
function (State $State) {
$attributes = [
'src' => $this->Link->url(),
'alt' => \array_reduce(
$Parsedown->inlines($this->Link->label()),
(new Parsedown($State))->inlines($this->Link->label()),
/**
* @param string $text
* @return string

View File

@ -112,11 +112,11 @@ final class Link implements Inline
/**
* @return Handler<Element|Text>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element|Text */
function (State $State) use ($Parsedown) {
function (State $State) {
$attributes = ['href' => $this->url];
if (isset($this->title)) {

View File

@ -8,7 +8,6 @@ use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Configurables\SafeMode;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -59,7 +58,7 @@ final class Markup implements Inline
/**
* @return Handler<Text|RawHtml>
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Handler(
/** @return Text|RawHtml */

View File

@ -5,7 +5,6 @@ namespace Erusev\Parsedown\Components\Inlines;
use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -44,7 +43,7 @@ final class PlainText implements Inline
/**
* @return Text
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Text($this->text);
}

View File

@ -9,7 +9,6 @@ use Erusev\Parsedown\Configurables\Breaks;
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;
use Erusev\Parsedown\State;
@ -65,7 +64,7 @@ final class SoftBreak implements Inline
/**
* @return Handler<Text|Container>
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Handler(
/** @return Text|Container */

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\RawHtml;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -45,7 +44,7 @@ final class SpecialCharacter implements Inline
/**
* @return RawHtml
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new RawHtml(
'&' . (new Text($this->charCodeHtml))->getHtml() . ';'

View File

@ -51,15 +51,15 @@ final class Strikethrough implements Inline
/**
* @return Handler<Element>
*/
public function stateRenderable(Parsedown $Parsedown)
public function stateRenderable()
{
return new Handler(
/** @return Element */
function (State $State) use ($Parsedown) {
function (State $State) {
return new Element(
'del',
[],
$State->applyTo($Parsedown->line($this->text))
$State->applyTo((new Parsedown($State))->line($this->text))
);
}
);

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -67,7 +66,7 @@ final class Url implements Inline
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element('a', ['href' => $this->url], [new Text($this->url)]);
}

View File

@ -6,7 +6,6 @@ use Erusev\Parsedown\AST\StateRenderable;
use Erusev\Parsedown\Components\Inline;
use Erusev\Parsedown\Html\Renderables\Element;
use Erusev\Parsedown\Html\Renderables\Text;
use Erusev\Parsedown\Parsedown;
use Erusev\Parsedown\Parsing\Excerpt;
use Erusev\Parsedown\State;
@ -44,7 +43,7 @@ final class UrlTag implements Inline
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
public function stateRenderable()
{
return new Element('a', ['href' => $this->url], [new Text($this->url)]);
}

View File

@ -66,7 +66,7 @@ final class Parsedown
{
return \array_map(
/** @return StateRenderable */
function (Block $Block) { return $Block->stateRenderable($this); },
function (Block $Block) { return $Block->stateRenderable(); },
$this->blocks($Lines)
);
}
@ -155,7 +155,7 @@ final class Parsedown
{
return \array_map(
/** @return StateRenderable */
function (Inline $Inline) { return $Inline->stateRenderable($this); },
function (Inline $Inline) { return $Inline->stateRenderable(); },
$this->inlines($text)
);
}