[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/html-api/ -> class-wp-html-doctype-info.php (summary)

HTML API: WP_HTML_Doctype_Info class

File Size: 616 lines (25 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_HTML_Doctype_Info:: (2 methods):
  __construct()
  from_doctype_token()


Class: WP_HTML_Doctype_Info  - X-Ref

Core class used by the HTML API to represent a DOCTYPE declaration.

This class parses DOCTYPE tokens for the full parser in the HTML Processor.
Most code interacting with HTML won't need to parse DOCTYPE declarations;
the HTML Processor is one exception. Consult the HTML Processor for proper
parsing of an HTML document.

A DOCTYPE declaration may indicate its document compatibility mode, which impacts
the structure of the following HTML as well as the behavior of CSS class selectors.
There are three possible modes:

- "no-quirks" and "limited-quirks" modes (also called "standards mode").
- "quirks" mode.

These modes mostly determine whether CSS class name selectors match values in the
HTML `class` attribute in an ASCII-case-insensitive way (quirks mode), or whether
they match only when byte-for-byte identical (no-quirks mode).

All HTML documents should start with the standard HTML5 DOCTYPE: `<!DOCTYPE html>`.

> DOCTYPEs are required for legacy reasons. When omitted, browsers tend to use a different
> rendering mode that is incompatible with some specifications. Including the DOCTYPE in a
> document ensures that the browser makes a best-effort attempt at following the
> relevant specifications.

__construct(?string $name,?string $public_identifier,?string $system_identifier,bool $force_quirks_flag)   X-Ref
Constructor.

This class should not be instantiated directly.
Use the static {@see self::from_doctype_token} method instead.

The arguments to this constructor correspond to the "DOCTYPE token"
as defined in the HTML specification.

> DOCTYPE tokens have a name, a public identifier, a system identifier,
> and a force-quirks flag. When a DOCTYPE token is created, its name, public identifier,
> and system identifier must be marked as missing (which is a distinct state from the
> empty string), and the force-quirks flag must be set to off (its other state is on).

param: string|null $name              Name of the DOCTYPE.
param: string|null $public_identifier Public identifier of the DOCTYPE.
param: string|null $system_identifier System identifier of the DOCTYPE.
param: bool        $force_quirks_flag Whether the force-quirks flag is set for the token.

from_doctype_token( string $doctype_html )   X-Ref
Creates a WP_HTML_Doctype_Info instance by parsing a raw DOCTYPE declaration token.

Use this method to parse a DOCTYPE declaration token and get access to its properties
via the returned WP_HTML_Doctype_Info class instance. The provided input must parse
properly as a DOCTYPE declaration, though it must not represent a valid DOCTYPE.

Example:

// Normative HTML DOCTYPE declaration.
$doctype = WP_HTML_Doctype_Info::from_doctype_token( '<!DOCTYPE html>' );
'no-quirks' === $doctype->indicated_compatability_mode;

// A nonsensical DOCTYPE is still valid, and will indicate "quirks" mode.
$doctype = WP_HTML_Doctype_Info::from_doctype_token( '<!doctypeJSON SILLY "nonsense\'>' );
'quirks' === $doctype->indicated_compatability_mode;

// Textual quirks present in raw HTML are handled appropriately.
$doctype = WP_HTML_Doctype_Info::from_doctype_token( "<!DOCTYPE\nhtml\n>" );
'no-quirks' === $doctype->indicated_compatability_mode;

// Anything other than a proper DOCTYPE declaration token fails to parse.
null === WP_HTML_Doctype_Info::from_doctype_token( ' <!DOCTYPE>' );
null === WP_HTML_Doctype_Info::from_doctype_token( '<!DOCTYPE ><p>' );
null === WP_HTML_Doctype_Info::from_doctype_token( '<!TYPEDOC>' );
null === WP_HTML_Doctype_Info::from_doctype_token( 'html' );
null === WP_HTML_Doctype_Info::from_doctype_token( '<?xml version="1.0" encoding="UTF-8" ?>' );

return: WP_HTML_Doctype_Info|null A WP_HTML_Doctype_Info instance will be returned if the
param: string $doctype_html The complete raw DOCTYPE HTML string, e.g. `<!DOCTYPE html>`.



Generated : Thu Oct 24 08:20:01 2024 Cross-referenced by PHPXref