db backup prior to drupal security update
[yaffs-website] / vendor / cebe / markdown / inline / EmphStrongTrait.php
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\markdown\inline;
9
10 /**
11  * Adds inline emphasizes and strong elements
12  */
13 trait EmphStrongTrait
14 {
15         /**
16          * Parses empathized and strong elements.
17          * @marker _
18          * @marker *
19          */
20         protected function parseEmphStrong($text)
21         {
22                 $marker = $text[0];
23
24                 if (!isset($text[1])) {
25                         return [['text', $text[0]], 1];
26                 }
27
28                 if ($marker == $text[1]) { // strong
29                         if ($marker == '*' && preg_match('/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', $text, $matches) ||
30                                 $marker == '_' && preg_match('/^__((?:[^_]|_[^_]*_)+?)__(?!_)/us', $text, $matches)) {
31
32                                 return [
33                                         [
34                                                 'strong',
35                                                 $this->parseInline($matches[1]),
36                                         ],
37                                         strlen($matches[0])
38                                 ];
39                         }
40                 } else { // emph
41                         if ($marker == '*' && preg_match('/^[*]((?:[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', $text, $matches) ||
42                                 $marker == '_' && preg_match('/^_((?:[^_]|__[^_]*__)+?)_(?!_)\b/us', $text, $matches)) {
43                                 return [
44                                         [
45                                                 'emph',
46                                                 $this->parseInline($matches[1]),
47                                         ],
48                                         strlen($matches[0])
49                                 ];
50                         }
51                 }
52                 return [['text', $text[0]], 1];
53         }
54
55         protected function renderStrong($block)
56         {
57                 return '<strong>' . $this->renderAbsy($block[1]) . '</strong>';
58         }
59
60         protected function renderEmph($block)
61         {
62                 return '<em>' . $this->renderAbsy($block[1]) . '</em>';
63         }
64 }