RuleTrait.php 805 B

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