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 fenced code blocks
13 * automatically included 4 space indented code blocks
20 * identify a line as the beginning of a fenced code block.
22 protected function identifyFencedCode($line)
24 return ($l = $line[0]) === '`' && strncmp($line, '```', 3) === 0 ||
25 $l === '~' && strncmp($line, '~~~', 3) === 0;
29 * Consume lines for a fenced code block
31 protected function consumeFencedCode($lines, $current)
34 $line = rtrim($lines[$current]);
35 $fence = substr($line, 0, $pos = strrpos($line, $line[0]) + 1);
36 $language = substr($line, $pos);
38 for ($i = $current + 1, $count = count($lines); $i < $count; $i++) {
39 if (rtrim($line = $lines[$i]) !== $fence) {
47 'content' => implode("\n", $content),
49 if (!empty($language)) {
50 $block['language'] = $language;