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;
11 * Markdown parser for github flavored markdown.
13 * @author Carsten Brandt <mail@cebe.cc>
15 class GithubMarkdown extends Markdown
17 // include block element parsing using traits
19 use block\FencedCodeTrait;
21 // include inline element parsing using traits
22 use inline\StrikeoutTrait;
23 use inline\UrlLinkTrait;
26 * @var boolean whether to interpret newlines as `<br />`-tags.
27 * This feature is useful for comments where newlines are often meant to be real new lines.
29 public $enableNewlines = false;
34 protected $escapeCharacters = [
40 '{', '}', // curly braces
41 '[', ']', // square brackets
42 '(', ')', // parentheses
45 '-', // minus sign (hyphen)
47 '!', // exclamation mark
49 // added by GithubMarkdown
57 * Consume lines for a paragraph
59 * Allow headlines, lists and code to break paragraphs
61 protected function consumeParagraph($lines, $current)
63 // consume until newline
65 for ($i = $current, $count = count($lines); $i < $count; $i++) {
67 if (!empty($line) && ltrim($line) !== '' &&
68 !($line[0] === "\t" || $line[0] === " " && strncmp($line, ' ', 4) === 0) &&
69 !$this->identifyHeadline($line, $lines, $i) &&
70 !$this->identifyUl($line, $lines, $i) &&
71 !$this->identifyOl($line, $lines, $i))
80 'content' => $this->parseInline(implode("\n", $content)),
82 return [$block, --$i];
88 * Parses a newline indicated by two spaces on the end of a markdown line.
90 protected function renderText($text)
92 if ($this->enableNewlines) {
93 $br = $this->html5 ? "<br>\n" : "<br />\n";
94 return strtr($text[1], [" \n" => $br, "\n" => $br]);
96 return parent::renderText($text);