leilukin-tumbleblog/includes/lib/xenocrat/markdown/block/RuleTrait.php

40 lines
799 B
PHP
Raw Normal View History

2024-06-20 14:10:42 +00:00
<?php
/**
* @copyright Copyright 2014 Carsten Brandt, 2024 Daniel Pimley
* @license https://github.com/xenocrat/chyrp-markdown/blob/master/LICENSE
* @link https://github.com/xenocrat/chyrp-markdown#readme
*/
namespace xenocrat\markdown\block;
/**
* Adds horizontal rules.
*/
trait RuleTrait
{
/**
* Identify a line as a horizontal rule.
*/
protected function identifyHr($line): bool
{
// At least 3 of -, * or _ on one line make a hr.
return preg_match('/^ {0,3}([\-\*_])\s*\1\s*\1(\1|\s)*$/', $line);
}
/**
* Consume a horizontal rule.
*/
protected function consumeHr($lines, $current): array
{
return [['hr'], $current];
}
/**
* Renders a horizontal rule.
*/
protected function renderHr($block): string
{
return $this->html5 ? "<hr>\n" : "<hr />\n";
}
}