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
8 namespace cebe\markdown\block;
11 * Adds the headline blocks
16 * identify a line as a headline
18 protected function identifyHeadline($line, $lines, $current)
24 // underlined headline
25 !empty($lines[$current + 1]) &&
26 (($l = $lines[$current + 1][0]) === '=' || $l === '-') &&
27 preg_match('/^(\-+|=+)\s*$/', $lines[$current + 1])
32 * Consume lines for a headline
34 protected function consumeHeadline($lines, $current)
36 if ($lines[$current][0] === '#') {
39 while (isset($lines[$current][$level]) && $lines[$current][$level] === '#' && $level < 6) {
44 'content' => $this->parseInline(trim($lines[$current], "# \t")),
47 return [$block, $current];
49 // underlined headline
52 'content' => $this->parseInline($lines[$current]),
53 'level' => $lines[$current + 1][0] === '=' ? 1 : 2,
55 return [$block, $current + 1];
62 protected function renderHeadline($block)
64 $tag = 'h' . $block['level'];
65 return "<$tag>" . $this->renderAbsy($block['content']) . "</$tag>\n";
68 abstract protected function parseInline($text);
69 abstract protected function renderAbsy($absy);