You are here

public static function FilterHtml::tagsToString in Markdown 8.2

Converts an array of tags (and their potential attributes) to a string.

Parameters

array $tags: An associative array of tags, where the key is the tag and the value can be a boolean (TRUE if allowed, FALSE otherwise) or an associative array containing key/value pairs of acceptable boolean based attribute values (i.e. 'dir' => ['ltr' => TRUE, 'rtl' => TRUE]).

Return value

string The tags, in string format.

2 calls to FilterHtml::tagsToString()
FilterHtml::getAllowedHtml in src/Util/FilterHtml.php
Retrieves the allowed HTML.
ParserConfigurationForm::buildRenderStrategy in src/Form/ParserConfigurationForm.php
Builds the render strategy for a specific parser.

File

src/Util/FilterHtml.php, line 226

Class

FilterHtml
Extends FilterHtml to allow more more permissive global attributes.

Namespace

Drupal\markdown\Util

Code

public static function tagsToString(array $tags = []) {
  $items = [];
  ksort($tags);
  foreach (static::normalizeTags($tags) as $tag => $attributes) {
    $tag = "<{$tag}";
    if (is_array($attributes)) {
      foreach ($attributes as $attribute => $value) {
        if (!$value) {
          continue;
        }
        $tag .= " {$attribute}";
        if ($value && $value !== TRUE) {
          if (is_array($value)) {
            $value = implode(' ', array_keys(array_filter($value)));
          }
          $tag .= "='{$value}'";
        }
      }
    }
    $tag .= '>';
    $items[] = $tag;
  }
  return implode(' ', $items);
}