[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Plugins/HTMLElements/ -> Parser.js (source)

   1  matches.forEach(function(m)
   2  {
   3      // Test whether this is an end tag
   4      var isEnd = (text[m[0][1] + 1] === '/');
   5  
   6      var pos    = m[0][1],
   7          len    = m[0][0].length,
   8          elName = m[2 - isEnd][0].toLowerCase();
   9  
  10      // Use the element's alias if applicable, or the  name of the element (with the
  11      // configured prefix) otherwise
  12      var tagName = (config.aliases && config.aliases[elName] && config.aliases[elName][''])
  13                  ? config.aliases[elName]['']
  14                  : config.prefix + ':' + elName;
  15  
  16      if (isEnd)
  17      {
  18          addEndTag(tagName, pos, len);
  19  
  20          return;
  21      }
  22  
  23      // Test whether it's a self-closing tag or a start tag.
  24      //
  25      // A self-closing tag will become one start tag consuming all of the text followed by a
  26      // 0-width end tag. Alternatively, it could be replaced by a pair of 0-width tags plus
  27      // an ignore tag to prevent the text in between from being output
  28      var tag = (/(<\S+|['"\s])\/>$/.test(m[0][0]))
  29              ? addTagPair(tagName, pos, len, pos + len, 0)
  30              : addStartTag(tagName, pos, len);
  31  
  32      captureAttributes(tag, elName, m[3][0]);
  33  });
  34  
  35  /**
  36  * Capture all attributes in given string
  37  *
  38  * @param  {!Tag}    tag    Target tag
  39  * @param  {string} elName Name of the HTML element
  40  * @param  {string} str    String containing the attribute declarations
  41  */
  42  function captureAttributes(tag, elName, str)
  43  {
  44      var regexp = /([a-z][-a-z0-9]*)(?:\s*=\s*("[^"]*"|'[^']*'|[^\s"'=<>`]+))?/gi,
  45          attrName,
  46          attrValue,
  47          m;
  48  
  49      while (m = regexp.exec(str))
  50      {
  51          /**
  52          * If there's no value, it's a boolean attribute and we generate a value equal
  53          * to the attribute's name, lowercased
  54          *
  55          * @link http://www.w3.org/html/wg/drafts/html/master/single-page.html#boolean-attributes
  56          */
  57          attrName  = m[1].toLowerCase();
  58          attrValue = (typeof m[2] !== 'undefined') ? m[2] : attrName;
  59  
  60          // Use the attribute's alias if applicable
  61          if (HINT.HTMLELEMENTS_HAS_ALIASES && config.aliases && config.aliases[elName] && config.aliases[elName][attrName])
  62          {
  63              attrName = config.aliases[elName][attrName];
  64          }
  65  
  66          // Remove quotes around the value
  67          if (/^["']/.test(attrValue))
  68          {
  69              attrValue = attrValue.substring(1, attrValue.length - 1);
  70          }
  71  
  72          tag.setAttribute(attrName, html_entity_decode(attrValue));
  73      }
  74  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1