Implement Rule

This commit is contained in:
Aidan Woods 2019-01-20 02:28:17 +00:00
parent a95bc60c30
commit af97e99b39
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
2 changed files with 43 additions and 18 deletions

View File

@ -0,0 +1,43 @@
<?php
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;
final class Rule implements Block
{
use BlockAcquisition;
/**
* @param Context $Context
* @param Block|null $Block
* @param State|null $State
* @return static|null
*/
public static function build(
Context $Context,
Block $Block = null,
State $State = null
) {
$marker = $Context->line()->text()[0];
if (\substr_count($Context->line()->text(), $marker) >= 3 and \chop($Context->line()->text(), " $marker") === '') {
return new self;
}
return null;
}
/**
* @return Element
*/
public function stateRenderable(Parsedown $_)
{
return Element::selfClosing('hr', []);
}
}

View File

@ -334,24 +334,6 @@ class Parsedown
return $Block;
}
#
# Rule
protected function blockRule(Context $Context)
{
$marker = $Context->line()->text()[0];
if (\substr_count($Context->line()->text(), $marker) >= 3 and \chop($Context->line()->text(), " $marker") === '') {
$Block = [
'element' => [
'name' => 'hr',
],
];
return $Block;
}
}
#
# Setext