Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
InlineCode.php
01 <?php
02
03 /**
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2022 The s9e authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Plugins\Litedown\Parser\Passes;
09
10 class InlineCode extends AbstractPass
11 {
12 /**
13 * {@inheritdoc}
14 */
15 public function parse()
16 {
17 $markers = $this->getInlineCodeMarkers();
18 $i = -1;
19 $cnt = count($markers);
20 while (++$i < ($cnt - 1))
21 {
22 $pos = $markers[$i]['next'];
23 $j = $i;
24 if ($this->text->charAt($markers[$i]['pos']) !== '`')
25 {
26 // Adjust the left marker if its first backtick was escaped
27 ++$markers[$i]['pos'];
28 --$markers[$i]['len'];
29 }
30 while (++$j < $cnt && $markers[$j]['pos'] === $pos)
31 {
32 if ($markers[$j]['len'] === $markers[$i]['len'])
33 {
34 $this->addInlineCodeTags($markers[$i], $markers[$j]);
35 $i = $j;
36 break;
37 }
38 $pos = $markers[$j]['next'];
39 }
40 }
41 }
42
43 /**
44 * Add the tag pair for an inline code span
45 *
46 * @param array $left Left marker
47 * @param array $right Right marker
48 * @return void
49 */
50 protected function addInlineCodeTags($left, $right)
51 {
52 $startPos = $left['pos'];
53 $startLen = $left['len'] + $left['trimAfter'];
54 $endPos = $right['pos'] - $right['trimBefore'];
55 $endLen = $right['len'] + $right['trimBefore'];
56 $this->parser->addTagPair('C', $startPos, $startLen, $endPos, $endLen);
57 $this->text->overwrite($startPos, $endPos + $endLen - $startPos);
58 }
59
60 /**
61 * Capture and return inline code markers
62 *
63 * @return array
64 */
65 protected function getInlineCodeMarkers()
66 {
67 $pos = $this->text->indexOf('`');
68 if ($pos === false)
69 {
70 return [];
71 }
72
73 preg_match_all(
74 '/(`+)(\\s*)[^\\x17`]*/',
75 str_replace("\x1BD", '\\`', $this->text),
76 $matches,
77 PREG_OFFSET_CAPTURE | PREG_SET_ORDER,
78 $pos
79 );
80 $trimNext = 0;
81 $markers = [];
82 foreach ($matches as $m)
83 {
84 $markers[] = [
85 'pos' => $m[0][1],
86 'len' => strlen($m[1][0]),
87 'trimBefore' => $trimNext,
88 'trimAfter' => strlen($m[2][0]),
89 'next' => $m[0][1] + strlen($m[0][0])
90 ];
91 $trimNext = strlen($m[0][0]) - strlen(rtrim($m[0][0]));
92 }
93
94 return $markers;
95 }
96 }