[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Plugins\Litedown\Parser\Passes; 9 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |