[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/Litedown/Parser/Passes/ -> InlineCode.php (source)

   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  class InlineCode extends AbstractPass
  10  {
  11  	public function parse()
  12      {
  13          $markers = $this->getInlineCodeMarkers();
  14          $i       = -1;
  15          $cnt     = \count($markers);
  16          while (++$i < ($cnt - 1))
  17          {
  18              $pos = $markers[$i]['next'];
  19              $j   = $i;
  20              if ($this->text->charAt($markers[$i]['pos']) !== '`')
  21              {
  22                  ++$markers[$i]['pos'];
  23                  --$markers[$i]['len'];
  24              }
  25              while (++$j < $cnt && $markers[$j]['pos'] === $pos)
  26              {
  27                  if ($markers[$j]['len'] === $markers[$i]['len'])
  28                  {
  29                      $this->addInlineCodeTags($markers[$i], $markers[$j]);
  30                      $i = $j;
  31                      break;
  32                  }
  33                  $pos = $markers[$j]['next'];
  34              }
  35          }
  36      }
  37  	protected function addInlineCodeTags($left, $right)
  38      {
  39          $startPos = $left['pos'];
  40          $startLen = $left['len'] + $left['trimAfter'];
  41          $endPos   = $right['pos'] - $right['trimBefore'];
  42          $endLen   = $right['len'] + $right['trimBefore'];
  43          $this->parser->addTagPair('C', $startPos, $startLen, $endPos, $endLen);
  44          $this->text->overwrite($startPos, $endPos + $endLen - $startPos);
  45      }
  46  	protected function getInlineCodeMarkers()
  47      {
  48          $pos = $this->text->indexOf('`');
  49          if ($pos === \false)
  50              return [];
  51          \preg_match_all(
  52              '/(`+)(\\s*)[^\\x17`]*/',
  53              \str_replace("\x1BB", '\\`', $this->text),
  54              $matches,
  55              \PREG_OFFSET_CAPTURE | \PREG_SET_ORDER,
  56              $pos
  57          );
  58          $trimNext = 0;
  59          $markers  = [];
  60          foreach ($matches as $m)
  61          {
  62              $markers[] = [
  63                  'pos'        => $m[0][1],
  64                  'len'        => \strlen($m[1][0]),
  65                  'trimBefore' => $trimNext,
  66                  'trimAfter'  => \strlen($m[2][0]),
  67                  'next'       => $m[0][1] + \strlen($m[0][0])
  68              ];
  69              $trimNext = \strlen($m[0][0]) - \strlen(\rtrim($m[0][0]));
  70          }
  71          return $markers;
  72      }
  73  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1