Remove all references to "self-closing" void elements in core

Created on 30 December 2011, over 13 years ago
Updated 22 August 2024, 8 months ago

Follow-up from #552478: Restrict "self-closing" tags to only void elements in drupal_pre_render_html_tag .

Motivation

HTML5 does not actually implement the concept of "self-closing tags". It is a relic from XHTML. From http://www.w3.org/TR/html5/syntax.html#syntax-start-tag:

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single "/" (U+002F) character. This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

It has "no effect on void elements", meaning it is ignored when being parsed.

Proposed resolution

Remove all unnecessary / characters from void elements in core-provided templates, documentation, sources and output:
area, base, br, col, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

This DOES NOT (and should not) include user generated content. For example, if a content editor inserts a <br /> tag into a body of a node, it should be preserved by filter as is.

Remaining tasks

  • Document self-closing tags usage in coding standards both for HTML and JS.
    Documentation should clearly describe the difference between void tags and foreign elements, as well as the usage of <div /> syntax in JS.
  • Can templates in stable theme be modified in minor release?
  • Remove self-closing void tags from output of filter module without breaking its current behavior.
    Filters should not forcibly remove the closing slash if it is added by user, but they should not forcibly add it in either.
  • Reconfigure editor to not generate these tags in content and update tests in editor module.
  • Test the behavior of Drupal\Core\Mail\MailFormatHelper::htmlToText to make sure that it can transform both cases.
  • Update XSS filtering tests to verify that they cover both normal and self-closing void tags (i.e. core/tests/Drupal/Tests/Component/Utility/XssTest.php).
  • Decide if it is necessary to remove self-closing tags from test fixtures.

A quote from @sun's comment #48 on migrations:

The D6 source configuration may contain self-closing tags, so migration tests should not be changed.

That said, perhaps we want to process such config in a way to automatically adjust self-closing tags during the migration, but that should be discussed in a separate/dedicated issue.

User interface changes

None

API changes

None

Template changes

Changes in stable, classy, bartik theme templates and default module templates.

Original report by @tim.plunkett

There are 11 uses of <br> in core, and 87 of <br />. I've never once used the latter, and both are valid HTML: http://dev.w3.org/html5/spec-author-view/syntax.html#syntax-start-tag

I propose core switch everything to <br>.

Either way, we should pick one for core, and clarify in the coding standards that one is preferred but both are allowed.

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Markup 

Last updated 18 days ago

No maintainer
Created by

🇺🇸United States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
  • html5

    Implements and supports the use of HTML5.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024