[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

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

   1  function parse()
   2  {
   3      var markers = getInlineCodeMarkers(),
   4          i       = -1,
   5          cnt     = markers.length;
   6      while (++i < (cnt - 1))
   7      {
   8          var pos = markers[i].next,
   9              j   = i;
  10          if (text[markers[i].pos] !== '`')
  11          {
  12              // Adjust the left marker if its first backtick was escaped
  13              ++markers[i].pos;
  14              --markers[i].len;
  15          }
  16          while (++j < cnt && markers[j].pos === pos)
  17          {
  18              if (markers[j].len === markers[i].len)
  19              {
  20                  addInlineCodeTags(markers[i], markers[j]);
  21                  i = j;
  22                  break;
  23              }
  24              pos = markers[j].next;
  25          }
  26      }
  27  }
  28  
  29  /**
  30  * Add the tag pair for an inline code span
  31  *
  32  * @param {!Object} left  Left marker
  33  * @param {!Object} right Right marker
  34  */
  35  function addInlineCodeTags(left, right)
  36  {
  37      var startPos = left.pos,
  38          startLen = left.len + left.trimAfter,
  39          endPos   = right.pos - right.trimBefore,
  40          endLen   = right.len + right.trimBefore;
  41      addTagPair('C', startPos, startLen, endPos, endLen);
  42      overwrite(startPos, endPos + endLen - startPos);
  43  }
  44  
  45  
  46  /**
  47  * Capture and return inline code markers
  48  *
  49  * @return {!Array<!Object>}
  50  */
  51  function getInlineCodeMarkers()
  52  {
  53      var pos = text.indexOf('`');
  54      if (pos < 0)
  55      {
  56          return [];
  57      }
  58  
  59      var regexp   = /(`+)(\s*)[^\x17`]*/g,
  60          trimNext = 0,
  61          markers  = [],
  62          _text    = text.replace(/\x1BB/g, '\\`'),
  63          m;
  64      regexp.lastIndex = pos;
  65      while (m = regexp.exec(_text))
  66      {
  67          markers.push({
  68              pos        : +m['index'],
  69              len        : m[1].length,
  70              trimBefore : trimNext,
  71              trimAfter  : m[2].length,
  72              next       : m['index'] + m[0].length
  73          });
  74          trimNext = m[0].length - m[0].replace(/\s+$/, '').length;
  75      }
  76  
  77      return markers;
  78  }


Generated: Sat Oct 26 11:28:42 2019 Cross-referenced by PHPXref 0.7.1