[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2019 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 use s9e\TextFormatter\Plugins\Litedown\Parser\LinkAttributesSetter; 10 class Links extends AbstractPass 11 { 12 use LinkAttributesSetter; 13 public function parse() 14 { 15 if ($this->text->indexOf('](') !== \false) 16 $this->parseInlineLinks(); 17 if ($this->text->hasReferences) 18 $this->parseReferenceLinks(); 19 } 20 protected function addLinkTag($startPos, $endPos, $endLen, $linkInfo) 21 { 22 $priority = ($endLen === 1) ? 1 : -1; 23 $tag = $this->parser->addTagPair('URL', $startPos, 1, $endPos, $endLen, $priority); 24 $this->setLinkAttributes($tag, $linkInfo, 'url'); 25 $this->text->overwrite($startPos, 1); 26 $this->text->overwrite($endPos, $endLen); 27 } 28 protected function getLabels() 29 { 30 \preg_match_all( 31 '/\\[((?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*)\\]/', 32 $this->text, 33 $matches, 34 \PREG_OFFSET_CAPTURE 35 ); 36 $labels = []; 37 foreach ($matches[1] as $m) 38 $labels[$m[1] - 1] = \strtolower($m[0]); 39 return $labels; 40 } 41 protected function parseInlineLinks() 42 { 43 \preg_match_all( 44 '/\\[(?:[^\\x17[\\]]|\\[[^\\x17[\\]]*\\])*\\]\\(( *(?:[^\\x17\\s()]|\\([^\\x17\\s()]*\\))*(?=[ )]) *(?:"[^\\x17]*?"|\'[^\\x17]*?\'|\\([^\\x17)]*\\))? *)\\)/', 45 $this->text, 46 $matches, 47 \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER 48 ); 49 foreach ($matches as $m) 50 { 51 $linkInfo = $m[1][0]; 52 $startPos = $m[0][1]; 53 $endLen = 3 + \strlen($linkInfo); 54 $endPos = $startPos + \strlen($m[0][0]) - $endLen; 55 $this->addLinkTag($startPos, $endPos, $endLen, $linkInfo); 56 } 57 } 58 protected function parseReferenceLinks() 59 { 60 $labels = $this->getLabels(); 61 foreach ($labels as $startPos => $id) 62 { 63 $labelPos = $startPos + 2 + \strlen($id); 64 $endPos = $labelPos - 1; 65 $endLen = 1; 66 if ($this->text->charAt($labelPos) === ' ') 67 ++$labelPos; 68 if (isset($labels[$labelPos], $this->text->linkReferences[$labels[$labelPos]])) 69 { 70 $id = $labels[$labelPos]; 71 $endLen = $labelPos + 2 + \strlen($id) - $endPos; 72 } 73 if (isset($this->text->linkReferences[$id])) 74 $this->addLinkTag($startPos, $endPos, $endLen, $this->text->linkReferences[$id]); 75 } 76 } 77 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |