1 | <?php |
||
13 | trait QuoteTrait |
||
14 | { |
||
15 | /** |
||
16 | * identify a line as the beginning of a block quote. |
||
17 | */ |
||
18 | 205 | protected function identifyQuote($line) |
|
19 | { |
||
20 | 205 | return $line[0] === '>' && (!isset($line[1]) || ($l1 = $line[1]) === ' ' || $l1 === "\t"); |
|
21 | } |
||
22 | |||
23 | /** |
||
24 | * Consume lines for a blockquote element |
||
25 | */ |
||
26 | 27 | protected function consumeQuote($lines, $current) |
|
27 | { |
||
28 | // consume until newline |
||
29 | 27 | $content = []; |
|
30 | 27 | for ($i = $current, $count = count($lines); $i < $count; $i++) { |
|
31 | 27 | $line = $lines[$i]; |
|
32 | 27 | if (ltrim($line) !== '') { |
|
33 | 27 | if ($line[0] == '>' && !isset($line[1])) { |
|
34 | 8 | $line = ''; |
|
35 | 27 | } elseif (strncmp($line, '> ', 2) === 0) { |
|
36 | 27 | $line = substr($line, 2); |
|
37 | } |
||
38 | 27 | $content[] = $line; |
|
39 | } else { |
||
40 | 24 | break; |
|
41 | } |
||
42 | } |
||
43 | |||
44 | $block = [ |
||
45 | 27 | 'quote', |
|
46 | 27 | 'content' => $this->parseBlocks($content), |
|
47 | 'simple' => true, |
||
48 | ]; |
||
49 | 27 | return [$block, $i]; |
|
50 | } |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Renders a blockquote |
||
55 | */ |
||
56 | 27 | protected function renderQuote($block) |
|
57 | { |
||
58 | 27 | return '<blockquote>' . $this->renderAbsy($block['content']) . "</blockquote>\n"; |
|
59 | } |
||
60 | |||
61 | abstract protected function parseBlocks($lines); |
||
63 | } |
||
64 |