Skip to content

Issue #6415178: Add a creatable element for each tag used in styles.

Problem

It should be implicit that any tag used in Styles be allowed by the HTML filter. The Style plugin just isn't telling the validator which tags it creates.

In this case, Style::getElementsSubset returns these elements:

<span class="text-large">
<span class="text-primary">
<span class="text-secondary">

None of these are considered createable because they all have attributes.

The plain, creatable, element is missing, i.e.

<span>

Solution

To fix this, Style::getElementsSubset could add a plain element for each tag used in the styles list.

e.g.

  public function getElementsSubset(): array {
    $elements = array_column($this->configuration['styles'], 'element');

    // Add a creatable element for each tag used in styles.
    $ghs_config = HTMLRestrictions::fromString(implode($elements))->toGeneralHtmlSupportConfig();
    $tags = array_column($ghs_config, 'name');
    foreach ($tags as $tag) {
      $elements[] = "<{$tag}>";
    }

    return $elements;
  }

The tags and classes used in Styles are automatically added to/removed from the HTML filter's list of allowed HTML tags as the list of Styles is updated by the user.

Edited by Brad Treloar

Merge request reports

Loading