Dustin Wilson
3 years ago
24 changed files with 2530 additions and 21 deletions
File diff suppressed because it is too large
@ -0,0 +1,13 @@ |
|||
{ |
|||
"title": "HTML", |
|||
"tagline": "Tools for parsing and printing HTML5 documents and fragments.", |
|||
"author": "Dustin Wilson", |
|||
"languages": { |
|||
"en": "English" |
|||
}, |
|||
"html": { |
|||
"float": false, |
|||
"toggle_code": false, |
|||
"search": false |
|||
} |
|||
} |
@ -0,0 +1 @@ |
|||
HTML is a library which provides tools for parsing and printing of HTML5 documents and fragments. Unlike PHP's DOM and other similar libraries the goal of the project is to parse HTML as accurate to the specification as possible given the limitations of PHP's DOM and of the uses of the library. Therefore, there is no scripting in this implementation, and there likely never will be. |
@ -0,0 +1,8 @@ |
|||
We try to make the installation of the MensBeam HTML library as easy and straightforward as possible. |
|||
|
|||
## Requirements ## |
|||
|
|||
HTML intentionally has few requirements. It only requires PHP 7.1.0 or later with the [dom](http://php.net/manual/en/book.dom.php) extension installed. It is recommended to install the [ctype](https://www.php.net/manual/en/book.ctype.php) extension for performance improvements, but it is not required. |
|||
|
|||
TODO: Add Installation instructions once there are releases and a package is available on Packagist. |
|||
|
@ -0,0 +1,28 @@ |
|||
--- |
|||
title: Document::__construct |
|||
--- |
|||
|
|||
Document::__construct — Creates a new Document object |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::__construct ( ) |
|||
``` |
|||
|
|||
Creates a new Document object. |
|||
|
|||
## Examples ## |
|||
|
|||
**Example \#1 Creating a new Document** |
|||
|
|||
```php |
|||
<?php |
|||
|
|||
namespace MensBeam\HTML; |
|||
|
|||
$dom = new Document(); |
|||
echo $dom; |
|||
|
|||
?> |
|||
``` |
@ -0,0 +1,13 @@ |
|||
--- |
|||
title: Document::createEntityReference |
|||
--- |
|||
|
|||
Document::createEntityReference — **DISABLED** |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::createEntityReference ( string $name ) : false |
|||
``` |
|||
|
|||
This function has been disabled and will always return `false`. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). DOM4 does not have entity references or entity nodes. |
@ -0,0 +1,46 @@ |
|||
--- |
|||
title: Document::load |
|||
--- |
|||
|
|||
Document::load — Load HTML from a file |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::load ( string $filename , null $options = null , string|null $encodingOrContentType = null ) : bool |
|||
``` |
|||
|
|||
Loads an HTML document from a file. |
|||
|
|||
## Parameters ## |
|||
|
|||
<dl> |
|||
<dt><code>filename</code></dt> |
|||
<dd>The path to the HTML document.</dd> |
|||
|
|||
<dt><code>options</code></dt> |
|||
<dd>Always <code>null</code>. Was used for option constants in <a href="https://www.php.net/manual/en/class.domdocument.php"><code>\DOMDocument</code></a>.</dd> |
|||
|
|||
<dt><code>encodingOrContentType</code></dt> |
|||
<dd>The encoding of the document that is being loaded. If not specified it will be determined automatically.</dd> |
|||
</dl> |
|||
|
|||
## Return Values ## |
|||
|
|||
Returns <code>true</code> on success or <code>false</code> on failure. |
|||
|
|||
## Examples ## |
|||
|
|||
**Example \#1 Creating a Document** |
|||
|
|||
```php |
|||
<?php |
|||
|
|||
namespace MensBeam\HTML; |
|||
|
|||
$dom = new Document(); |
|||
$dom->load('ook.html'); |
|||
echo $dom; |
|||
|
|||
?> |
|||
``` |
@ -0,0 +1,46 @@ |
|||
--- |
|||
title: Document::loadHTML |
|||
--- |
|||
|
|||
Document::loadHTML — Load HTML from a string |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::loadHTML ( string $source , null $options = null , string|null $encodingOrContentType = null ) : bool |
|||
``` |
|||
|
|||
The function parses the HTML contained in the string <var>source</var>. |
|||
|
|||
## Parameters ## |
|||
|
|||
<dl> |
|||
<dt><code>source</code></dt> |
|||
<dd>The HTML string.</dd> |
|||
|
|||
<dt><code>options</code></dt> |
|||
<dd>Always <code>null</code>. Was used for option constants in <a href="https://www.php.net/manual/en/class.domdocument.php"><code>\DOMDocument</code></a>.</dd> |
|||
|
|||
<dt><code>encodingOrContentType</code></dt> |
|||
<dd>The encoding of the document that is being loaded. If not specified it will be determined automatically.</dd> |
|||
</dl> |
|||
|
|||
## Return Values ## |
|||
|
|||
Returns <code>true</code> on success or <code>false</code> on failure. |
|||
|
|||
## Examples ## |
|||
|
|||
**Example \#1 Creating a Document** |
|||
|
|||
```php |
|||
<?php |
|||
|
|||
namespace MensBeam\HTML; |
|||
|
|||
$dom = new Document(); |
|||
$dom->loadHTML('<!DOCTYPE html><html><head><title>Ook!</title></head><body><h1>Eek</h1></body></html>'); |
|||
echo $dom; |
|||
|
|||
?> |
|||
``` |
@ -0,0 +1,9 @@ |
|||
--- |
|||
title: Document::loadHTMLFile |
|||
--- |
|||
|
|||
Document::loadHTMLFile — Alias of <a href="Document_load.html"><code>Document::load()</code></a> |
|||
|
|||
## Description ## |
|||
|
|||
This function is an alias of <a href="Document_load.html"><code>Document::load()</code></a>. |
@ -0,0 +1,13 @@ |
|||
--- |
|||
title: Document::loadXML |
|||
--- |
|||
|
|||
Document::loadXML — **DISABLED** |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::loadXML ( string $source , null $options = null ) : false |
|||
``` |
|||
|
|||
This function has been disabled and will always return `false`. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). |
@ -0,0 +1,43 @@ |
|||
--- |
|||
title: Document::save |
|||
--- |
|||
|
|||
Document::save — Serializes the DOM tree into a file |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::save ( string $filename , null $options = null ) : int|false |
|||
``` |
|||
|
|||
Creates an HTML document from the DOM representation. |
|||
|
|||
## Parameters ## |
|||
|
|||
<dl> |
|||
<dt><code>filename</code></dt> |
|||
<dd>The path to the saved HTML document</dd> |
|||
|
|||
<dt><code>options</code></dt> |
|||
<dd>Always <code>null</code>. Was used for option constants in <a href="https://www.php.net/manual/en/class.domdocument.php"><code>\DOMDocument</code></a>.</dd> |
|||
</dl> |
|||
|
|||
## Return Values ## |
|||
|
|||
Returns the number of bytes written or <code>false</code> on failure. |
|||
|
|||
## Examples ## |
|||
|
|||
**Example \#1 Saving a DOM tree into a file** |
|||
|
|||
```php |
|||
<?php |
|||
|
|||
namespace MensBeam\HTML; |
|||
|
|||
$dom = new Document(); |
|||
$dom->loadHTML('<!DOCTYPE html><html><head><title>Ook!</title></head><body><h1>Eek</h1></body></html>'); |
|||
echo 'Wrote: ' . $dom->save('/tmp/test.html') . ' bytes'; // Wrote: 85 bytes |
|||
|
|||
?> |
|||
``` |
@ -0,0 +1,9 @@ |
|||
--- |
|||
title: Document::saveHTMLFile |
|||
--- |
|||
|
|||
Document::saveHTMLFile — Alias of <a href="Document_save.html"><code>Document::save()</code></a> |
|||
|
|||
## Description ## |
|||
|
|||
This function is an alias of <a href="Document_save.html"><code>Document::save()</code></a>. |
@ -0,0 +1,13 @@ |
|||
--- |
|||
title: Document::saveXML |
|||
--- |
|||
|
|||
Document::saveXML — **DISABLED** |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::saveXML ( DOMNode|null $node = null , null $options = null ) : false |
|||
``` |
|||
|
|||
This function has been disabled and will always return `false`. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). |
@ -0,0 +1,13 @@ |
|||
--- |
|||
title: Document::validate |
|||
--- |
|||
|
|||
Document::validate — **DISABLED** |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::validate ( ) : true |
|||
``` |
|||
|
|||
This function has been disabled and will always return `true`. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). |
@ -0,0 +1,13 @@ |
|||
--- |
|||
title: Document::xinclude |
|||
--- |
|||
|
|||
Document::xinclude — **DISABLED** |
|||
|
|||
## Description ## |
|||
|
|||
```php |
|||
public Document::xinclude ( null $options = null ) : false |
|||
``` |
|||
|
|||
This function has been disabled and will always return `false`. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). |
@ -0,0 +1,97 @@ |
|||
--- |
|||
title: Document |
|||
--- |
|||
|
|||
# The Document class # |
|||
|
|||
## Introduction ## |
|||
|
|||
Represents an entire HTML document; serves as the root of the document tree. Unlike the PHP [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php) class in which it inherits from it cannot be used to represent an XML document. It is strictly used to represent HTML. |
|||
|
|||
<div class="info"><p><strong>Info</strong> Only new methods and methods which make outward-facing changes from <a href="https://www.php.net/manual/en/class.domdocument.php">\DOMDocument</a> will be documented here, otherwise they will be linked back to PHP's documentation.</p></div> |
|||
|
|||
<pre><code class="php">MensBeam\HTML\Document extends <a href="https://www.php.net/manual/en/class.domdocument.php">\DOMDocument</a> { |
|||
|
|||
/* Constants */ |
|||
public const NO_QUIRKS_MODE = 0 ; |
|||
public const QUIRKS_MODE = 1 ; |
|||
public const LIMITED_QUIRKS_MODE = 2 ; |
|||
|
|||
/* Properties */ |
|||
public string|null $documentEncoding = null ; |
|||
public int $quirksMode = 0 ; |
|||
|
|||
/* Inherited properties from <a href="https://www.php.net/manual/en/class.domdocument.php">\DOMDocument</a> */ |
|||
public readonly DocumentType <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.doctype">$doctype</a> ; |
|||
public readonly Element <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.documentelement">$documentElement</a> ; |
|||
public string|null <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.documenturi">$documentURI</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domimplementation.php">DOMImplementation</a> <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.implementation">$implementation</a> ; |
|||
|
|||
/* Inherited properties from <a href="https://www.php.net/manual/en/class.domnode.php">\DOMNode</a> */ |
|||
public readonly string <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.nodename">$nodeName</a> ; |
|||
public string <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.nodevalue">$nodeValue</a> ; |
|||
public readonly int <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.nodetype">$nodeType</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnode.php">DOMNode</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.parentnode">$parentNode</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnodelist.php">DOMNodeList</a> <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.childnodes">$childNodes</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnode.php">DOMNode</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.firstchild">$firstChild</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnode.php">DOMNode</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.lastchild">$lastChild</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnode.php">DOMNode</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.previoussibling">$previousSibling</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnode.php">DOMNode</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.nextsibling">$nextSibling</a> ; |
|||
public readonly \<a href="https://www.php.net/manual/en/class.domnamednodemap.php">DOMNamedNodeMap</a>|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.attributes">$attributes</a> ; |
|||
public readonly Document|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.ownerdocument">$ownerDocument</a> ; |
|||
public readonly string|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.namespaceuri">$namespaceURI</a> ; |
|||
public string <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.prefix">$prefix</a> ; |
|||
public readonly string <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.localname">$localName</a> ; |
|||
public readonly string|null <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.baseuri">$baseURI</a> ; |
|||
public string <a href="https://www.php.net/manual/en/class.domnode.php#domnode.props.textcontent">$textContent</a> ; |
|||
|
|||
/* Methods */ |
|||
public <a href="Document_construct.html">__construct</a> ( ) |
|||
public <a href="Document_createEntityReference.html">createEntityReference</a> ( string $name ) : false |
|||
public <a href="Document_load.html">load</a> ( string $filename , null $options = null , string|null $encodingOrContentType = null ) : bool |
|||
public <a href="Document_loadHTML.html">loadHTML</a> ( string $source , null $options = null , string|null $encodingOrContentType = null ) : bool |
|||
public <a href="Document_loadHTMLFile.html">loadHTMLFile</a> ( string $filename , null $options = null , string|null $encodingOrContentType = null ) : bool |
|||
public <a href="Document_loadHTML.html">loadXML</a> ( string $source , null $options = null ) : false |
|||
public <a href="Document_save.html">save</a> ( string $filename , null $options = null ) : int|false |
|||
public <a href="Document_saveHTMLFile.html">saveHTMLFile</a> ( string $filename , null $options = null ) : int|false |
|||
public <a href="Document_saveXML.html">saveXML</a> ( DOMNode|null $node = null , null $options = null ) : false |
|||
public <a href="Document_validate.html">validate</a> ( ) : true |
|||
public <a href="Document_xinclude.html">xinclude</a> ( null $options = null ) : false |
|||
|
|||
}</code></pre> |
|||
|
|||
## Constants ## |
|||
|
|||
| Constant | Value | Description | |
|||
| ----------------------------------------------------- | ----- | ------------------------------------- | |
|||
| <var>MensBeam\HTML\Document::NO_QUIRKS_MODE</var> | 0 | Document not in quirks mode | |
|||
| <var>MensBeam\HTML\Document::QUIRKS_MODE</var> | 1 | Document is in quirks mode | |
|||
| <var>MensBeam\HTML\Document::LIMITEDQUIRKS_MODE</var> | 2 | Document is in limited quirks mode | |
|||
|
|||
## Properties ## |
|||
|
|||
<dl> |
|||
<dt id="document-props-documentencoding"><var>documentEncoding</var></dt> |
|||
<dd>Encoding of the document, as specified when parsing or when determining encoding type. Use this instead of <a href="https://php.net/manual/en/class.domdocument.php#domdocument.props.encoding"><code>\DOMDocument::encoding</code></a>.</dd> |
|||
|
|||
<dt id="document-props-quirksmode"><var>quirksMode</var></dt> |
|||
<dd>Used when parsing. Specifies which mode the document was parsed in. One of the <a href="#page_Constants">predefined quirks mode constants</a>.</dd> |
|||
</dl> |
|||
|
|||
The following properties inherited from `\DOMDocument` have no effect in `Mensbeam\HTML\Document`, so therefore are not listed in the schema above: |
|||
|
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.actualencoding"><var>actualEncoding</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.config"><var>config</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.encoding"><var>encoding</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.formatoutput"><var>formatOutput</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.preservewhitespace"><var>preserveWhiteSpace</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.recover"><var>recover</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.resolveexternals"><var>resolveExternals</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.standalone"><var>standalone</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.stricterrorchecking"><var>strictErrorChecking</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.substituteentities"><var>substituteEntities</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.validateonparse"><var>validateOnParse</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.version"><var>version</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.xmlencoding"><var>xmlEncoding</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.xmlstandalone"><var>xmlStandalone</var></a> |
|||
* <a href="https://www.php.net/manual/en/class.domdocument.php#domdocument.props.xmlversion"><var>xmlVersion</var></a> |
@ -0,0 +1 @@ |
|||
The MensBeam HTML library works by parsing HTML strings into PHP's existing XML DOM. It, however, has to force the antiquated PHP DOM extension into working properly with modern HTML DOM by extending many of the node types. The documentation below follows PHP's doc style guide as closely as possible. Each class should be listed separately in the menu under this section. |
@ -0,0 +1 @@ |
|||
Welcome to the user manual for HTML. It is included with each copy of the software, and is also [available online](https://mensbeam.com/html/en/). Please select a language above. |
Loading…
Reference in new issue