1 | <?php |
||
14 | class MarkdownEngine extends \ParsedownExtra implements MarkupEngine |
||
15 | { |
||
16 | protected $highlighter; |
||
17 | |||
18 | 87 | public function __construct() |
|
24 | |||
25 | 11 | protected function blockHeader($Line) |
|
|
|||
26 | { |
||
27 | 11 | $Block = parent::blockHeader($Line); |
|
28 | |||
29 | 11 | if (isset($Block['element']['text'])) |
|
30 | 11 | { |
|
31 | 11 | $Block['element']['attributes']['id'] = $this->slugifyHeader($Block); |
|
32 | 11 | } |
|
33 | |||
34 | 11 | return $Block; |
|
35 | } |
||
36 | |||
37 | 3 | protected function blockSetextHeader($Line, array $Block = null) |
|
38 | { |
||
39 | 3 | $Block = parent::blockSetextHeader($Line, $Block); |
|
40 | |||
41 | 3 | if (isset($Block['element']['name'])) |
|
42 | 3 | { |
|
43 | 1 | $element = $Block['element']['name']; |
|
44 | |||
45 | 1 | if (in_array($element, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'])) |
|
46 | 1 | { |
|
47 | 1 | $Block['element']['attributes']['id'] = $this->slugifyHeader($Block); |
|
48 | 1 | } |
|
49 | 1 | } |
|
50 | |||
51 | 3 | return $Block; |
|
52 | } |
||
53 | |||
54 | 11 | private function slugifyHeader($Block) |
|
62 | |||
63 | 3 | protected function blockFencedCodeComplete($block) |
|
64 | { |
||
65 | // The class has a `language-` prefix, remove this to get the language |
||
66 | 3 | if (isset($block['element']['text']['attributes']) && Service::getParameter(Configuration::HIGHLIGHTER_ENABLED)) |
|
67 | 3 | { |
|
68 | 2 | $cssClass = &$block['element']['text']['attributes']['class']; |
|
69 | 2 | $language = substr($cssClass, 9); |
|
70 | 2 | $cssClass = 'hljs ' . $cssClass; |
|
71 | |||
72 | try |
||
73 | { |
||
74 | 2 | $highlighted = $this->highlighter->highlight($language, $block['element']['text']['text']); |
|
75 | 1 | $block['element']['text']['text'] = $highlighted->value; |
|
76 | |||
77 | // Only return the block if Highlighter knew the language and how to handle it. |
||
78 | 1 | return $block; |
|
79 | } |
||
80 | // Exception thrown when language not supported |
||
81 | 1 | catch (\DomainException $exception) |
|
82 | { |
||
83 | 1 | trigger_error("An unsupported language ($language) was detected in a code block", E_USER_WARNING); |
|
84 | } |
||
85 | } |
||
86 | |||
87 | 1 | return parent::blockFencedCodeComplete($block); |
|
88 | } |
||
89 | |||
90 | /// |
||
91 | // MarkupEngine Implementation |
||
92 | /// |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | 76 | public function getTemplateTag() |
|
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | 76 | public function getExtensions() |
|
113 | } |
||
114 |
This check marks parameter names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.