ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTML5 Class Reference
+ Collaboration diagram for HTML5:

Public Member Functions

 __construct ($data)
 save ()

Data Fields

const PCDATA = 0
const RCDATA = 1
const CDATA = 2
const PLAINTEXT = 3
const DOCTYPE = 0
const STARTTAG = 1
const ENDTAG = 2
const COMMENT = 3
const CHARACTR = 4
const EOF = 5

Private Member Functions

 char ()
 character ($s, $l=0)
 characters ($char_class, $start)
 dataState ()
 entityDataState ()
 tagOpenState ()
 closeTagOpenState ()
 tagNameState ()
 beforeAttributeNameState ()
 attributeNameState ()
 afterAttributeNameState ()
 beforeAttributeValueState ()
 attributeValueDoubleQuotedState ()
 attributeValueSingleQuotedState ()
 attributeValueUnquotedState ()
 entityInAttributeValueState ()
 bogusCommentState ()
 markupDeclarationOpenState ()
 commentState ()
 commentDashState ()
 commentEndState ()
 doctypeState ()
 beforeDoctypeNameState ()
 doctypeNameState ()
 afterDoctypeNameState ()
 bogusDoctypeState ()
 entity ()
 emitToken ($token)
 EOF ()

Private Attributes

 $data
 $char
 $EOF
 $state
 $tree
 $token
 $content_model
 $escape = false
 $entities

Detailed Description

Definition at line 63 of file PH5P.php.

Constructor & Destructor Documentation

HTML5::__construct (   $data)

Definition at line 127 of file PH5P.php.

References $data, EOF(), and PCDATA.

{
$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", null, $data);
$this->data = $data;
$this->char = -1;
$this->EOF = strlen($data);
$this->tree = new HTML5TreeConstructer;
$this->content_model = self::PCDATA;
$this->state = 'data';
while($this->state !== null) {
$this->{$this->state.'State'}();
}
}

+ Here is the call graph for this function:

Member Function Documentation

HTML5::afterAttributeNameState ( )
private

Definition at line 586 of file PH5P.php.

References $char, character(), elseif(), emitToken(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Stay in the after attribute name state. */
$this->state = 'afterAttributeName';
} elseif($char === '=') {
/* U+003D EQUALS SIGN (=)
Switch to the before attribute value state. */
$this->state = 'beforeAttributeValue';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} elseif($char === '/' && $this->character($this->char + 1) !== '>') {
/* U+002F SOLIDUS (/)
Parse error unless this is a permitted slash. Switch to the
before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the EOF
character in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
/* Anything else
Start a new attribute in the current tag token. Set that attribute's
name to the current input character, and its value to the empty string.
Switch to the attribute name state. */
$this->token['attr'][] = array(
'name' => strtolower($char),
'value' => null
);
$this->state = 'attributeName';
}
}

+ Here is the call graph for this function:

HTML5::afterDoctypeNameState ( )
private

Definition at line 1029 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
// Stay in the DOCTYPE name state.
} elseif($char === '>') {
$this->emitToken($this->token);
$this->state = 'data';
} elseif($this->char === $this->EOF) {
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
$this->token['error'] = true;
$this->state = 'bogusDoctype';
}
}

+ Here is the call graph for this function:

HTML5::attributeNameState ( )
private

Definition at line 535 of file PH5P.php.

References $char, character(), elseif(), emitToken(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Stay in the before attribute name state. */
$this->state = 'afterAttributeName';
} elseif($char === '=') {
/* U+003D EQUALS SIGN (=)
Switch to the before attribute value state. */
$this->state = 'beforeAttributeValue';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} elseif($char === '/' && $this->character($this->char + 1) !== '>') {
/* U+002F SOLIDUS (/)
Parse error unless this is a permitted slash. Switch to the before
attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the EOF
character in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
/* Anything else
Append the current input character to the current attribute's name.
Stay in the attribute name state. */
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['name'] .= strtolower($char);
$this->state = 'attributeName';
}
}

+ Here is the call graph for this function:

HTML5::attributeValueDoubleQuotedState ( )
private

Definition at line 688 of file PH5P.php.

References $char, character(), elseif(), emitToken(), entityInAttributeValueState(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if($char === '"') {
/* U+0022 QUOTATION MARK (")
Switch to the before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the entity in attribute value state. */
$this->entityInAttributeValueState('double');
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the character
in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
/* Anything else
Append the current input character to the current attribute's value.
Stay in the attribute value (double-quoted) state. */
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['value'] .= $char;
$this->state = 'attributeValueDoubleQuoted';
}
}

+ Here is the call graph for this function:

HTML5::attributeValueSingleQuotedState ( )
private

Definition at line 723 of file PH5P.php.

References $char, character(), elseif(), emitToken(), entityInAttributeValueState(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if($char === '\'') {
/* U+0022 QUOTATION MARK (')
Switch to the before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the entity in attribute value state. */
$this->entityInAttributeValueState('single');
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the character
in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
/* Anything else
Append the current input character to the current attribute's value.
Stay in the attribute value (single-quoted) state. */
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['value'] .= $char;
$this->state = 'attributeValueSingleQuoted';
}
}

+ Here is the call graph for this function:

HTML5::attributeValueUnquotedState ( )
private

Definition at line 758 of file PH5P.php.

References $char, character(), elseif(), emitToken(), and entityInAttributeValueState().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Switch to the before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the entity in attribute value state. */
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} else {
/* Anything else
Append the current input character to the current attribute's value.
Stay in the attribute value (unquoted) state. */
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['value'] .= $char;
$this->state = 'attributeValueUnquoted';
}
}

+ Here is the call graph for this function:

HTML5::beforeAttributeNameState ( )
private

Definition at line 486 of file PH5P.php.

References $char, character(), elseif(), emitToken(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Stay in the before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} elseif($char === '/') {
/* U+002F SOLIDUS (/)
Parse error unless this is a permitted slash. Stay in the before
attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the EOF
character in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
/* Anything else
Start a new attribute in the current tag token. Set that attribute's
name to the current input character, and its value to the empty string.
Switch to the attribute name state. */
$this->token['attr'][] = array(
'name' => strtolower($char),
'value' => null
);
$this->state = 'attributeName';
}
}

+ Here is the call graph for this function:

HTML5::beforeAttributeValueState ( )
private

Definition at line 640 of file PH5P.php.

References $char, character(), elseif(), and emitToken().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Stay in the before attribute value state. */
$this->state = 'beforeAttributeValue';
} elseif($char === '"') {
/* U+0022 QUOTATION MARK (")
Switch to the attribute value (double-quoted) state. */
$this->state = 'attributeValueDoubleQuoted';
} elseif($char === '&') {
/* U+0026 AMPERSAND (&)
Switch to the attribute value (unquoted) state and reconsume
this input character. */
$this->char--;
$this->state = 'attributeValueUnquoted';
} elseif($char === '\'') {
/* U+0027 APOSTROPHE (')
Switch to the attribute value (single-quoted) state. */
$this->state = 'attributeValueSingleQuoted';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} else {
/* Anything else
Append the current input character to the current attribute's value.
Switch to the attribute value (unquoted) state. */
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['value'] .= $char;
$this->state = 'attributeValueUnquoted';
}
}

+ Here is the call graph for this function:

HTML5::beforeDoctypeNameState ( )
private

Definition at line 953 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
// Stay in the before DOCTYPE name state.
} elseif(preg_match('/^[a-z]$/', $char)) {
$this->token = array(
'name' => strtoupper($char),
'type' => self::DOCTYPE,
'error' => true
);
$this->state = 'doctypeName';
} elseif($char === '>') {
$this->emitToken(array(
'name' => null,
'type' => self::DOCTYPE,
'error' => true
));
$this->state = 'data';
} elseif($this->char === $this->EOF) {
$this->emitToken(array(
'name' => null,
'type' => self::DOCTYPE,
'error' => true
));
$this->char--;
$this->state = 'data';
} else {
$this->token = array(
'name' => $char,
'type' => self::DOCTYPE,
'error' => true
);
$this->state = 'doctypeName';
}
}

+ Here is the call graph for this function:

HTML5::bogusCommentState ( )
private

Definition at line 809 of file PH5P.php.

References $data, characters(), emitToken(), and EOF().

{
/* Consume every character up to the first U+003E GREATER-THAN SIGN
character (>) or the end of the file (EOF), whichever comes first. Emit
a comment token whose data is the concatenation of all the characters
starting from and including the character that caused the state machine
to switch into the bogus comment state, up to and including the last
consumed character before the U+003E character, if any, or up to the
end of the file otherwise. (If the comment was started by the end of
the file (EOF), the token is empty.) */
$data = $this->characters('^>', $this->char);
$this->emitToken(array(
'data' => $data,
'type' => self::COMMENT
));
$this->char += strlen($data);
/* Switch to the data state. */
$this->state = 'data';
/* If the end of the file was reached, reconsume the EOF character. */
if($this->char === $this->EOF) {
$this->char = $this->EOF - 1;
}
}

+ Here is the call graph for this function:

HTML5::bogusDoctypeState ( )
private

Definition at line 1052 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if($char === '>') {
$this->emitToken($this->token);
$this->state = 'data';
} elseif($this->char === $this->EOF) {
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
// Stay in the bogus DOCTYPE state.
}
}

+ Here is the call graph for this function:

HTML5::char ( )
private

Definition at line 148 of file PH5P.php.

References $char, and EOF().

Referenced by afterDoctypeNameState(), beforeDoctypeNameState(), bogusDoctypeState(), closeTagOpenState(), commentDashState(), commentEndState(), commentState(), dataState(), doctypeNameState(), doctypeState(), and tagOpenState().

{
return ($this->char < $this->EOF)
? $this->data[$this->char]
: false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTML5::character (   $s,
  $l = 0 
)
private

Definition at line 154 of file PH5P.php.

References $l, and EOF().

Referenced by afterAttributeNameState(), attributeNameState(), attributeValueDoubleQuotedState(), attributeValueSingleQuotedState(), attributeValueUnquotedState(), beforeAttributeNameState(), beforeAttributeValueState(), closeTagOpenState(), dataState(), entity(), markupDeclarationOpenState(), tagNameState(), and tagOpenState().

{
if($s + $l < $this->EOF) {
if($l === 0) {
return $this->data[$s];
} else {
return substr($this->data, $s, $l);
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTML5::characters (   $char_class,
  $start 
)
private

Definition at line 164 of file PH5P.php.

References $start.

Referenced by bogusCommentState(), closeTagOpenState(), and entity().

{
return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
}

+ Here is the caller graph for this function:

HTML5::closeTagOpenState ( )
private

Definition at line 369 of file PH5P.php.

References $char, char(), character(), characters(), elseif(), emitToken(), and EOF().

{
$next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
$the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
if(($this->content_model === self::RCDATA || $this->content_model === self::CDATA) &&
(!$the_same || ($the_same && (!preg_match('/[\t\n\x0b\x0c >\/]/',
$this->character($this->char + 1 + strlen($next_node))) || $this->EOF === $this->char)))) {
/* If the content model flag is set to the RCDATA or CDATA states then
examine the next few characters. If they do not match the tag name of
the last start tag token emitted (case insensitively), or if they do but
they are not immediately followed by one of the following characters:
* U+0009 CHARACTER TABULATION
* U+000A LINE FEED (LF)
* U+000B LINE TABULATION
* U+000C FORM FEED (FF)
* U+0020 SPACE
* U+003E GREATER-THAN SIGN (>)
* U+002F SOLIDUS (/)
* EOF
...then there is a parse error. Emit a U+003C LESS-THAN SIGN character
token, a U+002F SOLIDUS character token, and switch to the data state
to process the next input character. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => '</'
));
$this->state = 'data';
} else {
/* Otherwise, if the content model flag is set to the PCDATA state,
or if the next few characters do match that tag name, consume the
next input character: */
$this->char++;
$char = $this->char();
if(preg_match('/^[A-Za-z]$/', $char)) {
/* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
Create a new end tag token, set its tag name to the lowercase version
of the input character (add 0x0020 to the character's code point), then
switch to the tag name state. (Don't emit the token yet; further details
will be filled in before it is emitted.) */
$this->token = array(
'name' => strtolower($char),
'type' => self::ENDTAG
);
$this->state = 'tagName';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Parse error. Switch to the data state. */
$this->state = 'data';
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit a U+003C LESS-THAN SIGN character token and a U+002F
SOLIDUS character token. Reconsume the EOF character in the data state. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => '</'
));
$this->char--;
$this->state = 'data';
} else {
/* Parse error. Switch to the bogus comment state. */
$this->state = 'bogusComment';
}
}
}

+ Here is the call graph for this function:

HTML5::commentDashState ( )
private

Definition at line 889 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
/* U+002D HYPHEN-MINUS (-) */
if($char === '-') {
/* Switch to the comment end state */
$this->state = 'commentEnd';
/* EOF */
} elseif($this->char === $this->EOF) {
/* Parse error. Emit the comment token. Reconsume the EOF character
in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
/* Anything else */
} else {
/* Append a U+002D HYPHEN-MINUS (-) character and the input
character to the comment token's data. Switch to the comment state. */
$this->token['data'] .= '-'.$char;
$this->state = 'comment';
}
}

+ Here is the call graph for this function:

HTML5::commentEndState ( )
private

Definition at line 916 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if($char === '>') {
$this->emitToken($this->token);
$this->state = 'data';
} elseif($char === '-') {
$this->token['data'] .= '-';
} elseif($this->char === $this->EOF) {
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
$this->token['data'] .= '--'.$char;
$this->state = 'comment';
}
}

+ Here is the call graph for this function:

HTML5::commentState ( )
private

Definition at line 863 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
/* U+002D HYPHEN-MINUS (-) */
if($char === '-') {
/* Switch to the comment dash state */
$this->state = 'commentDash';
/* EOF */
} elseif($this->char === $this->EOF) {
/* Parse error. Emit the comment token. Reconsume the EOF character
in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
/* Anything else */
} else {
/* Append the input character to the comment token's data. Stay in
the comment state. */
$this->token['data'] .= $char;
}
}

+ Here is the call graph for this function:

HTML5::dataState ( )
private

Definition at line 168 of file PH5P.php.

References $char, char(), character(), elseif(), emitToken(), and EOF().

{
// Consume the next input character
$this->char++;
$char = $this->char();
if($char === '&' && ($this->content_model === self::PCDATA || $this->content_model === self::RCDATA)) {
/* U+0026 AMPERSAND (&)
When the content model flag is set to one of the PCDATA or RCDATA
states: switch to the entity data state. Otherwise: treat it as per
the "anything else" entry below. */
$this->state = 'entityData';
} elseif($char === '-') {
/* If the content model flag is set to either the RCDATA state or
the CDATA state, and the escape flag is false, and there are at
least three characters before this one in the input stream, and the
last four characters in the input stream, including this one, are
U+003C LESS-THAN SIGN, U+0021 EXCLAMATION MARK, U+002D HYPHEN-MINUS,
and U+002D HYPHEN-MINUS ("<!--"), then set the escape flag to true. */
if(($this->content_model === self::RCDATA || $this->content_model ===
self::CDATA) && $this->escape === false &&
$this->char >= 3 && $this->character($this->char - 4, 4) === '<!--') {
$this->escape = true;
}
/* In any case, emit the input character as a character token. Stay
in the data state. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => $char
));
/* U+003C LESS-THAN SIGN (<) */
} elseif($char === '<' && ($this->content_model === self::PCDATA ||
(($this->content_model === self::RCDATA ||
$this->content_model === self::CDATA) && $this->escape === false))) {
/* When the content model flag is set to the PCDATA state: switch
to the tag open state.
When the content model flag is set to either the RCDATA state or
the CDATA state and the escape flag is false: switch to the tag
open state.
Otherwise: treat it as per the "anything else" entry below. */
$this->state = 'tagOpen';
/* U+003E GREATER-THAN SIGN (>) */
} elseif($char === '>') {
/* If the content model flag is set to either the RCDATA state or
the CDATA state, and the escape flag is true, and the last three
characters in the input stream including this one are U+002D
HYPHEN-MINUS, U+002D HYPHEN-MINUS, U+003E GREATER-THAN SIGN ("-->"),
set the escape flag to false. */
if(($this->content_model === self::RCDATA ||
$this->content_model === self::CDATA) && $this->escape === true &&
$this->character($this->char, 3) === '-->') {
$this->escape = false;
}
/* In any case, emit the input character as a character token.
Stay in the data state. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => $char
));
} elseif($this->char === $this->EOF) {
/* EOF
Emit an end-of-file token. */
$this->EOF();
} elseif($this->content_model === self::PLAINTEXT) {
/* When the content model flag is set to the PLAINTEXT state
THIS DIFFERS GREATLY FROM THE SPEC: Get the remaining characters of
the text and emit it as a character token. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => substr($this->data, $this->char)
));
$this->EOF();
} else {
/* Anything else
THIS DIFFERS GREATLY FROM THE SPEC: Get as many character that
otherwise would also be treated as a character token and emit it
as a single character token. Stay in the data state. */
$len = strcspn($this->data, '<&', $this->char);
$char = substr($this->data, $this->char, $len);
$this->char += $len - 1;
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => $char
));
$this->state = 'data';
}
}

+ Here is the call graph for this function:

HTML5::doctypeNameState ( )
private

Definition at line 1000 of file PH5P.php.

References $char, char(), elseif(), emitToken(), and EOF().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
$this->state = 'AfterDoctypeName';
} elseif($char === '>') {
$this->emitToken($this->token);
$this->state = 'data';
} elseif(preg_match('/^[a-z]$/', $char)) {
$this->token['name'] .= strtoupper($char);
} elseif($this->char === $this->EOF) {
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} else {
$this->token['name'] .= $char;
}
$this->token['error'] = ($this->token['name'] === 'HTML')
? false
: true;
}

+ Here is the call graph for this function:

HTML5::doctypeState ( )
private

Definition at line 939 of file PH5P.php.

References $char, and char().

{
/* Consume the next input character: */
$this->char++;
$char = $this->char();
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
$this->state = 'beforeDoctypeName';
} else {
$this->char--;
$this->state = 'beforeDoctypeName';
}
}

+ Here is the call graph for this function:

HTML5::emitToken (   $token)
private

Definition at line 1161 of file PH5P.php.

References $token, elseif(), and PCDATA.

Referenced by afterAttributeNameState(), afterDoctypeNameState(), attributeNameState(), attributeValueDoubleQuotedState(), attributeValueSingleQuotedState(), attributeValueUnquotedState(), beforeAttributeNameState(), beforeAttributeValueState(), beforeDoctypeNameState(), bogusCommentState(), bogusDoctypeState(), closeTagOpenState(), commentDashState(), commentEndState(), commentState(), dataState(), doctypeNameState(), entityDataState(), tagNameState(), and tagOpenState().

{
$emit = $this->tree->emitToken($token);
if(is_int($emit)) {
$this->content_model = $emit;
} elseif($token['type'] === self::ENDTAG) {
$this->content_model = self::PCDATA;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTML5::entity ( )
private

Definition at line 1071 of file PH5P.php.

References $char, $start, character(), and characters().

Referenced by entityDataState(), and entityInAttributeValueState().

{
// This section defines how to consume an entity. This definition is
// used when parsing entities in text and in attributes.
// The behaviour depends on the identity of the next character (the
// one immediately after the U+0026 AMPERSAND character):
switch($this->character($this->char + 1)) {
// U+0023 NUMBER SIGN (#)
case '#':
// The behaviour further depends on the character after the
// U+0023 NUMBER SIGN:
switch($this->character($this->char + 1)) {
// U+0078 LATIN SMALL LETTER X
// U+0058 LATIN CAPITAL LETTER X
case 'x':
case 'X':
// Follow the steps below, but using the range of
// characters U+0030 DIGIT ZERO through to U+0039 DIGIT
// NINE, U+0061 LATIN SMALL LETTER A through to U+0066
// LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
// A, through to U+0046 LATIN CAPITAL LETTER F (in other
// words, 0-9, A-F, a-f).
$char = 1;
$char_class = '0-9A-Fa-f';
break;
// Anything else
default:
// Follow the steps below, but using the range of
// characters U+0030 DIGIT ZERO through to U+0039 DIGIT
// NINE (i.e. just 0-9).
$char = 0;
$char_class = '0-9';
break;
}
// Consume as many characters as match the range of characters
// given above.
$this->char++;
$e_name = $this->characters($char_class, $this->char + $char + 1);
$entity = $this->character($start, $this->char);
$cond = strlen($e_name) > 0;
// The rest of the parsing happens bellow.
break;
// Anything else
default:
// Consume the maximum number of characters possible, with the
// consumed characters case-sensitively matching one of the
// identifiers in the first column of the entities table.
$e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
$len = strlen($e_name);
for($c = 1; $c <= $len; $c++) {
$id = substr($e_name, 0, $c);
$this->char++;
if(in_array($id, $this->entities)) {
if ($e_name[$c-1] !== ';') {
if ($c < $len && $e_name[$c] == ';') {
$this->char++; // consume extra semicolon
}
}
$entity = $id;
break;
}
}
$cond = isset($entity);
// The rest of the parsing happens bellow.
break;
}
if(!$cond) {
// If no match can be made, then this is a parse error. No
// characters are consumed, and nothing is returned.
$this->char = $start;
return false;
}
// Return a character token for the character corresponding to the
// entity name (as given by the second column of the entities table).
return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTML5::entityDataState ( )
private

Definition at line 268 of file PH5P.php.

References $char, emitToken(), and entity().

{
// Attempt to consume an entity.
$entity = $this->entity();
// If nothing is returned, emit a U+0026 AMPERSAND character token.
// Otherwise, emit the character token that was returned.
$char = (!$entity) ? '&' : $entity;
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => $char
));
// Finally, switch to the data state.
$this->state = 'data';
}

+ Here is the call graph for this function:

HTML5::entityInAttributeValueState ( )
private

Definition at line 794 of file PH5P.php.

References $char, and entity().

Referenced by attributeValueDoubleQuotedState(), attributeValueSingleQuotedState(), and attributeValueUnquotedState().

{
// Attempt to consume an entity.
$entity = $this->entity();
// If nothing is returned, append a U+0026 AMPERSAND character to the
// current attribute's value. Otherwise, emit the character token that
// was returned.
$char = (!$entity)
? '&'
: $entity;
$last = count($this->token['attr']) - 1;
$this->token['attr'][$last]['value'] .= $char;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTML5::markupDeclarationOpenState ( )
private

Definition at line 835 of file PH5P.php.

References character(), and elseif().

{
/* If the next two characters are both U+002D HYPHEN-MINUS (-)
characters, consume those two characters, create a comment token whose
data is the empty string, and switch to the comment state. */
if($this->character($this->char + 1, 2) === '--') {
$this->char += 2;
$this->state = 'comment';
$this->token = array(
'data' => null,
'type' => self::COMMENT
);
/* Otherwise if the next seven chacacters are a case-insensitive match
for the word "DOCTYPE", then consume those characters and switch to the
DOCTYPE state. */
} elseif(strtolower($this->character($this->char + 1, 7)) === 'doctype') {
$this->char += 7;
$this->state = 'doctype';
/* Otherwise, is is a parse error. Switch to the bogus comment state.
The next character that is consumed, if any, is the first character
that will be in the comment. */
} else {
$this->char++;
$this->state = 'bogusComment';
}
}

+ Here is the call graph for this function:

HTML5::save ( )

Definition at line 144 of file PH5P.php.

{
return $this->tree->save();
}
HTML5::tagNameState ( )
private

Definition at line 442 of file PH5P.php.

References $char, character(), elseif(), emitToken(), and EOF().

{
// Consume the next input character:
$this->char++;
$char = $this->character($this->char);
if(preg_match('/^[\t\n\x0b\x0c ]$/', $char)) {
/* U+0009 CHARACTER TABULATION
U+000A LINE FEED (LF)
U+000B LINE TABULATION
U+000C FORM FEED (FF)
U+0020 SPACE
Switch to the before attribute name state. */
$this->state = 'beforeAttributeName';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Emit the current tag token. Switch to the data state. */
$this->emitToken($this->token);
$this->state = 'data';
} elseif($this->char === $this->EOF) {
/* EOF
Parse error. Emit the current tag token. Reconsume the EOF
character in the data state. */
$this->emitToken($this->token);
$this->char--;
$this->state = 'data';
} elseif($char === '/') {
/* U+002F SOLIDUS (/)
Parse error unless this is a permitted slash. Switch to the before
attribute name state. */
$this->state = 'beforeAttributeName';
} else {
/* Anything else
Append the current input character to the current tag token's tag name.
Stay in the tag name state. */
$this->token['name'] .= strtolower($char);
$this->state = 'tagName';
}
}

+ Here is the call graph for this function:

HTML5::tagOpenState ( )
private

Definition at line 284 of file PH5P.php.

References $char, char(), character(), elseif(), and emitToken().

{
switch($this->content_model) {
case self::RCDATA:
case self::CDATA:
/* If the next input character is a U+002F SOLIDUS (/) character,
consume it and switch to the close tag open state. If the next
input character is not a U+002F SOLIDUS (/) character, emit a
U+003C LESS-THAN SIGN character token and switch to the data
state to process the next input character. */
if($this->character($this->char + 1) === '/') {
$this->char++;
$this->state = 'closeTagOpen';
} else {
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => '<'
));
$this->state = 'data';
}
break;
case self::PCDATA:
// If the content model flag is set to the PCDATA state
// Consume the next input character:
$this->char++;
$char = $this->char();
if($char === '!') {
/* U+0021 EXCLAMATION MARK (!)
Switch to the markup declaration open state. */
$this->state = 'markupDeclarationOpen';
} elseif($char === '/') {
/* U+002F SOLIDUS (/)
Switch to the close tag open state. */
$this->state = 'closeTagOpen';
} elseif(preg_match('/^[A-Za-z]$/', $char)) {
/* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
Create a new start tag token, set its tag name to the lowercase
version of the input character (add 0x0020 to the character's code
point), then switch to the tag name state. (Don't emit the token
yet; further details will be filled in before it is emitted.) */
$this->token = array(
'name' => strtolower($char),
'type' => self::STARTTAG,
'attr' => array()
);
$this->state = 'tagName';
} elseif($char === '>') {
/* U+003E GREATER-THAN SIGN (>)
Parse error. Emit a U+003C LESS-THAN SIGN character token and a
U+003E GREATER-THAN SIGN character token. Switch to the data state. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => '<>'
));
$this->state = 'data';
} elseif($char === '?') {
/* U+003F QUESTION MARK (?)
Parse error. Switch to the bogus comment state. */
$this->state = 'bogusComment';
} else {
/* Anything else
Parse error. Emit a U+003C LESS-THAN SIGN character token and
reconsume the current input character in the data state. */
$this->emitToken(array(
'type' => self::CHARACTR,
'data' => '<'
));
$this->char--;
$this->state = 'data';
}
break;
}
}

+ Here is the call graph for this function:

Field Documentation

HTML5::$content_model
private

Definition at line 70 of file PH5P.php.

HTML5::$data
private

Definition at line 64 of file PH5P.php.

Referenced by __construct(), and bogusCommentState().

HTML5::$entities
private

Definition at line 72 of file PH5P.php.

HTML5::$EOF
private

Definition at line 66 of file PH5P.php.

HTML5::$escape = false
private

Definition at line 71 of file PH5P.php.

HTML5::$state
private

Definition at line 67 of file PH5P.php.

HTML5::$token
private

Definition at line 69 of file PH5P.php.

Referenced by emitToken().

HTML5::$tree
private

Definition at line 68 of file PH5P.php.

const HTML5::CDATA = 2

Definition at line 117 of file PH5P.php.

Referenced by HTML5TreeConstructer\inBody(), and HTML5TreeConstructer\inHead().

const HTML5::EOF = 5

Definition at line 125 of file PH5P.php.

const HTML5::PCDATA = 0

Definition at line 115 of file PH5P.php.

Referenced by __construct(), emitToken(), and HTML5TreeConstructer\inHead().

const HTML5::PLAINTEXT = 3

Definition at line 118 of file PH5P.php.

Referenced by HTML5TreeConstructer\inBody().

const HTML5::RCDATA = 1

Definition at line 116 of file PH5P.php.

Referenced by HTML5TreeConstructer\inBody(), and HTML5TreeConstructer\inHead().


The documentation for this class was generated from the following file: