@@ 35-57 (lines=23) @@ | ||
32 | /** |
|
33 | * Consume lines for a fenced code block |
|
34 | */ |
|
35 | protected function consumeFencedCode($lines, $current) |
|
36 | { |
|
37 | $line = ltrim($lines[$current]); |
|
38 | $fence = substr($line, 0, $pos = strrpos($line, $line[0]) + 1); |
|
39 | $language = rtrim(substr($line, $pos)); |
|
40 | // consume until end fence |
|
41 | $content = []; |
|
42 | for ($i = $current + 1, $count = count($lines); $i < $count; $i++) { |
|
43 | if (($pos = strpos($line = $lines[$i], $fence)) === false || $pos > 3) { |
|
44 | $content[] = $line; |
|
45 | } else { |
|
46 | break; |
|
47 | } |
|
48 | } |
|
49 | $block = [ |
|
50 | 'code', |
|
51 | 'content' => implode("\n", $content), |
|
52 | ]; |
|
53 | if (!empty($language)) { |
|
54 | $block['language'] = $language; |
|
55 | } |
|
56 | return [$block, $i]; |
|
57 | } |
|
58 | } |
|
59 |
@@ 106-128 (lines=23) @@ | ||
103 | /** |
|
104 | * Consume lines for a fenced code block |
|
105 | */ |
|
106 | protected function consumeFencedCode($lines, $current) |
|
107 | { |
|
108 | // consume until ``` |
|
109 | $block = [ |
|
110 | 'code', |
|
111 | ]; |
|
112 | $line = trim($lines[$current]); |
|
113 | if (($pos = strrpos($line, '`')) === false) { |
|
114 | $pos = strrpos($line, '~'); |
|
115 | } |
|
116 | $fence = substr($line, 0, $pos + 1); |
|
117 | $block['attributes'] = substr($line, $pos); |
|
118 | $content = []; |
|
119 | for($i = $current + 1, $count = count($lines); $i < $count; $i++) { |
|
120 | if (($pos = strpos($line = $lines[$i], $fence)) === false || $pos > 3) { |
|
121 | $content[] = $line; |
|
122 | } else { |
|
123 | break; |
|
124 | } |
|
125 | } |
|
126 | $block['content'] = implode("\n", $content); |
|
127 | return [$block, $i]; |
|
128 | } |
|
129 | ||
130 | protected function renderCode($block) |
|
131 | { |