RuleTrait.php
805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @copyright Copyright (c) 2014 Carsten Brandt
* @license https://github.com/cebe/markdown/blob/master/LICENSE
* @link https://github.com/cebe/markdown#readme
*/
namespace cebe\markdown\block;
/**
* Adds horizontal rules
*/
trait RuleTrait
{
/**
* identify a line as a horizontal rule.
*/
protected function identifyHr($line)
{
// at least 3 of -, * or _ on one line make a hr
return (($l = $line[0]) === ' ' || $l === '-' || $l === '*' || $l === '_') && preg_match('/^ {0,3}([\-\*_])\s*\1\s*\1(\1|\s)*$/', $line);
}
/**
* Consume a horizontal rule
*/
protected function consumeHr($lines, $current)
{
return [['hr'], $current];
}
/**
* Renders a horizontal rule
*/
protected function renderHr($block)
{
return $this->html5 ? "<hr>\n" : "<hr />\n";
}
}