function HTMLRestrictions::getTextContainerElementList

Same name in other branches
  1. 9 core/modules/ckeditor5/src/HTMLRestrictions.php \Drupal\ckeditor5\HTMLRestrictions::getTextContainerElementList()
  2. 10 core/modules/ckeditor5/src/HTMLRestrictions.php \Drupal\ckeditor5\HTMLRestrictions::getTextContainerElementList()

Gets a list of CKEditor 5's `$block` text container elements.

This is a hard coded list of known elements that CKEditor 5 uses as `$block` text container elements. The elements listed here are registered with `inheritAllFrom: "$block"` to the CKEditor 5 schema. This list corresponds to the `$text-container` wildcard in Drupal configuration.

This group of elements is special because they allow text as an immediate child node. These elements are also allowed to be used for text styles that must be applied to the wrapper instead of inline to the text, such as text alignment.

This list is highly opinionated. It is based on decisions made upstream in CKEditor 5. For example, `<blockquote>` is not considered as a `$block` text container, meaning that text inside `<blockquote>` needs to always be wrapped by an element that is `$block` text container such as `<p>`. This list also excludes some special case text container elements like `<caption>` that allow containing text directly inside the element, yet do not fully implement the `$block` text container interface.

It is acceptable to list the elements here because the list of elements is not likely to change often. If the list changed, an upgrade path would be required anyway. In most cases, missing elements would only impact new functionality shipped in upstream.

Return value

string[] An array of block-level element tags.

See also

https://ckeditor.com/docs/ckeditor5/latest/framework/guides/deep-dive/s…

File

core/modules/ckeditor5/src/HTMLRestrictions.php, line 1361

Class

HTMLRestrictions
Represents a set of HTML restrictions.

Namespace

Drupal\ckeditor5

Code

private static function getTextContainerElementList() : array {
    return [
        'div',
        'p',
        'h1',
        'h2',
        'h3',
        'h4',
        'h5',
        'h6',
        'pre',
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.