[ Index ]

PHP Cross Reference of phpBB-3.3.9-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/ -> InlineTextElements.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
   9  
  10  use DOMElement;
  11  
  12  class InlineTextElements extends AbstractNormalization
  13  {
  14      /**
  15      * {@inheritdoc}
  16      */
  17      protected $queries = ['//xsl:text[not(@disable-output-escaping="yes")]'];
  18  
  19      /**
  20      * Test whether an element is followed by a text node
  21      *
  22      * @param  DOMElement $element
  23      * @return bool
  24      */
  25  	protected function isFollowedByText(DOMElement $element)
  26      {
  27          return ($element->nextSibling && $element->nextSibling->nodeType === XML_TEXT_NODE);
  28      }
  29  
  30      /**
  31      * Test whether an element is preceded by a text node
  32      *
  33      * @param  DOMElement $element
  34      * @return bool
  35      */
  36  	protected function isPrecededByText(DOMElement $element)
  37      {
  38          return ($element->previousSibling && $element->previousSibling->nodeType === XML_TEXT_NODE);
  39      }
  40  
  41      /**
  42      * {@inheritdoc}
  43      */
  44  	protected function normalizeElement(DOMElement $element)
  45      {
  46          // If this node's content is whitespace, ensure it's preceded or followed by a text node
  47          if (trim($element->textContent) === '')
  48          {
  49              if (!$this->isFollowedByText($element) && !$this->isPrecededByText($element))
  50              {
  51                  // This would become inter-element whitespace, therefore we can't inline
  52                  return;
  53              }
  54          }
  55          $element->parentNode->replaceChild($this->createTextNode($element->textContent), $element);
  56      }
  57  }


Generated: Wed Dec 7 15:09:22 2022 Cross-referenced by PHPXref 0.7.1