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

56 lines
1.2 KiB
PHP
Raw Normal View History

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
{
private function __construct()
{
}
2019-01-20 05:28:17 +03:00
/**
* @param Context $Context
* @param State $State
2019-01-20 05:28:17 +03:00
* @param Block|null $Block
* @return static|null
*/
public static function build(
Context $Context,
State $State,
Block $Block = null
2019-01-20 05:28:17 +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
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
*/
public function stateRenderable()
2019-01-20 05:28:17 +03:00
{
return Element::selfClosing('hr', []);
}
}