PluginProbe
OPcache Manager / 3.3.0
OPcache Manager v3.3.0
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 2.0.0 2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.14.0 2.2.0 2.3.0 2.3.1 2.3.2 2.4.0 2.5.0 2.6.0 All 36 releases
opcache-manager / includes / libraries / markdown / GithubMarkdown.php

GithubMarkdown.php in OPcache Manager 3.3.0, at includes/libraries/markdown/GithubMarkdown.php

115 lines 2.7 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;
9
10 /**
11 * Markdown parser for github flavored markdown.
12 *
13 * @author Carsten Brandt <mail@cebe.cc>
14 */
15 class GithubMarkdown extends MarkdownParser
16 {
17 // include block element parsing using traits
18 use block\TableTrait;
19 use block\FencedCodeTrait;
20
21 // include inline element parsing using traits
22 use inline\StrikeoutTrait;
23 use inline\UrlLinkTrait;
24
25 /**
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.
28 */
29 public $enableNewlines = false;
30
31 /**
32 * @inheritDoc
33 */
34 protected $escapeCharacters = [
35 // from Markdown
36 '\\', // backslash
37 '`', // backtick
38 '*', // asterisk
39 '_', // underscore
40 '{', '}', // curly braces
41 '[', ']', // square brackets
42 '(', ')', // parentheses
43 '#', // hash mark
44 '+', // plus sign
45 '-', // minus sign (hyphen)
46 '.', // dot
47 '!', // exclamation mark
48 '<', '>',
49 // added by GithubMarkdown
50 ':', // colon
51 '|', // pipe
52 ];
53
54
55
56 /**
57 * Consume lines for a paragraph
58 *
59 * Allow headlines, lists and code to break paragraphs
60 */
61 protected function consumeParagraph($lines, $current)
62 {
63 // consume until newline
64 $content = [];
65 for ($i = $current, $count = count($lines); $i < $count; $i++) {
66 $line = $lines[$i];
67 if ($line === ''
68 || ltrim($line) === ''
69 || !ctype_alpha($line[0]) && (
70 $this->identifyQuote($line, $lines, $i) ||
71 $this->identifyFencedCode($line, $lines, $i) ||
72 $this->identifyUl($line, $lines, $i) ||
73 $this->identifyOl($line, $lines, $i) ||
74 $this->identifyHr($line, $lines, $i)
75 )
76 || $this->identifyHeadline($line, $lines, $i))
77 {
78 break;
79 } elseif ($this->identifyCode($line, $lines, $i)) {
80 // possible beginning of a code block
81 // but check for continued inline HTML
82 // e.g. <img src="file.jpg"
83 // alt="some alt aligned with src attribute" title="some text" />
84 if (preg_match('~<\w+([^>]+)$~s', implode("\n", $content))) {
85 $content[] = $line;
86 } else {
87 break;
88 }
89 } else {
90 $content[] = $line;
91 }
92 }
93 $block = [
94 'paragraph',
95 'content' => $this->parseInline(implode("\n", $content)),
96 ];
97 return [$block, --$i];
98 }
99
100 /**
101 * @inheritdocs
102 *
103 * Parses a newline indicated by two spaces on the end of a markdown line.
104 */
105 protected function renderText($text)
106 {
107 if ($this->enableNewlines) {
108 $br = $this->html5 ? "<br>\n" : "<br />\n";
109 return strtr($text[1], [" \n" => $br, "\n" => $br]);
110 } else {
111 return parent::renderText($text);
112 }
113 }
114 }
115