You are here

private function XBBCodeFilter::renderTag in Extensible BBCode 8.2

Render a single tag.

Parameters

$tag: The complete match object, including its name, content and attributes.

Return value

HTML code to insert in place of the tag and its content.

1 call to XBBCodeFilter::renderTag()
XBBCodeFilter::renderTree in src/Plugin/Filter/XBBCodeFilter.php

File

src/Plugin/Filter/XBBCodeFilter.php, line 222
Contains Drupal\xbbcode\Plugin\Filter\XBBCodeFilter.

Class

XBBCodeFilter
Provides a filter that converts BBCode to HTML.

Namespace

Drupal\xbbcode\Plugin\Filter

Code

private function renderTag(XBBCodeTagMatch $tag) {
  if ($callback = $this->tags[$tag->name]->callback) {
    return $callback($tag);
  }
  else {
    $replace['{content}'] = $tag->content;
    $replace['{source}'] = $tag->source;
    $replace['{option}'] = $tag->option;
    foreach ($tag->attrs as $name => $value) {
      $replace['{' . $name . '}'] = $value;
    }
    $markup = str_replace(array_keys($replace), array_values($replace), $this->tags[$tag->name]->markup);

    // Make sure that unset placeholders are replaced with empty strings.
    $markup = preg_replace('/{\\w+}/', '', $markup);
    return $markup;
  }
}