You are here

public static function XBBCodeFilter::decodeHtml in Extensible BBCode 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/Filter/XBBCodeFilter.php \Drupal\xbbcode\Plugin\Filter\XBBCodeFilter::decodeHtml()

Reverse HTML encoding that other filters may have applied.

The "option" and "attribute" values are provided to plugins as raw input (and will be filtered by them before printing).

Parameters

\Drupal\xbbcode\Parser\Tree\NodeElementInterface $tree: The parse tree.

1 call to XBBCodeFilter::decodeHtml()
XBBCodeFilter::process in src/Plugin/Filter/XBBCodeFilter.php
Performs the filter processing.

File

src/Plugin/Filter/XBBCodeFilter.php, line 291

Class

XBBCodeFilter
Provides a filter that converts BBCode to HTML.

Namespace

Drupal\xbbcode\Plugin\Filter

Code

public static function decodeHtml(NodeElementInterface $tree) : void {
  $filter = static function (string $text) : string {

    // If the string is free of raw HTML, decode its entities.
    if (!preg_match('/[<>"\']/', $text)) {
      $text = Html::decodeEntities($text);
    }
    return $text;
  };
  foreach ($tree
    ->getDescendants() as $node) {
    if ($node instanceof TagElementInterface) {
      $node
        ->setOption($filter($node
        ->getOption()));
      $node
        ->setAttributes(array_map($filter, $node
        ->getAttributes()));
      $node
        ->setSource($filter($node
        ->getSource()));
    }
  }
}