PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / markdown / block / QuoteTrait.php

QuoteTrait.php in DecaLog 4.4.0, at includes/libraries/markdown/block/QuoteTrait.php

64 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
8 namespace cebe\markdownparser\block;
9
10 /**
11 * Adds the block quote elements
12 */
13 trait QuoteTrait
14 {
15 /**
16 * identify a line as the beginning of a block quote.
17 */
18 protected function identifyQuote($line)
19 {
20 return $line[0] === '>' && (!isset($line[1]) || ($l1 = $line[1]) === ' ' || $l1 === "\t");
21 }
22
23 /**
24 * Consume lines for a blockquote element
25 */
26 protected function consumeQuote($lines, $current)
27 {
28 // consume until newline
29 $content = [];
30 for ($i = $current, $count = count($lines); $i < $count; $i++) {
31 $line = $lines[$i];
32 if (ltrim($line) !== '') {
33 if ($line[0] == '>' && !isset($line[1])) {
34 $line = '';
35 } elseif (strncmp($line, '> ', 2) === 0) {
36 $line = substr($line, 2);
37 }
38 $content[] = $line;
39 } else {
40 break;
41 }
42 }
43
44 $block = [
45 'quote',
46 'content' => $this->parseBlocks($content),
47 'simple' => true,
48 ];
49 return [$block, $i];
50 }
51
52
53 /**
54 * Renders a blockquote
55 */
56 protected function renderQuote($block)
57 {
58 return '<blockquote>' . $this->renderAbsy($block['content']) . "</blockquote>\n";
59 }
60
61 abstract protected function parseBlocks($lines);
62 abstract protected function renderAbsy($absy);
63 }
64