2019-01-20 05:28:17 +03:00
|
|
|
<?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\Parsing\Context;
|
|
|
|
use Erusev\Parsedown\State;
|
|
|
|
|
|
|
|
final class Rule implements Block
|
|
|
|
{
|
2019-02-16 15:37:22 +03:00
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-20 05:28:17 +03:00
|
|
|
/**
|
|
|
|
* @param Context $Context
|
2019-02-10 21:32:28 +03:00
|
|
|
* @param State $State
|
2019-01-20 05:28:17 +03:00
|
|
|
* @param Block|null $Block
|
|
|
|
* @return static|null
|
|
|
|
*/
|
|
|
|
public static function build(
|
|
|
|
Context $Context,
|
2019-02-10 21:32:28 +03:00
|
|
|
State $State,
|
|
|
|
Block $Block = null
|
2019-01-20 05:28:17 +03:00
|
|
|
) {
|
2019-01-22 22:23:05 +03:00
|
|
|
if ($Context->line()->indent() > 3) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-02-03 00:07:12 +03:00
|
|
|
$marker = \substr($Context->line()->text(), 0, 1);
|
2019-01-20 05:28:17 +03:00
|
|
|
|
2019-02-03 03:20:54 +03:00
|
|
|
if ($marker !== '*' && $marker !== '-' && $marker !== '_') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-22 22:28:12 +03:00
|
|
|
if (
|
|
|
|
\substr_count($Context->line()->text(), $marker) >= 3
|
2019-01-26 17:51:05 +03:00
|
|
|
&& \chop($Context->line()->text(), " \t$marker") === ''
|
2019-01-22 22:28:12 +03:00
|
|
|
) {
|
2019-01-20 05:28:17 +03:00
|
|
|
return new self;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Element
|
|
|
|
*/
|
2019-01-26 00:39:37 +03:00
|
|
|
public function stateRenderable()
|
2019-01-20 05:28:17 +03:00
|
|
|
{
|
|
|
|
return Element::selfClosing('hr', []);
|
|
|
|
}
|
|
|
|
}
|