[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

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

   1  function parse()
   2  {
   3      if (text.indexOf('](') !== -1)
   4      {
   5          parseInlineLinks();
   6      }
   7      if (hasReferences)
   8      {
   9          parseReferenceLinks();
  10      }
  11  }
  12  
  13  /**
  14  * Add an image tag for given text span
  15  *
  16  * @param {number} startPos Start tag position
  17  * @param {number} endPos   End tag position
  18  * @param {number} endLen   End tag length
  19  * @param {string} linkInfo URL optionally followed by space and a title
  20  */
  21  function addLinkTag(startPos, endPos, endLen, linkInfo)
  22  {
  23      // Give the link a slightly worse priority if this is a implicit reference and a slightly
  24      // better priority if it's an explicit reference or an inline link or to give it precedence
  25      // over possible BBCodes such as [b](https://en.wikipedia.org/wiki/B)
  26      var priority = (endLen === 1) ? 1 : -1;
  27  
  28      var tag = addTagPair('URL', startPos, 1, endPos, endLen, priority);
  29      setLinkAttributes(tag, linkInfo, 'url');
  30  
  31      // Overwrite the markup without touching the link's text
  32      overwrite(startPos, 1);
  33      overwrite(endPos,   endLen);
  34  }
  35  
  36  /**
  37  * Capture and return labels used in current text
  38  *
  39  * @return {!Object} Labels' text position as keys, lowercased text content as values
  40  */
  41  function getLabels()
  42  {
  43      var labels = {}, m, regexp = /\[((?:[^\x17[\]]|\[[^\x17[\]]*\])*)\]/g;
  44      while (m = regexp.exec(text))
  45      {
  46          labels[m['index']] = m[1].toLowerCase();
  47      }
  48  
  49      return labels;
  50  }
  51  
  52  /**
  53  * Parse inline links markup
  54  */
  55  function parseInlineLinks()
  56  {
  57      var m, regexp = /\[(?:[^\x17[\]]|\[[^\x17[\]]*\])*\]\(( *(?:[^\x17\s()]|\([^\x17\s()]*\))*(?=[ )]) *(?:"[^\x17]*?"|'[^\x17]*?'|\([^\x17)]*\))? *)\)/g;
  58      while (m = regexp.exec(text))
  59      {
  60          var linkInfo = m[1],
  61              startPos = +m['index'],
  62              endLen   = 3 + linkInfo.length,
  63              endPos   = startPos + m[0].length - endLen;
  64  
  65          addLinkTag(startPos, endPos, endLen, linkInfo);
  66      }
  67  }
  68  
  69  /**
  70  * Parse reference links markup
  71  */
  72  function parseReferenceLinks()
  73  {
  74      var labels = getLabels(), startPos;
  75      for (startPos in labels)
  76      {
  77          var id       = labels[startPos],
  78              labelPos = +startPos + 2 + id.length,
  79              endPos   = labelPos - 1,
  80              endLen   = 1;
  81  
  82          if (text[labelPos] === ' ')
  83          {
  84              ++labelPos;
  85          }
  86          if (labels[labelPos] > '' && linkReferences[labels[labelPos]])
  87          {
  88              id     = labels[labelPos];
  89              endLen = labelPos + 2 + id.length - endPos;
  90          }
  91          if (linkReferences[id])
  92          {
  93              addLinkTag(+startPos, endPos, endLen, linkReferences[id]);
  94          }
  95      }
  96  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1