Make WordPress Core


Ignore:
Timestamp:
04/04/2023 10:04:45 AM (18 months ago)
Author:
Bernhard Reiter
Message:

HTML API: Add has_self_closing_flag() to Tag Processor.

In this patch we're adding has_self_closing_flag() to the HTML Tag Processor.
This exposes whether a currently-matched tag contains the self-closing flag /.

This information is critical for the evolution of the HTML API in order
to track and parse HTML structure, specifically, knowing whether an
HTML foreign element is self-closing or not.

Props dmsnell, zieladam.
Fixes #58009.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r55555 r55619  
    17581758
    17591759        return strtoupper( $tag_name );
     1760    }
     1761
     1762    /**
     1763     * Indicates if the currently matched tag contains the self-closing flag.
     1764     *
     1765     * No HTML elements ought to have the self-closing flag and for those, the self-closing
     1766     * flag will be ignored. For void elements this is benign because they "self close"
     1767     * automatically. For non-void HTML elements though problems will appear if someone
     1768     * intends to use a self-closing element in place of that element with an empty body.
     1769     * For HTML foreign elements and custom elements the self-closing flag determines if
     1770     * they self-close or not.
     1771     *
     1772     * This function does not determine if a tag is self-closing,
     1773     * but only if the self-closing flag is present in the syntax.
     1774     *
     1775     * @since 6.3.0
     1776     *
     1777     * @return bool Whether the currently matched tag contains the self-closing flag.
     1778     */
     1779    public function has_self_closing_flag() {
     1780        if ( ! $this->tag_name_starts_at ) {
     1781            return false;
     1782        }
     1783
     1784        return '/' === $this->html[ $this->tag_ends_at - 1 ];
    17601785    }
    17611786
Note: See TracChangeset for help on using the changeset viewer.