Completed
Pull Request — master (#1795)
by Christian
16:22 queued 04:43
created
modules/contrib/htmlpurifier/library/HTMLPurifier/VarParser/Flexible.php 1 patch
Switch Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -23,105 +23,105 @@
 block discarded – undo
23 23
             // Note: if code "breaks" from the switch, it triggers a generic
24 24
             // exception to be thrown. Specific errors can be specifically
25 25
             // done here.
26
-            case self::MIXED:
27
-            case self::ISTRING:
28
-            case self::STRING:
29
-            case self::TEXT:
30
-            case self::ITEXT:
31
-                return $var;
32
-            case self::INT:
33
-                if (is_string($var) && ctype_digit($var)) {
34
-                    $var = (int)$var;
26
+        case self::MIXED:
27
+        case self::ISTRING:
28
+        case self::STRING:
29
+        case self::TEXT:
30
+        case self::ITEXT:
31
+            return $var;
32
+        case self::INT:
33
+            if (is_string($var) && ctype_digit($var)) {
34
+                $var = (int)$var;
35
+            }
36
+            return $var;
37
+        case self::FLOAT:
38
+            if ((is_string($var) && is_numeric($var)) || is_int($var)) {
39
+                $var = (float)$var;
40
+            }
41
+            return $var;
42
+        case self::BOOL:
43
+            if (is_int($var) && ($var === 0 || $var === 1)) {
44
+                $var = (bool)$var;
45
+            } elseif (is_string($var)) {
46
+                if ($var == 'on' || $var == 'true' || $var == '1') {
47
+                    $var = true;
48
+                } elseif ($var == 'off' || $var == 'false' || $var == '0') {
49
+                    $var = false;
50
+                } else {
51
+                    throw new HTMLPurifier_VarParserException("Unrecognized value '$var' for $type");
35 52
                 }
36
-                return $var;
37
-            case self::FLOAT:
38
-                if ((is_string($var) && is_numeric($var)) || is_int($var)) {
39
-                    $var = (float)$var;
53
+            }
54
+            return $var;
55
+        case self::ALIST:
56
+        case self::HASH:
57
+        case self::LOOKUP:
58
+            if (is_string($var)) {
59
+                // special case: technically, this is an array with
60
+                // a single empty string item, but having an empty
61
+                // array is more intuitive
62
+                if ($var == '') {
63
+                    return array();
40 64
                 }
41
-                return $var;
42
-            case self::BOOL:
43
-                if (is_int($var) && ($var === 0 || $var === 1)) {
44
-                    $var = (bool)$var;
45
-                } elseif (is_string($var)) {
46
-                    if ($var == 'on' || $var == 'true' || $var == '1') {
47
-                        $var = true;
48
-                    } elseif ($var == 'off' || $var == 'false' || $var == '0') {
49
-                        $var = false;
50
-                    } else {
51
-                        throw new HTMLPurifier_VarParserException("Unrecognized value '$var' for $type");
52
-                    }
65
+                if (strpos($var, "\n") === false && strpos($var, "\r") === false) {
66
+                    // simplistic string to array method that only works
67
+                    // for simple lists of tag names or alphanumeric characters
68
+                    $var = explode(',', $var);
69
+                } else {
70
+                    $var = preg_split('/(,|[\n\r]+)/', $var);
53 71
                 }
54
-                return $var;
55
-            case self::ALIST:
56
-            case self::HASH:
57
-            case self::LOOKUP:
58
-                if (is_string($var)) {
59
-                    // special case: technically, this is an array with
60
-                    // a single empty string item, but having an empty
61
-                    // array is more intuitive
62
-                    if ($var == '') {
63
-                        return array();
64
-                    }
65
-                    if (strpos($var, "\n") === false && strpos($var, "\r") === false) {
66
-                        // simplistic string to array method that only works
67
-                        // for simple lists of tag names or alphanumeric characters
68
-                        $var = explode(',', $var);
69
-                    } else {
70
-                        $var = preg_split('/(,|[\n\r]+)/', $var);
71
-                    }
72
-                    // remove spaces
73
-                    foreach ($var as $i => $j) {
74
-                        $var[$i] = trim($j);
75
-                    }
76
-                    if ($type === self::HASH) {
77
-                        // key:value,key2:value2
78
-                        $nvar = array();
79
-                        foreach ($var as $keypair) {
80
-                            $c = explode(':', $keypair, 2);
81
-                            if (!isset($c[1])) {
82
-                                continue;
83
-                            }
84
-                            $nvar[trim($c[0])] = trim($c[1]);
85
-                        }
86
-                        $var = $nvar;
87
-                    }
72
+                // remove spaces
73
+                foreach ($var as $i => $j) {
74
+                    $var[$i] = trim($j);
88 75
                 }
89
-                if (!is_array($var)) {
90
-                    break;
91
-                }
92
-                $keys = array_keys($var);
93
-                if ($keys === array_keys($keys)) {
94
-                    if ($type == self::ALIST) {
95
-                        return $var;
96
-                    } elseif ($type == self::LOOKUP) {
97
-                        $new = array();
98
-                        foreach ($var as $key) {
99
-                            $new[$key] = true;
76
+                if ($type === self::HASH) {
77
+                    // key:value,key2:value2
78
+                    $nvar = array();
79
+                    foreach ($var as $keypair) {
80
+                        $c = explode(':', $keypair, 2);
81
+                        if (!isset($c[1])) {
82
+                            continue;
100 83
                         }
101
-                        return $new;
102
-                    } else {
103
-                        break;
84
+                        $nvar[trim($c[0])] = trim($c[1]);
104 85
                     }
86
+                    $var = $nvar;
105 87
                 }
106
-                if ($type === self::ALIST) {
107
-                    trigger_error("Array list did not have consecutive integer indexes", E_USER_WARNING);
108
-                    return array_values($var);
88
+            }
89
+            if (!is_array($var)) {
90
+                break;
91
+            }
92
+            $keys = array_keys($var);
93
+            if ($keys === array_keys($keys)) {
94
+                if ($type == self::ALIST) {
95
+                    return $var;
96
+                } elseif ($type == self::LOOKUP) {
97
+                    $new = array();
98
+                    foreach ($var as $key) {
99
+                        $new[$key] = true;
100
+                    }
101
+                    return $new;
102
+                } else {
103
+                    break;
109 104
                 }
110
-                if ($type === self::LOOKUP) {
111
-                    foreach ($var as $key => $value) {
112
-                        if ($value !== true) {
113
-                            trigger_error(
114
-                                "Lookup array has non-true value at key '$key'; " .
115
-                                "maybe your input array was not indexed numerically",
116
-                                E_USER_WARNING
117
-                            );
118
-                        }
119
-                        $var[$key] = true;
105
+            }
106
+            if ($type === self::ALIST) {
107
+                trigger_error("Array list did not have consecutive integer indexes", E_USER_WARNING);
108
+                return array_values($var);
109
+            }
110
+            if ($type === self::LOOKUP) {
111
+                foreach ($var as $key => $value) {
112
+                    if ($value !== true) {
113
+                        trigger_error(
114
+                            "Lookup array has non-true value at key '$key'; " .
115
+                            "maybe your input array was not indexed numerically",
116
+                            E_USER_WARNING
117
+                        );
120 118
                     }
119
+                    $var[$key] = true;
121 120
                 }
122
-                return $var;
123
-            default:
124
-                $this->errorInconsistent(__CLASS__, $type);
121
+            }
122
+            return $var;
123
+        default:
124
+            $this->errorInconsistent(__CLASS__, $type);
125 125
         }
126 126
         $this->errorGeneric($var, $type);
127 127
     }
Please login to merge, or discard this patch.
boinc/modules/contrib/htmlpurifier/library/HTMLPurifier/AttrDef/Lang.php 1 patch
Switch Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -30,23 +30,23 @@
 block discarded – undo
30 30
         // process primary subtag : $subtags[0]
31 31
         $length = strlen($subtags[0]);
32 32
         switch ($length) {
33
-            case 0:
33
+        case 0:
34
+            return false;
35
+        case 1:
36
+            if (!($subtags[0] == 'x' || $subtags[0] == 'i')) {
34 37
                 return false;
35
-            case 1:
36
-                if (!($subtags[0] == 'x' || $subtags[0] == 'i')) {
37
-                    return false;
38
-                }
39
-                break;
40
-            case 2:
41
-            case 3:
42
-                if (!ctype_alpha($subtags[0])) {
43
-                    return false;
44
-                } elseif (!ctype_lower($subtags[0])) {
45
-                    $subtags[0] = strtolower($subtags[0]);
46
-                }
47
-                break;
48
-            default:
38
+            }
39
+            break;
40
+        case 2:
41
+        case 3:
42
+            if (!ctype_alpha($subtags[0])) {
49 43
                 return false;
44
+            } elseif (!ctype_lower($subtags[0])) {
45
+                $subtags[0] = strtolower($subtags[0]);
46
+            }
47
+            break;
48
+        default:
49
+            return false;
50 50
         }
51 51
 
52 52
         $new_string = $subtags[0];
Please login to merge, or discard this patch.
modules/contrib/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/Number.php 1 patch
Switch Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@
 block discarded – undo
41 41
 
42 42
         $sign = '';
43 43
         switch ($number[0]) {
44
-            case '-':
45
-                if ($this->non_negative) {
46
-                    return false;
47
-                }
48
-                $sign = '-';
49
-            case '+':
50
-                $number = substr($number, 1);
44
+        case '-':
45
+            if ($this->non_negative) {
46
+                return false;
47
+            }
48
+            $sign = '-';
49
+        case '+':
50
+            $number = substr($number, 1);
51 51
         }
52 52
 
53 53
         if (ctype_digit($number)) {
Please login to merge, or discard this patch.
modules/contrib/htmlpurifier/library/HTMLPurifier/AttrDef/CSS/Font.php 1 patch
Switch Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -70,103 +70,103 @@
 block discarded – undo
70 70
                 continue;
71 71
             }
72 72
             switch ($stage) {
73
-                case 0: // attempting to catch font-style, font-variant or font-weight
74
-                    foreach ($stage_1 as $validator_name) {
75
-                        if (isset($caught[$validator_name])) {
76
-                            continue;
77
-                        }
78
-                        $r = $this->info[$validator_name]->validate(
79
-                            $bits[$i],
80
-                            $config,
81
-                            $context
82
-                        );
83
-                        if ($r !== false) {
84
-                            $final .= $r . ' ';
85
-                            $caught[$validator_name] = true;
86
-                            break;
87
-                        }
88
-                    }
89
-                    // all three caught, continue on
90
-                    if (count($caught) >= 3) {
91
-                        $stage = 1;
73
+            case 0: // attempting to catch font-style, font-variant or font-weight
74
+                foreach ($stage_1 as $validator_name) {
75
+                    if (isset($caught[$validator_name])) {
76
+                        continue;
92 77
                     }
78
+                    $r = $this->info[$validator_name]->validate(
79
+                        $bits[$i],
80
+                        $config,
81
+                        $context
82
+                    );
93 83
                     if ($r !== false) {
84
+                        $final .= $r . ' ';
85
+                        $caught[$validator_name] = true;
94 86
                         break;
95 87
                     }
96
-                case 1: // attempting to catch font-size and perhaps line-height
97
-                    $found_slash = false;
98
-                    if (strpos($bits[$i], '/') !== false) {
99
-                        list($font_size, $line_height) =
100
-                            explode('/', $bits[$i]);
101
-                        if ($line_height === '') {
102
-                            // ooh, there's a space after the slash!
103
-                            $line_height = false;
104
-                            $found_slash = true;
105
-                        }
106
-                    } else {
107
-                        $font_size = $bits[$i];
88
+                }
89
+                // all three caught, continue on
90
+                if (count($caught) >= 3) {
91
+                    $stage = 1;
92
+                }
93
+                if ($r !== false) {
94
+                    break;
95
+                }
96
+            case 1: // attempting to catch font-size and perhaps line-height
97
+                $found_slash = false;
98
+                if (strpos($bits[$i], '/') !== false) {
99
+                    list($font_size, $line_height) =
100
+                        explode('/', $bits[$i]);
101
+                    if ($line_height === '') {
102
+                        // ooh, there's a space after the slash!
108 103
                         $line_height = false;
104
+                        $found_slash = true;
109 105
                     }
110
-                    $r = $this->info['font-size']->validate(
111
-                        $font_size,
112
-                        $config,
113
-                        $context
114
-                    );
115
-                    if ($r !== false) {
116
-                        $final .= $r;
117
-                        // attempt to catch line-height
118
-                        if ($line_height === false) {
119
-                            // we need to scroll forward
120
-                            for ($j = $i + 1; $j < $size; $j++) {
121
-                                if ($bits[$j] === '') {
106
+                } else {
107
+                    $font_size = $bits[$i];
108
+                    $line_height = false;
109
+                }
110
+                $r = $this->info['font-size']->validate(
111
+                    $font_size,
112
+                    $config,
113
+                    $context
114
+                );
115
+                if ($r !== false) {
116
+                    $final .= $r;
117
+                    // attempt to catch line-height
118
+                    if ($line_height === false) {
119
+                        // we need to scroll forward
120
+                        for ($j = $i + 1; $j < $size; $j++) {
121
+                            if ($bits[$j] === '') {
122
+                                continue;
123
+                            }
124
+                            if ($bits[$j] === '/') {
125
+                                if ($found_slash) {
126
+                                    return false;
127
+                                } else {
128
+                                    $found_slash = true;
122 129
                                     continue;
123 130
                                 }
124
-                                if ($bits[$j] === '/') {
125
-                                    if ($found_slash) {
126
-                                        return false;
127
-                                    } else {
128
-                                        $found_slash = true;
129
-                                        continue;
130
-                                    }
131
-                                }
132
-                                $line_height = $bits[$j];
133
-                                break;
134
-                            }
135
-                        } else {
136
-                            // slash already found
137
-                            $found_slash = true;
138
-                            $j = $i;
139
-                        }
140
-                        if ($found_slash) {
141
-                            $i = $j;
142
-                            $r = $this->info['line-height']->validate(
143
-                                $line_height,
144
-                                $config,
145
-                                $context
146
-                            );
147
-                            if ($r !== false) {
148
-                                $final .= '/' . $r;
149 131
                             }
132
+                            $line_height = $bits[$j];
133
+                            break;
150 134
                         }
151
-                        $final .= ' ';
152
-                        $stage = 2;
153
-                        break;
135
+                    } else {
136
+                        // slash already found
137
+                        $found_slash = true;
138
+                        $j = $i;
154 139
                     }
155
-                    return false;
156
-                case 2: // attempting to catch font-family
157
-                    $font_family =
158
-                        implode(' ', array_slice($bits, $i, $size - $i));
159
-                    $r = $this->info['font-family']->validate(
160
-                        $font_family,
161
-                        $config,
162
-                        $context
163
-                    );
164
-                    if ($r !== false) {
165
-                        $final .= $r . ' ';
166
-                        // processing completed successfully
167
-                        return rtrim($final);
140
+                    if ($found_slash) {
141
+                        $i = $j;
142
+                        $r = $this->info['line-height']->validate(
143
+                            $line_height,
144
+                            $config,
145
+                            $context
146
+                        );
147
+                        if ($r !== false) {
148
+                            $final .= '/' . $r;
149
+                        }
168 150
                     }
169
-                    return false;
151
+                    $final .= ' ';
152
+                    $stage = 2;
153
+                    break;
154
+                }
155
+                return false;
156
+            case 2: // attempting to catch font-family
157
+                $font_family =
158
+                    implode(' ', array_slice($bits, $i, $size - $i));
159
+                $r = $this->info['font-family']->validate(
160
+                    $font_family,
161
+                    $config,
162
+                    $context
163
+                );
164
+                if ($r !== false) {
165
+                    $final .= $r . ' ';
166
+                    // processing completed successfully
167
+                    return rtrim($final);
168
+                }
169
+                return false;
170 170
             }
171 171
         }
172 172
         return false;
Please login to merge, or discard this patch.
default/boinc/modules/contrib/htmlpurifier/library/HTMLPurifier/Token.php 1 patch
Switch Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -50,18 +50,18 @@
 block discarded – undo
50 50
         if ($n === 'type') {
51 51
             trigger_error('Deprecated type property called; use instanceof', E_USER_NOTICE);
52 52
             switch (get_class($this)) {
53
-                case 'HTMLPurifier_Token_Start':
54
-                    return 'start';
55
-                case 'HTMLPurifier_Token_Empty':
56
-                    return 'empty';
57
-                case 'HTMLPurifier_Token_End':
58
-                    return 'end';
59
-                case 'HTMLPurifier_Token_Text':
60
-                    return 'text';
61
-                case 'HTMLPurifier_Token_Comment':
62
-                    return 'comment';
63
-                default:
64
-                    return null;
53
+            case 'HTMLPurifier_Token_Start':
54
+                return 'start';
55
+            case 'HTMLPurifier_Token_Empty':
56
+                return 'empty';
57
+            case 'HTMLPurifier_Token_End':
58
+                return 'end';
59
+            case 'HTMLPurifier_Token_Text':
60
+                return 'text';
61
+            case 'HTMLPurifier_Token_Comment':
62
+                return 'comment';
63
+            default:
64
+                return null;
65 65
             }
66 66
         }
67 67
     }
Please login to merge, or discard this patch.
default/boinc/modules/contrib/htmlpurifier/library/HTMLPurifier/Lexer.php 1 patch
Switch Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -113,20 +113,20 @@
 block discarded – undo
113 113
 
114 114
             // instantiate recognized string names
115 115
             switch ($lexer) {
116
-                case 'DOMLex':
117
-                    $inst = new HTMLPurifier_Lexer_DOMLex();
118
-                    break;
119
-                case 'DirectLex':
120
-                    $inst = new HTMLPurifier_Lexer_DirectLex();
121
-                    break;
122
-                case 'PH5P':
123
-                    $inst = new HTMLPurifier_Lexer_PH5P();
124
-                    break;
125
-                default:
126
-                    throw new HTMLPurifier_Exception(
127
-                        "Cannot instantiate unrecognized Lexer type " .
128
-                        htmlspecialchars($lexer)
129
-                    );
116
+            case 'DOMLex':
117
+                $inst = new HTMLPurifier_Lexer_DOMLex();
118
+                break;
119
+            case 'DirectLex':
120
+                $inst = new HTMLPurifier_Lexer_DirectLex();
121
+                break;
122
+            case 'PH5P':
123
+                $inst = new HTMLPurifier_Lexer_PH5P();
124
+                break;
125
+            default:
126
+                throw new HTMLPurifier_Exception(
127
+                    "Cannot instantiate unrecognized Lexer type " .
128
+                    htmlspecialchars($lexer)
129
+                );
130 130
             }
131 131
         }
132 132
 
Please login to merge, or discard this patch.
boinc/modules/contrib/htmlpurifier/library/HTMLPurifier/ContentSets.php 1 patch
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -125,14 +125,14 @@
 block discarded – undo
125 125
             return $value;
126 126
         }
127 127
         switch ($def->content_model_type) {
128
-            case 'required':
129
-                return new HTMLPurifier_ChildDef_Required($value);
130
-            case 'optional':
131
-                return new HTMLPurifier_ChildDef_Optional($value);
132
-            case 'empty':
133
-                return new HTMLPurifier_ChildDef_Empty();
134
-            case 'custom':
135
-                return new HTMLPurifier_ChildDef_Custom($value);
128
+        case 'required':
129
+            return new HTMLPurifier_ChildDef_Required($value);
130
+        case 'optional':
131
+            return new HTMLPurifier_ChildDef_Optional($value);
132
+        case 'empty':
133
+            return new HTMLPurifier_ChildDef_Empty();
134
+        case 'custom':
135
+            return new HTMLPurifier_ChildDef_Custom($value);
136 136
         }
137 137
         // defer to its module
138 138
         $return = false;
Please login to merge, or discard this patch.
contrib/htmlpurifier/library/HTMLPurifier/AttrTransform/SafeParam.php 1 patch
Switch Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -43,34 +43,34 @@
 block discarded – undo
43 43
         switch ($attr['name']) {
44 44
             // application/x-shockwave-flash
45 45
             // Keep this synchronized with Injector/SafeObject.php
46
-            case 'allowScriptAccess':
47
-                $attr['value'] = 'never';
48
-                break;
49
-            case 'allowNetworking':
50
-                $attr['value'] = 'internal';
51
-                break;
52
-            case 'allowFullScreen':
53
-                if ($config->get('HTML.FlashAllowFullScreen')) {
54
-                    $attr['value'] = ($attr['value'] == 'true') ? 'true' : 'false';
55
-                } else {
56
-                    $attr['value'] = 'false';
57
-                }
58
-                break;
59
-            case 'wmode':
60
-                $attr['value'] = $this->wmode->validate($attr['value'], $config, $context);
61
-                break;
62
-            case 'movie':
63
-            case 'src':
64
-                $attr['name'] = "movie";
65
-                $attr['value'] = $this->uri->validate($attr['value'], $config, $context);
66
-                break;
67
-            case 'flashvars':
68
-                // we're going to allow arbitrary inputs to the SWF, on
69
-                // the reasoning that it could only hack the SWF, not us.
70
-                break;
71
-            // add other cases to support other param name/value pairs
72
-            default:
73
-                $attr['name'] = $attr['value'] = null;
46
+        case 'allowScriptAccess':
47
+            $attr['value'] = 'never';
48
+            break;
49
+        case 'allowNetworking':
50
+            $attr['value'] = 'internal';
51
+            break;
52
+        case 'allowFullScreen':
53
+            if ($config->get('HTML.FlashAllowFullScreen')) {
54
+                $attr['value'] = ($attr['value'] == 'true') ? 'true' : 'false';
55
+            } else {
56
+                $attr['value'] = 'false';
57
+            }
58
+            break;
59
+        case 'wmode':
60
+            $attr['value'] = $this->wmode->validate($attr['value'], $config, $context);
61
+            break;
62
+        case 'movie':
63
+        case 'src':
64
+            $attr['name'] = "movie";
65
+            $attr['value'] = $this->uri->validate($attr['value'], $config, $context);
66
+            break;
67
+        case 'flashvars':
68
+            // we're going to allow arbitrary inputs to the SWF, on
69
+            // the reasoning that it could only hack the SWF, not us.
70
+            break;
71
+        // add other cases to support other param name/value pairs
72
+        default:
73
+            $attr['name'] = $attr['value'] = null;
74 74
         }
75 75
         return $attr;
76 76
     }
Please login to merge, or discard this patch.
boinc/modules/contrib/htmlpurifier/library/HTMLPurifier/Lexer/PH5P.php 1 patch
Switch Indentation   +974 added lines, -974 removed lines patch added patch discarded remove patch
@@ -636,92 +636,92 @@  discard block
 block discarded – undo
636 636
     private function tagOpenState()
637 637
     {
638 638
         switch ($this->content_model) {
639
-            case self::RCDATA:
640
-            case self::CDATA:
641
-                /* If the next input character is a U+002F SOLIDUS (/) character,
639
+        case self::RCDATA:
640
+        case self::CDATA:
641
+            /* If the next input character is a U+002F SOLIDUS (/) character,
642 642
                 consume it and switch to the close tag open state. If the next
643 643
                 input character is not a U+002F SOLIDUS (/) character, emit a
644 644
                 U+003C LESS-THAN SIGN character token and switch to the data
645 645
                 state to process the next input character. */
646
-                if ($this->character($this->char + 1) === '/') {
647
-                    $this->char++;
648
-                    $this->state = 'closeTagOpen';
646
+            if ($this->character($this->char + 1) === '/') {
647
+                $this->char++;
648
+                $this->state = 'closeTagOpen';
649 649
 
650
-                } else {
651
-                    $this->emitToken(
652
-                        array(
653
-                            'type' => self::CHARACTR,
654
-                            'data' => '<'
655
-                        )
656
-                    );
657
-
658
-                    $this->state = 'data';
659
-                }
660
-                break;
650
+            } else {
651
+                $this->emitToken(
652
+                    array(
653
+                        'type' => self::CHARACTR,
654
+                        'data' => '<'
655
+                    )
656
+                );
661 657
 
662
-            case self::PCDATA:
663
-                // If the content model flag is set to the PCDATA state
664
-                // Consume the next input character:
665
-                $this->char++;
666
-                $char = $this->char();
658
+                $this->state = 'data';
659
+            }
660
+            break;
661
+
662
+        case self::PCDATA:
663
+            // If the content model flag is set to the PCDATA state
664
+            // Consume the next input character:
665
+            $this->char++;
666
+            $char = $this->char();
667 667
 
668
-                if ($char === '!') {
669
-                    /* U+0021 EXCLAMATION MARK (!)
668
+            if ($char === '!') {
669
+                /* U+0021 EXCLAMATION MARK (!)
670 670
                     Switch to the markup declaration open state. */
671
-                    $this->state = 'markupDeclarationOpen';
671
+                $this->state = 'markupDeclarationOpen';
672 672
 
673
-                } elseif ($char === '/') {
674
-                    /* U+002F SOLIDUS (/)
673
+            } elseif ($char === '/') {
674
+                /* U+002F SOLIDUS (/)
675 675
                     Switch to the close tag open state. */
676
-                    $this->state = 'closeTagOpen';
676
+                $this->state = 'closeTagOpen';
677 677
 
678
-                } elseif (preg_match('/^[A-Za-z]$/', $char)) {
679
-                    /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
678
+            } elseif (preg_match('/^[A-Za-z]$/', $char)) {
679
+                /* U+0041 LATIN LETTER A through to U+005A LATIN LETTER Z
680 680
                     Create a new start tag token, set its tag name to the lowercase
681 681
                     version of the input character (add 0x0020 to the character's code
682 682
                     point), then switch to the tag name state. (Don't emit the token
683 683
                     yet; further details will be filled in before it is emitted.) */
684
-                    $this->token = array(
685
-                        'name' => strtolower($char),
686
-                        'type' => self::STARTTAG,
687
-                        'attr' => array()
688
-                    );
684
+                $this->token = array(
685
+                    'name' => strtolower($char),
686
+                    'type' => self::STARTTAG,
687
+                    'attr' => array()
688
+                );
689 689
 
690
-                    $this->state = 'tagName';
690
+                $this->state = 'tagName';
691 691
 
692
-                } elseif ($char === '>') {
693
-                    /* U+003E GREATER-THAN SIGN (>)
692
+            } elseif ($char === '>') {
693
+                /* U+003E GREATER-THAN SIGN (>)
694 694
                     Parse error. Emit a U+003C LESS-THAN SIGN character token and a
695 695
                     U+003E GREATER-THAN SIGN character token. Switch to the data state. */
696
-                    $this->emitToken(
697
-                        array(
698
-                            'type' => self::CHARACTR,
699
-                            'data' => '<>'
700
-                        )
701
-                    );
696
+                $this->emitToken(
697
+                    array(
698
+                        'type' => self::CHARACTR,
699
+                        'data' => '<>'
700
+                    )
701
+                );
702 702
 
703
-                    $this->state = 'data';
703
+                $this->state = 'data';
704 704
 
705
-                } elseif ($char === '?') {
706
-                    /* U+003F QUESTION MARK (?)
705
+            } elseif ($char === '?') {
706
+                /* U+003F QUESTION MARK (?)
707 707
                     Parse error. Switch to the bogus comment state. */
708
-                    $this->state = 'bogusComment';
708
+                $this->state = 'bogusComment';
709 709
 
710
-                } else {
711
-                    /* Anything else
710
+            } else {
711
+                /* Anything else
712 712
                     Parse error. Emit a U+003C LESS-THAN SIGN character token and
713 713
                     reconsume the current input character in the data state. */
714
-                    $this->emitToken(
715
-                        array(
716
-                            'type' => self::CHARACTR,
717
-                            'data' => '<'
718
-                        )
719
-                    );
720
-
721
-                    $this->char--;
722
-                    $this->state = 'data';
723
-                }
724
-                break;
714
+                $this->emitToken(
715
+                    array(
716
+                        'type' => self::CHARACTR,
717
+                        'data' => '<'
718
+                    )
719
+                );
720
+
721
+                $this->char--;
722
+                $this->state = 'data';
723
+            }
724
+            break;
725 725
         }
726 726
     }
727 727
 
@@ -1472,34 +1472,34 @@  discard block
 block discarded – undo
1472 1472
 
1473 1473
         switch ($this->character($this->char + 1)) {
1474 1474
             // U+0023 NUMBER SIGN (#)
1475
-            case '#':
1476
-
1477
-                // The behaviour further depends on the character after the
1478
-                // U+0023 NUMBER SIGN:
1479
-                switch ($this->character($this->char + 1)) {
1480
-                    // U+0078 LATIN SMALL LETTER X
1481
-                    // U+0058 LATIN CAPITAL LETTER X
1482
-                    case 'x':
1483
-                    case 'X':
1484
-                        // Follow the steps below, but using the range of
1485
-                        // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1486
-                        // NINE, U+0061 LATIN SMALL LETTER A through to U+0066
1487
-                        // LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
1488
-                        // A, through to U+0046 LATIN CAPITAL LETTER F (in other
1489
-                        // words, 0-9, A-F, a-f).
1490
-                        $char = 1;
1491
-                        $char_class = '0-9A-Fa-f';
1492
-                        break;
1475
+        case '#':
1476
+
1477
+            // The behaviour further depends on the character after the
1478
+            // U+0023 NUMBER SIGN:
1479
+            switch ($this->character($this->char + 1)) {
1480
+                // U+0078 LATIN SMALL LETTER X
1481
+                // U+0058 LATIN CAPITAL LETTER X
1482
+            case 'x':
1483
+            case 'X':
1484
+            // Follow the steps below, but using the range of
1485
+            // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1486
+            // NINE, U+0061 LATIN SMALL LETTER A through to U+0066
1487
+            // LATIN SMALL LETTER F, and U+0041 LATIN CAPITAL LETTER
1488
+            // A, through to U+0046 LATIN CAPITAL LETTER F (in other
1489
+            // words, 0-9, A-F, a-f).
1490
+            $char = 1;
1491
+            $char_class = '0-9A-Fa-f';
1492
+            break;
1493 1493
 
1494
-                    // Anything else
1495
-                    default:
1496
-                        // Follow the steps below, but using the range of
1497
-                        // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1498
-                        // NINE (i.e. just 0-9).
1499
-                        $char = 0;
1500
-                        $char_class = '0-9';
1501
-                        break;
1502
-                }
1494
+            // Anything else
1495
+            default:
1496
+            // Follow the steps below, but using the range of
1497
+            // characters U+0030 DIGIT ZERO through to U+0039 DIGIT
1498
+            // NINE (i.e. just 0-9).
1499
+            $char = 0;
1500
+            $char_class = '0-9';
1501
+            break;
1502
+            }
1503 1503
 
1504 1504
                 // Consume as many characters as match the range of characters
1505 1505
                 // given above.
@@ -1512,31 +1512,31 @@  discard block
 block discarded – undo
1512 1512
                 break;
1513 1513
 
1514 1514
             // Anything else
1515
-            default:
1516
-                // Consume the maximum number of characters possible, with the
1517
-                // consumed characters case-sensitively matching one of the
1518
-                // identifiers in the first column of the entities table.
1519
-                $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1520
-                $len = strlen($e_name);
1521
-
1522
-                for ($c = 1; $c <= $len; $c++) {
1523
-                    $id = substr($e_name, 0, $c);
1524
-                    $this->char++;
1525
-
1526
-                    if (in_array($id, $this->entities)) {
1527
-                        if ($e_name[$c - 1] !== ';') {
1528
-                            if ($c < $len && $e_name[$c] == ';') {
1529
-                                $this->char++; // consume extra semicolon
1530
-                            }
1515
+        default:
1516
+            // Consume the maximum number of characters possible, with the
1517
+            // consumed characters case-sensitively matching one of the
1518
+            // identifiers in the first column of the entities table.
1519
+            $e_name = $this->characters('0-9A-Za-z;', $this->char + 1);
1520
+            $len = strlen($e_name);
1521
+
1522
+            for ($c = 1; $c <= $len; $c++) {
1523
+                $id = substr($e_name, 0, $c);
1524
+                $this->char++;
1525
+
1526
+                if (in_array($id, $this->entities)) {
1527
+                    if ($e_name[$c - 1] !== ';') {
1528
+                        if ($c < $len && $e_name[$c] == ';') {
1529
+                            $this->char++; // consume extra semicolon
1531 1530
                         }
1532
-                        $entity = $id;
1533
-                        break;
1534 1531
                     }
1532
+                    $entity = $id;
1533
+                    break;
1535 1534
                 }
1535
+            }
1536 1536
 
1537
-                $cond = isset($entity);
1538
-                // The rest of the parsing happens bellow.
1539
-                break;
1537
+            $cond = isset($entity);
1538
+            // The rest of the parsing happens bellow.
1539
+            break;
1540 1540
         }
1541 1541
 
1542 1542
         if (!$cond) {
@@ -1713,18 +1713,18 @@  discard block
 block discarded – undo
1713 1713
     public function emitToken($token)
1714 1714
     {
1715 1715
         switch ($this->phase) {
1716
-            case self::INIT_PHASE:
1717
-                return $this->initPhase($token);
1718
-                break;
1719
-            case self::ROOT_PHASE:
1720
-                return $this->rootElementPhase($token);
1721
-                break;
1722
-            case self::MAIN_PHASE:
1723
-                return $this->mainPhase($token);
1724
-                break;
1725
-            case self::END_PHASE :
1726
-                return $this->trailingEndPhase($token);
1727
-                break;
1716
+        case self::INIT_PHASE:
1717
+            return $this->initPhase($token);
1718
+            break;
1719
+        case self::ROOT_PHASE:
1720
+            return $this->rootElementPhase($token);
1721
+            break;
1722
+        case self::MAIN_PHASE:
1723
+            return $this->mainPhase($token);
1724
+            break;
1725
+        case self::END_PHASE :
1726
+            return $this->trailingEndPhase($token);
1727
+            break;
1728 1728
         }
1729 1729
     }
1730 1730
 
@@ -1865,51 +1865,51 @@  discard block
 block discarded – undo
1865 1865
         } else {
1866 1866
             /* Depends on the insertion mode: */
1867 1867
             switch ($this->mode) {
1868
-                case self::BEFOR_HEAD:
1869
-                    return $this->beforeHead($token);
1870
-                    break;
1871
-                case self::IN_HEAD:
1872
-                    return $this->inHead($token);
1873
-                    break;
1874
-                case self::AFTER_HEAD:
1875
-                    return $this->afterHead($token);
1876
-                    break;
1877
-                case self::IN_BODY:
1878
-                    return $this->inBody($token);
1879
-                    break;
1880
-                case self::IN_TABLE:
1881
-                    return $this->inTable($token);
1882
-                    break;
1883
-                case self::IN_CAPTION:
1884
-                    return $this->inCaption($token);
1885
-                    break;
1886
-                case self::IN_CGROUP:
1887
-                    return $this->inColumnGroup($token);
1888
-                    break;
1889
-                case self::IN_TBODY:
1890
-                    return $this->inTableBody($token);
1891
-                    break;
1892
-                case self::IN_ROW:
1893
-                    return $this->inRow($token);
1894
-                    break;
1895
-                case self::IN_CELL:
1896
-                    return $this->inCell($token);
1897
-                    break;
1898
-                case self::IN_SELECT:
1899
-                    return $this->inSelect($token);
1900
-                    break;
1901
-                case self::AFTER_BODY:
1902
-                    return $this->afterBody($token);
1903
-                    break;
1904
-                case self::IN_FRAME:
1905
-                    return $this->inFrameset($token);
1906
-                    break;
1907
-                case self::AFTR_FRAME:
1908
-                    return $this->afterFrameset($token);
1909
-                    break;
1910
-                case self::END_PHASE:
1911
-                    return $this->trailingEndPhase($token);
1912
-                    break;
1868
+            case self::BEFOR_HEAD:
1869
+                return $this->beforeHead($token);
1870
+                break;
1871
+            case self::IN_HEAD:
1872
+                return $this->inHead($token);
1873
+                break;
1874
+            case self::AFTER_HEAD:
1875
+                return $this->afterHead($token);
1876
+                break;
1877
+            case self::IN_BODY:
1878
+                return $this->inBody($token);
1879
+                break;
1880
+            case self::IN_TABLE:
1881
+                return $this->inTable($token);
1882
+                break;
1883
+            case self::IN_CAPTION:
1884
+                return $this->inCaption($token);
1885
+                break;
1886
+            case self::IN_CGROUP:
1887
+                return $this->inColumnGroup($token);
1888
+                break;
1889
+            case self::IN_TBODY:
1890
+                return $this->inTableBody($token);
1891
+                break;
1892
+            case self::IN_ROW:
1893
+                return $this->inRow($token);
1894
+                break;
1895
+            case self::IN_CELL:
1896
+                return $this->inCell($token);
1897
+                break;
1898
+            case self::IN_SELECT:
1899
+                return $this->inSelect($token);
1900
+                break;
1901
+            case self::AFTER_BODY:
1902
+                return $this->afterBody($token);
1903
+                break;
1904
+            case self::IN_FRAME:
1905
+                return $this->inFrameset($token);
1906
+                break;
1907
+            case self::AFTR_FRAME:
1908
+                return $this->afterFrameset($token);
1909
+                break;
1910
+            case self::END_PHASE:
1911
+                return $this->trailingEndPhase($token);
1912
+                break;
1913 1913
             }
1914 1914
         }
1915 1915
     }
@@ -2179,233 +2179,233 @@  discard block
 block discarded – undo
2179 2179
 
2180 2180
         switch ($token['type']) {
2181 2181
             /* A character token */
2182
-            case HTML5::CHARACTR:
2183
-                /* Reconstruct the active formatting elements, if any. */
2184
-                $this->reconstructActiveFormattingElements();
2182
+        case HTML5::CHARACTR:
2183
+            /* Reconstruct the active formatting elements, if any. */
2184
+            $this->reconstructActiveFormattingElements();
2185 2185
 
2186
-                /* Append the token's character to the current node. */
2187
-                $this->insertText($token['data']);
2188
-                break;
2186
+            /* Append the token's character to the current node. */
2187
+            $this->insertText($token['data']);
2188
+            break;
2189 2189
 
2190
-            /* A comment token */
2191
-            case HTML5::COMMENT:
2192
-                /* Append a Comment node to the current node with the data
2190
+        /* A comment token */
2191
+        case HTML5::COMMENT:
2192
+            /* Append a Comment node to the current node with the data
2193 2193
                 attribute set to the data given in the comment token. */
2194
-                $this->insertComment($token['data']);
2195
-                break;
2194
+            $this->insertComment($token['data']);
2195
+            break;
2196 2196
 
2197
-            case HTML5::STARTTAG:
2198
-                switch ($token['name']) {
2199
-                    /* A start tag token whose tag name is one of: "script",
2197
+        case HTML5::STARTTAG:
2198
+            switch ($token['name']) {
2199
+                /* A start tag token whose tag name is one of: "script",
2200 2200
                     "style" */
2201
-                    case 'script':
2202
-                    case 'style':
2203
-                        /* Process the token as if the insertion mode had been "in
2201
+            case 'script':
2202
+            case 'style':
2203
+            /* Process the token as if the insertion mode had been "in
2204 2204
                         head". */
2205
-                        return $this->inHead($token);
2206
-                        break;
2205
+            return $this->inHead($token);
2206
+            break;
2207 2207
 
2208
-                    /* A start tag token whose tag name is one of: "base", "link",
2208
+            /* A start tag token whose tag name is one of: "base", "link",
2209 2209
                     "meta", "title" */
2210
-                    case 'base':
2211
-                    case 'link':
2212
-                    case 'meta':
2213
-                    case 'title':
2214
-                        /* Parse error. Process the token as if the insertion mode
2210
+            case 'base':
2211
+            case 'link':
2212
+            case 'meta':
2213
+            case 'title':
2214
+            /* Parse error. Process the token as if the insertion mode
2215 2215
                         had    been "in head". */
2216
-                        return $this->inHead($token);
2217
-                        break;
2216
+            return $this->inHead($token);
2217
+            break;
2218 2218
 
2219
-                    /* A start tag token with the tag name "body" */
2220
-                    case 'body':
2221
-                        /* Parse error. If the second element on the stack of open
2219
+            /* A start tag token with the tag name "body" */
2220
+            case 'body':
2221
+            /* Parse error. If the second element on the stack of open
2222 2222
                         elements is not a body element, or, if the stack of open
2223 2223
                         elements has only one node on it, then ignore the token.
2224 2224
                         (innerHTML case) */
2225
-                        if (count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
2226
-                            // Ignore
2225
+            if (count($this->stack) === 1 || $this->stack[1]->nodeName !== 'body') {
2226
+            // Ignore
2227 2227
 
2228
-                            /* Otherwise, for each attribute on the token, check to see
2228
+            /* Otherwise, for each attribute on the token, check to see
2229 2229
                             if the attribute is already present on the body element (the
2230 2230
                             second element)    on the stack of open elements. If it is not,
2231 2231
                             add the attribute and its corresponding value to that
2232 2232
                             element. */
2233
-                        } else {
2234
-                            foreach ($token['attr'] as $attr) {
2235
-                                if (!$this->stack[1]->hasAttribute($attr['name'])) {
2236
-                                    $this->stack[1]->setAttribute($attr['name'], $attr['value']);
2237
-                                }
2238
-                            }
2239
-                        }
2240
-                        break;
2233
+            } else {
2234
+            foreach ($token['attr'] as $attr) {
2235
+                if (!$this->stack[1]->hasAttribute($attr['name'])) {
2236
+                    $this->stack[1]->setAttribute($attr['name'], $attr['value']);
2237
+                }
2238
+            }
2239
+            }
2240
+            break;
2241 2241
 
2242
-                    /* A start tag whose tag name is one of: "address",
2242
+            /* A start tag whose tag name is one of: "address",
2243 2243
                     "blockquote", "center", "dir", "div", "dl", "fieldset",
2244 2244
                     "listing", "menu", "ol", "p", "ul" */
2245
-                    case 'address':
2246
-                    case 'blockquote':
2247
-                    case 'center':
2248
-                    case 'dir':
2249
-                    case 'div':
2250
-                    case 'dl':
2251
-                    case 'fieldset':
2252
-                    case 'listing':
2253
-                    case 'menu':
2254
-                    case 'ol':
2255
-                    case 'p':
2256
-                    case 'ul':
2257
-                        /* If the stack of open elements has a p element in scope,
2245
+            case 'address':
2246
+            case 'blockquote':
2247
+            case 'center':
2248
+            case 'dir':
2249
+            case 'div':
2250
+            case 'dl':
2251
+            case 'fieldset':
2252
+            case 'listing':
2253
+            case 'menu':
2254
+            case 'ol':
2255
+            case 'p':
2256
+            case 'ul':
2257
+            /* If the stack of open elements has a p element in scope,
2258 2258
                         then act as if an end tag with the tag name p had been
2259 2259
                         seen. */
2260
-                        if ($this->elementInScope('p')) {
2261
-                            $this->emitToken(
2262
-                                array(
2263
-                                    'name' => 'p',
2264
-                                    'type' => HTML5::ENDTAG
2265
-                                )
2266
-                            );
2267
-                        }
2260
+            if ($this->elementInScope('p')) {
2261
+            $this->emitToken(
2262
+                array(
2263
+                    'name' => 'p',
2264
+                    'type' => HTML5::ENDTAG
2265
+                )
2266
+            );
2267
+            }
2268 2268
 
2269
-                        /* Insert an HTML element for the token. */
2270
-                        $this->insertElement($token);
2271
-                        break;
2269
+            /* Insert an HTML element for the token. */
2270
+            $this->insertElement($token);
2271
+            break;
2272 2272
 
2273
-                    /* A start tag whose tag name is "form" */
2274
-                    case 'form':
2275
-                        /* If the form element pointer is not null, ignore the
2273
+            /* A start tag whose tag name is "form" */
2274
+            case 'form':
2275
+            /* If the form element pointer is not null, ignore the
2276 2276
                         token with a parse error. */
2277
-                        if ($this->form_pointer !== null) {
2278
-                            // Ignore.
2277
+            if ($this->form_pointer !== null) {
2278
+            // Ignore.
2279 2279
 
2280
-                            /* Otherwise: */
2281
-                        } else {
2282
-                            /* If the stack of open elements has a p element in
2280
+            /* Otherwise: */
2281
+            } else {
2282
+            /* If the stack of open elements has a p element in
2283 2283
                             scope, then act as if an end tag with the tag name p
2284 2284
                             had been seen. */
2285
-                            if ($this->elementInScope('p')) {
2286
-                                $this->emitToken(
2287
-                                    array(
2288
-                                        'name' => 'p',
2289
-                                        'type' => HTML5::ENDTAG
2290
-                                    )
2291
-                                );
2292
-                            }
2293
-
2294
-                            /* Insert an HTML element for the token, and set the
2285
+            if ($this->elementInScope('p')) {
2286
+                $this->emitToken(
2287
+                    array(
2288
+                        'name' => 'p',
2289
+                        'type' => HTML5::ENDTAG
2290
+                    )
2291
+                );
2292
+            }
2293
+
2294
+            /* Insert an HTML element for the token, and set the
2295 2295
                             form element pointer to point to the element created. */
2296
-                            $element = $this->insertElement($token);
2297
-                            $this->form_pointer = $element;
2298
-                        }
2299
-                        break;
2296
+            $element = $this->insertElement($token);
2297
+            $this->form_pointer = $element;
2298
+            }
2299
+            break;
2300 2300
 
2301
-                    /* A start tag whose tag name is "li", "dd" or "dt" */
2302
-                    case 'li':
2303
-                    case 'dd':
2304
-                    case 'dt':
2305
-                        /* If the stack of open elements has a p  element in scope,
2301
+            /* A start tag whose tag name is "li", "dd" or "dt" */
2302
+            case 'li':
2303
+            case 'dd':
2304
+            case 'dt':
2305
+            /* If the stack of open elements has a p  element in scope,
2306 2306
                         then act as if an end tag with the tag name p had been
2307 2307
                         seen. */
2308
-                        if ($this->elementInScope('p')) {
2309
-                            $this->emitToken(
2310
-                                array(
2311
-                                    'name' => 'p',
2312
-                                    'type' => HTML5::ENDTAG
2313
-                                )
2314
-                            );
2315
-                        }
2308
+            if ($this->elementInScope('p')) {
2309
+            $this->emitToken(
2310
+                array(
2311
+                    'name' => 'p',
2312
+                    'type' => HTML5::ENDTAG
2313
+                )
2314
+            );
2315
+            }
2316 2316
 
2317
-                        $stack_length = count($this->stack) - 1;
2317
+            $stack_length = count($this->stack) - 1;
2318 2318
 
2319
-                        for ($n = $stack_length; 0 <= $n; $n--) {
2320
-                            /* 1. Initialise node to be the current node (the
2319
+            for ($n = $stack_length; 0 <= $n; $n--) {
2320
+            /* 1. Initialise node to be the current node (the
2321 2321
                             bottommost node of the stack). */
2322
-                            $stop = false;
2323
-                            $node = $this->stack[$n];
2324
-                            $cat = $this->getElementCategory($node->tagName);
2322
+            $stop = false;
2323
+            $node = $this->stack[$n];
2324
+            $cat = $this->getElementCategory($node->tagName);
2325 2325
 
2326
-                            /* 2. If node is an li, dd or dt element, then pop all
2326
+            /* 2. If node is an li, dd or dt element, then pop all
2327 2327
                             the    nodes from the current node up to node, including
2328 2328
                             node, then stop this algorithm. */
2329
-                            if ($token['name'] === $node->tagName || ($token['name'] !== 'li'
2330
-                                    && ($node->tagName === 'dd' || $node->tagName === 'dt'))
2331
-                            ) {
2332
-                                for ($x = $stack_length; $x >= $n; $x--) {
2333
-                                    array_pop($this->stack);
2334
-                                }
2329
+            if ($token['name'] === $node->tagName || ($token['name'] !== 'li'
2330
+                    && ($node->tagName === 'dd' || $node->tagName === 'dt'))
2331
+            ) {
2332
+                for ($x = $stack_length; $x >= $n; $x--) {
2333
+                    array_pop($this->stack);
2334
+                }
2335 2335
 
2336
-                                break;
2337
-                            }
2336
+                break;
2337
+            }
2338 2338
 
2339
-                            /* 3. If node is not in the formatting category, and is
2339
+            /* 3. If node is not in the formatting category, and is
2340 2340
                             not    in the phrasing category, and is not an address or
2341 2341
                             div element, then stop this algorithm. */
2342
-                            if ($cat !== self::FORMATTING && $cat !== self::PHRASING &&
2343
-                                $node->tagName !== 'address' && $node->tagName !== 'div'
2344
-                            ) {
2345
-                                break;
2346
-                            }
2347
-                        }
2342
+            if ($cat !== self::FORMATTING && $cat !== self::PHRASING &&
2343
+                $node->tagName !== 'address' && $node->tagName !== 'div'
2344
+            ) {
2345
+                break;
2346
+            }
2347
+            }
2348 2348
 
2349
-                        /* Finally, insert an HTML element with the same tag
2349
+            /* Finally, insert an HTML element with the same tag
2350 2350
                         name as the    token's. */
2351
-                        $this->insertElement($token);
2352
-                        break;
2351
+            $this->insertElement($token);
2352
+            break;
2353 2353
 
2354
-                    /* A start tag token whose tag name is "plaintext" */
2355
-                    case 'plaintext':
2356
-                        /* If the stack of open elements has a p  element in scope,
2354
+            /* A start tag token whose tag name is "plaintext" */
2355
+            case 'plaintext':
2356
+            /* If the stack of open elements has a p  element in scope,
2357 2357
                         then act as if an end tag with the tag name p had been
2358 2358
                         seen. */
2359
-                        if ($this->elementInScope('p')) {
2360
-                            $this->emitToken(
2361
-                                array(
2362
-                                    'name' => 'p',
2363
-                                    'type' => HTML5::ENDTAG
2364
-                                )
2365
-                            );
2366
-                        }
2359
+            if ($this->elementInScope('p')) {
2360
+            $this->emitToken(
2361
+                array(
2362
+                    'name' => 'p',
2363
+                    'type' => HTML5::ENDTAG
2364
+                )
2365
+            );
2366
+            }
2367 2367
 
2368
-                        /* Insert an HTML element for the token. */
2369
-                        $this->insertElement($token);
2368
+            /* Insert an HTML element for the token. */
2369
+            $this->insertElement($token);
2370 2370
 
2371
-                        return HTML5::PLAINTEXT;
2372
-                        break;
2371
+            return HTML5::PLAINTEXT;
2372
+            break;
2373 2373
 
2374
-                    /* A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
2374
+            /* A start tag whose tag name is one of: "h1", "h2", "h3", "h4",
2375 2375
                     "h5", "h6" */
2376
-                    case 'h1':
2377
-                    case 'h2':
2378
-                    case 'h3':
2379
-                    case 'h4':
2380
-                    case 'h5':
2381
-                    case 'h6':
2382
-                        /* If the stack of open elements has a p  element in scope,
2376
+            case 'h1':
2377
+            case 'h2':
2378
+            case 'h3':
2379
+            case 'h4':
2380
+            case 'h5':
2381
+            case 'h6':
2382
+            /* If the stack of open elements has a p  element in scope,
2383 2383
                         then act as if an end tag with the tag name p had been seen. */
2384
-                        if ($this->elementInScope('p')) {
2385
-                            $this->emitToken(
2386
-                                array(
2387
-                                    'name' => 'p',
2388
-                                    'type' => HTML5::ENDTAG
2389
-                                )
2390
-                            );
2391
-                        }
2384
+            if ($this->elementInScope('p')) {
2385
+            $this->emitToken(
2386
+                array(
2387
+                    'name' => 'p',
2388
+                    'type' => HTML5::ENDTAG
2389
+                )
2390
+            );
2391
+            }
2392 2392
 
2393
-                        /* If the stack of open elements has in scope an element whose
2393
+            /* If the stack of open elements has in scope an element whose
2394 2394
                         tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6", then
2395 2395
                         this is a parse error; pop elements from the stack until an
2396 2396
                         element with one of those tag names has been popped from the
2397 2397
                         stack. */
2398
-                        while ($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
2399
-                            array_pop($this->stack);
2400
-                        }
2398
+            while ($this->elementInScope(array('h1', 'h2', 'h3', 'h4', 'h5', 'h6'))) {
2399
+            array_pop($this->stack);
2400
+            }
2401 2401
 
2402
-                        /* Insert an HTML element for the token. */
2403
-                        $this->insertElement($token);
2404
-                        break;
2402
+            /* Insert an HTML element for the token. */
2403
+            $this->insertElement($token);
2404
+            break;
2405 2405
 
2406
-                    /* A start tag whose tag name is "a" */
2407
-                    case 'a':
2408
-                        /* If the list of active formatting elements contains
2406
+            /* A start tag whose tag name is "a" */
2407
+            case 'a':
2408
+            /* If the list of active formatting elements contains
2409 2409
                         an element whose tag name is "a" between the end of the
2410 2410
                         list and the last marker on the list (or the start of
2411 2411
                         the list if there is no marker on the list), then this
@@ -2414,901 +2414,901 @@  discard block
 block discarded – undo
2414 2414
                         of active formatting elements and the stack of open
2415 2415
                         elements if the end tag didn't already remove it (it
2416 2416
                         might not have if the element is not in table scope). */
2417
-                        $leng = count($this->a_formatting);
2418
-
2419
-                        for ($n = $leng - 1; $n >= 0; $n--) {
2420
-                            if ($this->a_formatting[$n] === self::MARKER) {
2421
-                                break;
2422
-
2423
-                            } elseif ($this->a_formatting[$n]->nodeName === 'a') {
2424
-                                $this->emitToken(
2425
-                                    array(
2426
-                                        'name' => 'a',
2427
-                                        'type' => HTML5::ENDTAG
2428
-                                    )
2429
-                                );
2430
-                                break;
2431
-                            }
2432
-                        }
2417
+            $leng = count($this->a_formatting);
2433 2418
 
2434
-                        /* Reconstruct the active formatting elements, if any. */
2435
-                        $this->reconstructActiveFormattingElements();
2419
+            for ($n = $leng - 1; $n >= 0; $n--) {
2420
+            if ($this->a_formatting[$n] === self::MARKER) {
2421
+                break;
2436 2422
 
2437
-                        /* Insert an HTML element for the token. */
2438
-                        $el = $this->insertElement($token);
2423
+            } elseif ($this->a_formatting[$n]->nodeName === 'a') {
2424
+                $this->emitToken(
2425
+                    array(
2426
+                        'name' => 'a',
2427
+                        'type' => HTML5::ENDTAG
2428
+                    )
2429
+                );
2430
+                break;
2431
+            }
2432
+            }
2439 2433
 
2440
-                        /* Add that element to the list of active formatting
2434
+            /* Reconstruct the active formatting elements, if any. */
2435
+            $this->reconstructActiveFormattingElements();
2436
+
2437
+            /* Insert an HTML element for the token. */
2438
+            $el = $this->insertElement($token);
2439
+
2440
+            /* Add that element to the list of active formatting
2441 2441
                         elements. */
2442
-                        $this->a_formatting[] = $el;
2443
-                        break;
2442
+            $this->a_formatting[] = $el;
2443
+            break;
2444 2444
 
2445
-                    /* A start tag whose tag name is one of: "b", "big", "em", "font",
2445
+            /* A start tag whose tag name is one of: "b", "big", "em", "font",
2446 2446
                     "i", "nobr", "s", "small", "strike", "strong", "tt", "u" */
2447
-                    case 'b':
2448
-                    case 'big':
2449
-                    case 'em':
2450
-                    case 'font':
2451
-                    case 'i':
2452
-                    case 'nobr':
2453
-                    case 's':
2454
-                    case 'small':
2455
-                    case 'strike':
2456
-                    case 'strong':
2457
-                    case 'tt':
2458
-                    case 'u':
2459
-                        /* Reconstruct the active formatting elements, if any. */
2460
-                        $this->reconstructActiveFormattingElements();
2461
-
2462
-                        /* Insert an HTML element for the token. */
2463
-                        $el = $this->insertElement($token);
2464
-
2465
-                        /* Add that element to the list of active formatting
2447
+            case 'b':
2448
+            case 'big':
2449
+            case 'em':
2450
+            case 'font':
2451
+            case 'i':
2452
+            case 'nobr':
2453
+            case 's':
2454
+            case 'small':
2455
+            case 'strike':
2456
+            case 'strong':
2457
+            case 'tt':
2458
+            case 'u':
2459
+            /* Reconstruct the active formatting elements, if any. */
2460
+            $this->reconstructActiveFormattingElements();
2461
+
2462
+            /* Insert an HTML element for the token. */
2463
+            $el = $this->insertElement($token);
2464
+
2465
+            /* Add that element to the list of active formatting
2466 2466
                         elements. */
2467
-                        $this->a_formatting[] = $el;
2468
-                        break;
2467
+            $this->a_formatting[] = $el;
2468
+            break;
2469 2469
 
2470
-                    /* A start tag token whose tag name is "button" */
2471
-                    case 'button':
2472
-                        /* If the stack of open elements has a button element in scope,
2470
+            /* A start tag token whose tag name is "button" */
2471
+            case 'button':
2472
+            /* If the stack of open elements has a button element in scope,
2473 2473
                         then this is a parse error; act as if an end tag with the tag
2474 2474
                         name "button" had been seen, then reprocess the token. (We don't
2475 2475
                         do that. Unnecessary.) */
2476
-                        if ($this->elementInScope('button')) {
2477
-                            $this->inBody(
2478
-                                array(
2479
-                                    'name' => 'button',
2480
-                                    'type' => HTML5::ENDTAG
2481
-                                )
2482
-                            );
2483
-                        }
2476
+            if ($this->elementInScope('button')) {
2477
+            $this->inBody(
2478
+                array(
2479
+                    'name' => 'button',
2480
+                    'type' => HTML5::ENDTAG
2481
+                )
2482
+            );
2483
+            }
2484 2484
 
2485
-                        /* Reconstruct the active formatting elements, if any. */
2486
-                        $this->reconstructActiveFormattingElements();
2485
+            /* Reconstruct the active formatting elements, if any. */
2486
+            $this->reconstructActiveFormattingElements();
2487 2487
 
2488
-                        /* Insert an HTML element for the token. */
2489
-                        $this->insertElement($token);
2488
+            /* Insert an HTML element for the token. */
2489
+            $this->insertElement($token);
2490 2490
 
2491
-                        /* Insert a marker at the end of the list of active
2491
+            /* Insert a marker at the end of the list of active
2492 2492
                         formatting elements. */
2493
-                        $this->a_formatting[] = self::MARKER;
2494
-                        break;
2493
+            $this->a_formatting[] = self::MARKER;
2494
+            break;
2495 2495
 
2496
-                    /* A start tag token whose tag name is one of: "marquee", "object" */
2497
-                    case 'marquee':
2498
-                    case 'object':
2499
-                        /* Reconstruct the active formatting elements, if any. */
2500
-                        $this->reconstructActiveFormattingElements();
2496
+            /* A start tag token whose tag name is one of: "marquee", "object" */
2497
+            case 'marquee':
2498
+            case 'object':
2499
+            /* Reconstruct the active formatting elements, if any. */
2500
+            $this->reconstructActiveFormattingElements();
2501 2501
 
2502
-                        /* Insert an HTML element for the token. */
2503
-                        $this->insertElement($token);
2502
+            /* Insert an HTML element for the token. */
2503
+            $this->insertElement($token);
2504 2504
 
2505
-                        /* Insert a marker at the end of the list of active
2505
+            /* Insert a marker at the end of the list of active
2506 2506
                         formatting elements. */
2507
-                        $this->a_formatting[] = self::MARKER;
2508
-                        break;
2507
+            $this->a_formatting[] = self::MARKER;
2508
+            break;
2509 2509
 
2510
-                    /* A start tag token whose tag name is "xmp" */
2511
-                    case 'xmp':
2512
-                        /* Reconstruct the active formatting elements, if any. */
2513
-                        $this->reconstructActiveFormattingElements();
2510
+            /* A start tag token whose tag name is "xmp" */
2511
+            case 'xmp':
2512
+            /* Reconstruct the active formatting elements, if any. */
2513
+            $this->reconstructActiveFormattingElements();
2514 2514
 
2515
-                        /* Insert an HTML element for the token. */
2516
-                        $this->insertElement($token);
2515
+            /* Insert an HTML element for the token. */
2516
+            $this->insertElement($token);
2517 2517
 
2518
-                        /* Switch the content model flag to the CDATA state. */
2519
-                        return HTML5::CDATA;
2520
-                        break;
2518
+            /* Switch the content model flag to the CDATA state. */
2519
+            return HTML5::CDATA;
2520
+            break;
2521 2521
 
2522
-                    /* A start tag whose tag name is "table" */
2523
-                    case 'table':
2524
-                        /* If the stack of open elements has a p element in scope,
2522
+            /* A start tag whose tag name is "table" */
2523
+            case 'table':
2524
+            /* If the stack of open elements has a p element in scope,
2525 2525
                         then act as if an end tag with the tag name p had been seen. */
2526
-                        if ($this->elementInScope('p')) {
2527
-                            $this->emitToken(
2528
-                                array(
2529
-                                    'name' => 'p',
2530
-                                    'type' => HTML5::ENDTAG
2531
-                                )
2532
-                            );
2533
-                        }
2526
+            if ($this->elementInScope('p')) {
2527
+            $this->emitToken(
2528
+                array(
2529
+                    'name' => 'p',
2530
+                    'type' => HTML5::ENDTAG
2531
+                )
2532
+            );
2533
+            }
2534 2534
 
2535
-                        /* Insert an HTML element for the token. */
2536
-                        $this->insertElement($token);
2535
+            /* Insert an HTML element for the token. */
2536
+            $this->insertElement($token);
2537 2537
 
2538
-                        /* Change the insertion mode to "in table". */
2539
-                        $this->mode = self::IN_TABLE;
2540
-                        break;
2538
+            /* Change the insertion mode to "in table". */
2539
+            $this->mode = self::IN_TABLE;
2540
+            break;
2541 2541
 
2542
-                    /* A start tag whose tag name is one of: "area", "basefont",
2542
+            /* A start tag whose tag name is one of: "area", "basefont",
2543 2543
                     "bgsound", "br", "embed", "img", "param", "spacer", "wbr" */
2544
-                    case 'area':
2545
-                    case 'basefont':
2546
-                    case 'bgsound':
2547
-                    case 'br':
2548
-                    case 'embed':
2549
-                    case 'img':
2550
-                    case 'param':
2551
-                    case 'spacer':
2552
-                    case 'wbr':
2553
-                        /* Reconstruct the active formatting elements, if any. */
2554
-                        $this->reconstructActiveFormattingElements();
2555
-
2556
-                        /* Insert an HTML element for the token. */
2557
-                        $this->insertElement($token);
2558
-
2559
-                        /* Immediately pop the current node off the stack of open elements. */
2560
-                        array_pop($this->stack);
2561
-                        break;
2544
+            case 'area':
2545
+            case 'basefont':
2546
+            case 'bgsound':
2547
+            case 'br':
2548
+            case 'embed':
2549
+            case 'img':
2550
+            case 'param':
2551
+            case 'spacer':
2552
+            case 'wbr':
2553
+            /* Reconstruct the active formatting elements, if any. */
2554
+            $this->reconstructActiveFormattingElements();
2555
+
2556
+            /* Insert an HTML element for the token. */
2557
+            $this->insertElement($token);
2562 2558
 
2563
-                    /* A start tag whose tag name is "hr" */
2564
-                    case 'hr':
2565
-                        /* If the stack of open elements has a p element in scope,
2559
+            /* Immediately pop the current node off the stack of open elements. */
2560
+            array_pop($this->stack);
2561
+            break;
2562
+
2563
+            /* A start tag whose tag name is "hr" */
2564
+            case 'hr':
2565
+            /* If the stack of open elements has a p element in scope,
2566 2566
                         then act as if an end tag with the tag name p had been seen. */
2567
-                        if ($this->elementInScope('p')) {
2568
-                            $this->emitToken(
2569
-                                array(
2570
-                                    'name' => 'p',
2571
-                                    'type' => HTML5::ENDTAG
2572
-                                )
2573
-                            );
2574
-                        }
2567
+            if ($this->elementInScope('p')) {
2568
+            $this->emitToken(
2569
+                array(
2570
+                    'name' => 'p',
2571
+                    'type' => HTML5::ENDTAG
2572
+                )
2573
+            );
2574
+            }
2575 2575
 
2576
-                        /* Insert an HTML element for the token. */
2577
-                        $this->insertElement($token);
2576
+            /* Insert an HTML element for the token. */
2577
+            $this->insertElement($token);
2578 2578
 
2579
-                        /* Immediately pop the current node off the stack of open elements. */
2580
-                        array_pop($this->stack);
2581
-                        break;
2579
+            /* Immediately pop the current node off the stack of open elements. */
2580
+            array_pop($this->stack);
2581
+            break;
2582 2582
 
2583
-                    /* A start tag whose tag name is "image" */
2584
-                    case 'image':
2585
-                        /* Parse error. Change the token's tag name to "img" and
2583
+            /* A start tag whose tag name is "image" */
2584
+            case 'image':
2585
+            /* Parse error. Change the token's tag name to "img" and
2586 2586
                         reprocess it. (Don't ask.) */
2587
-                        $token['name'] = 'img';
2588
-                        return $this->inBody($token);
2589
-                        break;
2587
+            $token['name'] = 'img';
2588
+            return $this->inBody($token);
2589
+            break;
2590 2590
 
2591
-                    /* A start tag whose tag name is "input" */
2592
-                    case 'input':
2593
-                        /* Reconstruct the active formatting elements, if any. */
2594
-                        $this->reconstructActiveFormattingElements();
2591
+            /* A start tag whose tag name is "input" */
2592
+            case 'input':
2593
+            /* Reconstruct the active formatting elements, if any. */
2594
+            $this->reconstructActiveFormattingElements();
2595 2595
 
2596
-                        /* Insert an input element for the token. */
2597
-                        $element = $this->insertElement($token, false);
2596
+            /* Insert an input element for the token. */
2597
+            $element = $this->insertElement($token, false);
2598 2598
 
2599
-                        /* If the form element pointer is not null, then associate the
2599
+            /* If the form element pointer is not null, then associate the
2600 2600
                         input element with the form element pointed to by the form
2601 2601
                         element pointer. */
2602
-                        $this->form_pointer !== null
2603
-                            ? $this->form_pointer->appendChild($element)
2604
-                            : end($this->stack)->appendChild($element);
2602
+            $this->form_pointer !== null
2603
+            ? $this->form_pointer->appendChild($element)
2604
+            : end($this->stack)->appendChild($element);
2605 2605
 
2606
-                        /* Pop that input element off the stack of open elements. */
2607
-                        array_pop($this->stack);
2608
-                        break;
2606
+            /* Pop that input element off the stack of open elements. */
2607
+            array_pop($this->stack);
2608
+            break;
2609 2609
 
2610
-                    /* A start tag whose tag name is "isindex" */
2611
-                    case 'isindex':
2612
-                        /* Parse error. */
2613
-                        // w/e
2610
+            /* A start tag whose tag name is "isindex" */
2611
+            case 'isindex':
2612
+            /* Parse error. */
2613
+            // w/e
2614 2614
 
2615
-                        /* If the form element pointer is not null,
2615
+            /* If the form element pointer is not null,
2616 2616
                         then ignore the token. */
2617
-                        if ($this->form_pointer === null) {
2618
-                            /* Act as if a start tag token with the tag name "form" had
2617
+            if ($this->form_pointer === null) {
2618
+            /* Act as if a start tag token with the tag name "form" had
2619 2619
                             been seen. */
2620
-                            $this->inBody(
2621
-                                array(
2622
-                                    'name' => 'body',
2623
-                                    'type' => HTML5::STARTTAG,
2624
-                                    'attr' => array()
2625
-                                )
2626
-                            );
2627
-
2628
-                            /* Act as if a start tag token with the tag name "hr" had
2620
+            $this->inBody(
2621
+                array(
2622
+                    'name' => 'body',
2623
+                    'type' => HTML5::STARTTAG,
2624
+                    'attr' => array()
2625
+                )
2626
+            );
2627
+
2628
+            /* Act as if a start tag token with the tag name "hr" had
2629 2629
                             been seen. */
2630
-                            $this->inBody(
2631
-                                array(
2632
-                                    'name' => 'hr',
2633
-                                    'type' => HTML5::STARTTAG,
2634
-                                    'attr' => array()
2635
-                                )
2636
-                            );
2637
-
2638
-                            /* Act as if a start tag token with the tag name "p" had
2630
+            $this->inBody(
2631
+                array(
2632
+                    'name' => 'hr',
2633
+                    'type' => HTML5::STARTTAG,
2634
+                    'attr' => array()
2635
+                )
2636
+            );
2637
+
2638
+            /* Act as if a start tag token with the tag name "p" had
2639 2639
                             been seen. */
2640
-                            $this->inBody(
2641
-                                array(
2642
-                                    'name' => 'p',
2643
-                                    'type' => HTML5::STARTTAG,
2644
-                                    'attr' => array()
2645
-                                )
2646
-                            );
2647
-
2648
-                            /* Act as if a start tag token with the tag name "label"
2640
+            $this->inBody(
2641
+                array(
2642
+                    'name' => 'p',
2643
+                    'type' => HTML5::STARTTAG,
2644
+                    'attr' => array()
2645
+                )
2646
+            );
2647
+
2648
+            /* Act as if a start tag token with the tag name "label"
2649 2649
                             had been seen. */
2650
-                            $this->inBody(
2651
-                                array(
2652
-                                    'name' => 'label',
2653
-                                    'type' => HTML5::STARTTAG,
2654
-                                    'attr' => array()
2655
-                                )
2656
-                            );
2657
-
2658
-                            /* Act as if a stream of character tokens had been seen. */
2659
-                            $this->insertText(
2660
-                                'This is a searchable index. ' .
2661
-                                'Insert your search keywords here: '
2662
-                            );
2663
-
2664
-                            /* Act as if a start tag token with the tag name "input"
2650
+            $this->inBody(
2651
+                array(
2652
+                    'name' => 'label',
2653
+                    'type' => HTML5::STARTTAG,
2654
+                    'attr' => array()
2655
+                )
2656
+            );
2657
+
2658
+            /* Act as if a stream of character tokens had been seen. */
2659
+            $this->insertText(
2660
+                'This is a searchable index. ' .
2661
+                'Insert your search keywords here: '
2662
+            );
2663
+
2664
+            /* Act as if a start tag token with the tag name "input"
2665 2665
                             had been seen, with all the attributes from the "isindex"
2666 2666
                             token, except with the "name" attribute set to the value
2667 2667
                             "isindex" (ignoring any explicit "name" attribute). */
2668
-                            $attr = $token['attr'];
2669
-                            $attr[] = array('name' => 'name', 'value' => 'isindex');
2670
-
2671
-                            $this->inBody(
2672
-                                array(
2673
-                                    'name' => 'input',
2674
-                                    'type' => HTML5::STARTTAG,
2675
-                                    'attr' => $attr
2676
-                                )
2677
-                            );
2678
-
2679
-                            /* Act as if a stream of character tokens had been seen
2668
+            $attr = $token['attr'];
2669
+            $attr[] = array('name' => 'name', 'value' => 'isindex');
2670
+
2671
+            $this->inBody(
2672
+                array(
2673
+                    'name' => 'input',
2674
+                    'type' => HTML5::STARTTAG,
2675
+                    'attr' => $attr
2676
+                )
2677
+            );
2678
+
2679
+            /* Act as if a stream of character tokens had been seen
2680 2680
                             (see below for what they should say). */
2681
-                            $this->insertText(
2682
-                                'This is a searchable index. ' .
2683
-                                'Insert your search keywords here: '
2684
-                            );
2681
+            $this->insertText(
2682
+                'This is a searchable index. ' .
2683
+                'Insert your search keywords here: '
2684
+            );
2685 2685
 
2686
-                            /* Act as if an end tag token with the tag name "label"
2686
+            /* Act as if an end tag token with the tag name "label"
2687 2687
                             had been seen. */
2688
-                            $this->inBody(
2689
-                                array(
2690
-                                    'name' => 'label',
2691
-                                    'type' => HTML5::ENDTAG
2692
-                                )
2693
-                            );
2694
-
2695
-                            /* Act as if an end tag token with the tag name "p" had
2688
+            $this->inBody(
2689
+                array(
2690
+                    'name' => 'label',
2691
+                    'type' => HTML5::ENDTAG
2692
+                )
2693
+            );
2694
+
2695
+            /* Act as if an end tag token with the tag name "p" had
2696 2696
                             been seen. */
2697
-                            $this->inBody(
2698
-                                array(
2699
-                                    'name' => 'p',
2700
-                                    'type' => HTML5::ENDTAG
2701
-                                )
2702
-                            );
2703
-
2704
-                            /* Act as if a start tag token with the tag name "hr" had
2697
+            $this->inBody(
2698
+                array(
2699
+                    'name' => 'p',
2700
+                    'type' => HTML5::ENDTAG
2701
+                )
2702
+            );
2703
+
2704
+            /* Act as if a start tag token with the tag name "hr" had
2705 2705
                             been seen. */
2706
-                            $this->inBody(
2707
-                                array(
2708
-                                    'name' => 'hr',
2709
-                                    'type' => HTML5::ENDTAG
2710
-                                )
2711
-                            );
2712
-
2713
-                            /* Act as if an end tag token with the tag name "form" had
2706
+            $this->inBody(
2707
+                array(
2708
+                    'name' => 'hr',
2709
+                    'type' => HTML5::ENDTAG
2710
+                )
2711
+            );
2712
+
2713
+            /* Act as if an end tag token with the tag name "form" had
2714 2714
                             been seen. */
2715
-                            $this->inBody(
2716
-                                array(
2717
-                                    'name' => 'form',
2718
-                                    'type' => HTML5::ENDTAG
2719
-                                )
2720
-                            );
2721
-                        }
2722
-                        break;
2715
+            $this->inBody(
2716
+                array(
2717
+                    'name' => 'form',
2718
+                    'type' => HTML5::ENDTAG
2719
+                )
2720
+            );
2721
+            }
2722
+            break;
2723 2723
 
2724
-                    /* A start tag whose tag name is "textarea" */
2725
-                    case 'textarea':
2726
-                        $this->insertElement($token);
2724
+            /* A start tag whose tag name is "textarea" */
2725
+            case 'textarea':
2726
+            $this->insertElement($token);
2727 2727
 
2728
-                        /* Switch the tokeniser's content model flag to the
2728
+            /* Switch the tokeniser's content model flag to the
2729 2729
                         RCDATA state. */
2730
-                        return HTML5::RCDATA;
2731
-                        break;
2730
+            return HTML5::RCDATA;
2731
+            break;
2732 2732
 
2733
-                    /* A start tag whose tag name is one of: "iframe", "noembed",
2733
+            /* A start tag whose tag name is one of: "iframe", "noembed",
2734 2734
                     "noframes" */
2735
-                    case 'iframe':
2736
-                    case 'noembed':
2737
-                    case 'noframes':
2738
-                        $this->insertElement($token);
2735
+            case 'iframe':
2736
+            case 'noembed':
2737
+            case 'noframes':
2738
+            $this->insertElement($token);
2739 2739
 
2740
-                        /* Switch the tokeniser's content model flag to the CDATA state. */
2741
-                        return HTML5::CDATA;
2742
-                        break;
2740
+            /* Switch the tokeniser's content model flag to the CDATA state. */
2741
+            return HTML5::CDATA;
2742
+            break;
2743 2743
 
2744
-                    /* A start tag whose tag name is "select" */
2745
-                    case 'select':
2746
-                        /* Reconstruct the active formatting elements, if any. */
2747
-                        $this->reconstructActiveFormattingElements();
2744
+            /* A start tag whose tag name is "select" */
2745
+            case 'select':
2746
+            /* Reconstruct the active formatting elements, if any. */
2747
+            $this->reconstructActiveFormattingElements();
2748 2748
 
2749
-                        /* Insert an HTML element for the token. */
2750
-                        $this->insertElement($token);
2749
+            /* Insert an HTML element for the token. */
2750
+            $this->insertElement($token);
2751 2751
 
2752
-                        /* Change the insertion mode to "in select". */
2753
-                        $this->mode = self::IN_SELECT;
2754
-                        break;
2752
+            /* Change the insertion mode to "in select". */
2753
+            $this->mode = self::IN_SELECT;
2754
+            break;
2755 2755
 
2756
-                    /* A start or end tag whose tag name is one of: "caption", "col",
2756
+            /* A start or end tag whose tag name is one of: "caption", "col",
2757 2757
                     "colgroup", "frame", "frameset", "head", "option", "optgroup",
2758 2758
                     "tbody", "td", "tfoot", "th", "thead", "tr". */
2759
-                    case 'caption':
2760
-                    case 'col':
2761
-                    case 'colgroup':
2762
-                    case 'frame':
2763
-                    case 'frameset':
2764
-                    case 'head':
2765
-                    case 'option':
2766
-                    case 'optgroup':
2767
-                    case 'tbody':
2768
-                    case 'td':
2769
-                    case 'tfoot':
2770
-                    case 'th':
2771
-                    case 'thead':
2772
-                    case 'tr':
2773
-                        // Parse error. Ignore the token.
2774
-                        break;
2759
+            case 'caption':
2760
+            case 'col':
2761
+            case 'colgroup':
2762
+            case 'frame':
2763
+            case 'frameset':
2764
+            case 'head':
2765
+            case 'option':
2766
+            case 'optgroup':
2767
+            case 'tbody':
2768
+            case 'td':
2769
+            case 'tfoot':
2770
+            case 'th':
2771
+            case 'thead':
2772
+            case 'tr':
2773
+            // Parse error. Ignore the token.
2774
+            break;
2775 2775
 
2776
-                    /* A start or end tag whose tag name is one of: "event-source",
2776
+            /* A start or end tag whose tag name is one of: "event-source",
2777 2777
                     "section", "nav", "article", "aside", "header", "footer",
2778 2778
                     "datagrid", "command" */
2779
-                    case 'event-source':
2780
-                    case 'section':
2781
-                    case 'nav':
2782
-                    case 'article':
2783
-                    case 'aside':
2784
-                    case 'header':
2785
-                    case 'footer':
2786
-                    case 'datagrid':
2787
-                    case 'command':
2788
-                        // Work in progress!
2789
-                        break;
2790
-
2791
-                    /* A start tag token not covered by the previous entries */
2792
-                    default:
2793
-                        /* Reconstruct the active formatting elements, if any. */
2794
-                        $this->reconstructActiveFormattingElements();
2779
+            case 'event-source':
2780
+            case 'section':
2781
+            case 'nav':
2782
+            case 'article':
2783
+            case 'aside':
2784
+            case 'header':
2785
+            case 'footer':
2786
+            case 'datagrid':
2787
+            case 'command':
2788
+            // Work in progress!
2789
+            break;
2790
+
2791
+            /* A start tag token not covered by the previous entries */
2792
+            default:
2793
+            /* Reconstruct the active formatting elements, if any. */
2794
+            $this->reconstructActiveFormattingElements();
2795 2795
 
2796
-                        $this->insertElement($token, true, true);
2797
-                        break;
2798
-                }
2796
+            $this->insertElement($token, true, true);
2797
+            break;
2798
+            }
2799 2799
                 break;
2800 2800
 
2801
-            case HTML5::ENDTAG:
2802
-                switch ($token['name']) {
2803
-                    /* An end tag with the tag name "body" */
2804
-                    case 'body':
2805
-                        /* If the second element in the stack of open elements is
2801
+        case HTML5::ENDTAG:
2802
+            switch ($token['name']) {
2803
+                /* An end tag with the tag name "body" */
2804
+            case 'body':
2805
+            /* If the second element in the stack of open elements is
2806 2806
                         not a body element, this is a parse error. Ignore the token.
2807 2807
                         (innerHTML case) */
2808
-                        if (count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2809
-                            // Ignore.
2808
+            if (count($this->stack) < 2 || $this->stack[1]->nodeName !== 'body') {
2809
+            // Ignore.
2810 2810
 
2811
-                            /* If the current node is not the body element, then this
2811
+            /* If the current node is not the body element, then this
2812 2812
                             is a parse error. */
2813
-                        } elseif (end($this->stack)->nodeName !== 'body') {
2814
-                            // Parse error.
2815
-                        }
2813
+            } elseif (end($this->stack)->nodeName !== 'body') {
2814
+            // Parse error.
2815
+            }
2816 2816
 
2817
-                        /* Change the insertion mode to "after body". */
2818
-                        $this->mode = self::AFTER_BODY;
2819
-                        break;
2817
+            /* Change the insertion mode to "after body". */
2818
+            $this->mode = self::AFTER_BODY;
2819
+            break;
2820 2820
 
2821
-                    /* An end tag with the tag name "html" */
2822
-                    case 'html':
2823
-                        /* Act as if an end tag with tag name "body" had been seen,
2821
+            /* An end tag with the tag name "html" */
2822
+            case 'html':
2823
+            /* Act as if an end tag with tag name "body" had been seen,
2824 2824
                         then, if that token wasn't ignored, reprocess the current
2825 2825
                         token. */
2826
-                        $this->inBody(
2827
-                            array(
2828
-                                'name' => 'body',
2829
-                                'type' => HTML5::ENDTAG
2830
-                            )
2831
-                        );
2832
-
2833
-                        return $this->afterBody($token);
2834
-                        break;
2826
+            $this->inBody(
2827
+            array(
2828
+                'name' => 'body',
2829
+                'type' => HTML5::ENDTAG
2830
+            )
2831
+            );
2832
+
2833
+            return $this->afterBody($token);
2834
+            break;
2835 2835
 
2836
-                    /* An end tag whose tag name is one of: "address", "blockquote",
2836
+            /* An end tag whose tag name is one of: "address", "blockquote",
2837 2837
                     "center", "dir", "div", "dl", "fieldset", "listing", "menu",
2838 2838
                     "ol", "pre", "ul" */
2839
-                    case 'address':
2840
-                    case 'blockquote':
2841
-                    case 'center':
2842
-                    case 'dir':
2843
-                    case 'div':
2844
-                    case 'dl':
2845
-                    case 'fieldset':
2846
-                    case 'listing':
2847
-                    case 'menu':
2848
-                    case 'ol':
2849
-                    case 'pre':
2850
-                    case 'ul':
2851
-                        /* If the stack of open elements has an element in scope
2839
+            case 'address':
2840
+            case 'blockquote':
2841
+            case 'center':
2842
+            case 'dir':
2843
+            case 'div':
2844
+            case 'dl':
2845
+            case 'fieldset':
2846
+            case 'listing':
2847
+            case 'menu':
2848
+            case 'ol':
2849
+            case 'pre':
2850
+            case 'ul':
2851
+            /* If the stack of open elements has an element in scope
2852 2852
                         with the same tag name as that of the token, then generate
2853 2853
                         implied end tags. */
2854
-                        if ($this->elementInScope($token['name'])) {
2855
-                            $this->generateImpliedEndTags();
2854
+            if ($this->elementInScope($token['name'])) {
2855
+            $this->generateImpliedEndTags();
2856 2856
 
2857
-                            /* Now, if the current node is not an element with
2857
+            /* Now, if the current node is not an element with
2858 2858
                             the same tag name as that of the token, then this
2859 2859
                             is a parse error. */
2860
-                            // w/e
2860
+            // w/e
2861 2861
 
2862
-                            /* If the stack of open elements has an element in
2862
+            /* If the stack of open elements has an element in
2863 2863
                             scope with the same tag name as that of the token,
2864 2864
                             then pop elements from this stack until an element
2865 2865
                             with that tag name has been popped from the stack. */
2866
-                            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2867
-                                if ($this->stack[$n]->nodeName === $token['name']) {
2868
-                                    $n = -1;
2869
-                                }
2866
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2867
+                if ($this->stack[$n]->nodeName === $token['name']) {
2868
+                    $n = -1;
2869
+                }
2870 2870
 
2871
-                                array_pop($this->stack);
2872
-                            }
2873
-                        }
2874
-                        break;
2871
+                array_pop($this->stack);
2872
+            }
2873
+            }
2874
+            break;
2875 2875
 
2876
-                    /* An end tag whose tag name is "form" */
2877
-                    case 'form':
2878
-                        /* If the stack of open elements has an element in scope
2876
+            /* An end tag whose tag name is "form" */
2877
+            case 'form':
2878
+            /* If the stack of open elements has an element in scope
2879 2879
                         with the same tag name as that of the token, then generate
2880 2880
                         implied    end tags. */
2881
-                        if ($this->elementInScope($token['name'])) {
2882
-                            $this->generateImpliedEndTags();
2881
+            if ($this->elementInScope($token['name'])) {
2882
+            $this->generateImpliedEndTags();
2883 2883
 
2884
-                        }
2884
+            }
2885 2885
 
2886
-                        if (end($this->stack)->nodeName !== $token['name']) {
2887
-                            /* Now, if the current node is not an element with the
2886
+            if (end($this->stack)->nodeName !== $token['name']) {
2887
+            /* Now, if the current node is not an element with the
2888 2888
                             same tag name as that of the token, then this is a parse
2889 2889
                             error. */
2890
-                            // w/e
2890
+            // w/e
2891 2891
 
2892
-                        } else {
2893
-                            /* Otherwise, if the current node is an element with
2892
+            } else {
2893
+            /* Otherwise, if the current node is an element with
2894 2894
                             the same tag name as that of the token pop that element
2895 2895
                             from the stack. */
2896
-                            array_pop($this->stack);
2897
-                        }
2896
+            array_pop($this->stack);
2897
+            }
2898 2898
 
2899
-                        /* In any case, set the form element pointer to null. */
2900
-                        $this->form_pointer = null;
2901
-                        break;
2899
+            /* In any case, set the form element pointer to null. */
2900
+            $this->form_pointer = null;
2901
+            break;
2902 2902
 
2903
-                    /* An end tag whose tag name is "p" */
2904
-                    case 'p':
2905
-                        /* If the stack of open elements has a p element in scope,
2903
+            /* An end tag whose tag name is "p" */
2904
+            case 'p':
2905
+            /* If the stack of open elements has a p element in scope,
2906 2906
                         then generate implied end tags, except for p elements. */
2907
-                        if ($this->elementInScope('p')) {
2908
-                            $this->generateImpliedEndTags(array('p'));
2907
+            if ($this->elementInScope('p')) {
2908
+            $this->generateImpliedEndTags(array('p'));
2909 2909
 
2910
-                            /* If the current node is not a p element, then this is
2910
+            /* If the current node is not a p element, then this is
2911 2911
                             a parse error. */
2912
-                            // k
2912
+            // k
2913 2913
 
2914
-                            /* If the stack of open elements has a p element in
2914
+            /* If the stack of open elements has a p element in
2915 2915
                             scope, then pop elements from this stack until the stack
2916 2916
                             no longer has a p element in scope. */
2917
-                            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2918
-                                if ($this->elementInScope('p')) {
2919
-                                    array_pop($this->stack);
2920
-
2921
-                                } else {
2922
-                                    break;
2923
-                                }
2924
-                            }
2925
-                        }
2926
-                        break;
2917
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2918
+                if ($this->elementInScope('p')) {
2919
+                    array_pop($this->stack);
2920
+
2921
+                } else {
2922
+                    break;
2923
+                }
2924
+            }
2925
+            }
2926
+            break;
2927 2927
 
2928
-                    /* An end tag whose tag name is "dd", "dt", or "li" */
2929
-                    case 'dd':
2930
-                    case 'dt':
2931
-                    case 'li':
2932
-                        /* If the stack of open elements has an element in scope
2928
+            /* An end tag whose tag name is "dd", "dt", or "li" */
2929
+            case 'dd':
2930
+            case 'dt':
2931
+            case 'li':
2932
+            /* If the stack of open elements has an element in scope
2933 2933
                         whose tag name matches the tag name of the token, then
2934 2934
                         generate implied end tags, except for elements with the
2935 2935
                         same tag name as the token. */
2936
-                        if ($this->elementInScope($token['name'])) {
2937
-                            $this->generateImpliedEndTags(array($token['name']));
2936
+            if ($this->elementInScope($token['name'])) {
2937
+            $this->generateImpliedEndTags(array($token['name']));
2938 2938
 
2939
-                            /* If the current node is not an element with the same
2939
+            /* If the current node is not an element with the same
2940 2940
                             tag name as the token, then this is a parse error. */
2941
-                            // w/e
2941
+            // w/e
2942 2942
 
2943
-                            /* If the stack of open elements has an element in scope
2943
+            /* If the stack of open elements has an element in scope
2944 2944
                             whose tag name matches the tag name of the token, then
2945 2945
                             pop elements from this stack until an element with that
2946 2946
                             tag name has been popped from the stack. */
2947
-                            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2948
-                                if ($this->stack[$n]->nodeName === $token['name']) {
2949
-                                    $n = -1;
2950
-                                }
2947
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
2948
+                if ($this->stack[$n]->nodeName === $token['name']) {
2949
+                    $n = -1;
2950
+                }
2951 2951
 
2952
-                                array_pop($this->stack);
2953
-                            }
2954
-                        }
2955
-                        break;
2952
+                array_pop($this->stack);
2953
+            }
2954
+            }
2955
+            break;
2956 2956
 
2957
-                    /* An end tag whose tag name is one of: "h1", "h2", "h3", "h4",
2957
+            /* An end tag whose tag name is one of: "h1", "h2", "h3", "h4",
2958 2958
                     "h5", "h6" */
2959
-                    case 'h1':
2960
-                    case 'h2':
2961
-                    case 'h3':
2962
-                    case 'h4':
2963
-                    case 'h5':
2964
-                    case 'h6':
2965
-                        $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
2966
-
2967
-                        /* If the stack of open elements has in scope an element whose
2959
+            case 'h1':
2960
+            case 'h2':
2961
+            case 'h3':
2962
+            case 'h4':
2963
+            case 'h5':
2964
+            case 'h6':
2965
+            $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
2966
+
2967
+            /* If the stack of open elements has in scope an element whose
2968 2968
                         tag name is one of "h1", "h2", "h3", "h4", "h5", or "h6", then
2969 2969
                         generate implied end tags. */
2970
-                        if ($this->elementInScope($elements)) {
2971
-                            $this->generateImpliedEndTags();
2970
+            if ($this->elementInScope($elements)) {
2971
+            $this->generateImpliedEndTags();
2972 2972
 
2973
-                            /* Now, if the current node is not an element with the same
2973
+            /* Now, if the current node is not an element with the same
2974 2974
                             tag name as that of the token, then this is a parse error. */
2975
-                            // w/e
2975
+            // w/e
2976 2976
 
2977
-                            /* If the stack of open elements has in scope an element
2977
+            /* If the stack of open elements has in scope an element
2978 2978
                             whose tag name is one of "h1", "h2", "h3", "h4", "h5", or
2979 2979
                             "h6", then pop elements from the stack until an element
2980 2980
                             with one of those tag names has been popped from the stack. */
2981
-                            while ($this->elementInScope($elements)) {
2982
-                                array_pop($this->stack);
2983
-                            }
2984
-                        }
2985
-                        break;
2981
+            while ($this->elementInScope($elements)) {
2982
+                array_pop($this->stack);
2983
+            }
2984
+            }
2985
+            break;
2986 2986
 
2987
-                    /* An end tag whose tag name is one of: "a", "b", "big", "em",
2987
+            /* An end tag whose tag name is one of: "a", "b", "big", "em",
2988 2988
                     "font", "i", "nobr", "s", "small", "strike", "strong", "tt", "u" */
2989
-                    case 'a':
2990
-                    case 'b':
2991
-                    case 'big':
2992
-                    case 'em':
2993
-                    case 'font':
2994
-                    case 'i':
2995
-                    case 'nobr':
2996
-                    case 's':
2997
-                    case 'small':
2998
-                    case 'strike':
2999
-                    case 'strong':
3000
-                    case 'tt':
3001
-                    case 'u':
3002
-                        /* 1. Let the formatting element be the last element in
2989
+            case 'a':
2990
+            case 'b':
2991
+            case 'big':
2992
+            case 'em':
2993
+            case 'font':
2994
+            case 'i':
2995
+            case 'nobr':
2996
+            case 's':
2997
+            case 'small':
2998
+            case 'strike':
2999
+            case 'strong':
3000
+            case 'tt':
3001
+            case 'u':
3002
+            /* 1. Let the formatting element be the last element in
3003 3003
                         the list of active formatting elements that:
3004 3004
                             * is between the end of the list and the last scope
3005 3005
                             marker in the list, if any, or the start of the list
3006 3006
                             otherwise, and
3007 3007
                             * has the same tag name as the token.
3008 3008
                         */
3009
-                        while (true) {
3010
-                            for ($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
3011
-                                if ($this->a_formatting[$a] === self::MARKER) {
3012
-                                    break;
3013
-
3014
-                                } elseif ($this->a_formatting[$a]->tagName === $token['name']) {
3015
-                                    $formatting_element = $this->a_formatting[$a];
3016
-                                    $in_stack = in_array($formatting_element, $this->stack, true);
3017
-                                    $fe_af_pos = $a;
3018
-                                    break;
3019
-                                }
3020
-                            }
3021
-
3022
-                            /* If there is no such node, or, if that node is
3009
+            while (true) {
3010
+            for ($a = count($this->a_formatting) - 1; $a >= 0; $a--) {
3011
+                if ($this->a_formatting[$a] === self::MARKER) {
3012
+                    break;
3013
+
3014
+                } elseif ($this->a_formatting[$a]->tagName === $token['name']) {
3015
+                    $formatting_element = $this->a_formatting[$a];
3016
+                    $in_stack = in_array($formatting_element, $this->stack, true);
3017
+                    $fe_af_pos = $a;
3018
+                    break;
3019
+                }
3020
+            }
3021
+
3022
+            /* If there is no such node, or, if that node is
3023 3023
                             also in the stack of open elements but the element
3024 3024
                             is not in scope, then this is a parse error. Abort
3025 3025
                             these steps. The token is ignored. */
3026
-                            if (!isset($formatting_element) || ($in_stack &&
3027
-                                    !$this->elementInScope($token['name']))
3028
-                            ) {
3029
-                                break;
3026
+            if (!isset($formatting_element) || ($in_stack &&
3027
+                    !$this->elementInScope($token['name']))
3028
+            ) {
3029
+                break;
3030 3030
 
3031
-                                /* Otherwise, if there is such a node, but that node
3031
+                /* Otherwise, if there is such a node, but that node
3032 3032
                                 is not in the stack of open elements, then this is a
3033 3033
                                 parse error; remove the element from the list, and
3034 3034
                                 abort these steps. */
3035
-                            } elseif (isset($formatting_element) && !$in_stack) {
3036
-                                unset($this->a_formatting[$fe_af_pos]);
3037
-                                $this->a_formatting = array_merge($this->a_formatting);
3038
-                                break;
3039
-                            }
3035
+            } elseif (isset($formatting_element) && !$in_stack) {
3036
+                unset($this->a_formatting[$fe_af_pos]);
3037
+                $this->a_formatting = array_merge($this->a_formatting);
3038
+                break;
3039
+            }
3040 3040
 
3041
-                            /* 2. Let the furthest block be the topmost node in the
3041
+            /* 2. Let the furthest block be the topmost node in the
3042 3042
                             stack of open elements that is lower in the stack
3043 3043
                             than the formatting element, and is not an element in
3044 3044
                             the phrasing or formatting categories. There might
3045 3045
                             not be one. */
3046
-                            $fe_s_pos = array_search($formatting_element, $this->stack, true);
3047
-                            $length = count($this->stack);
3046
+            $fe_s_pos = array_search($formatting_element, $this->stack, true);
3047
+            $length = count($this->stack);
3048 3048
 
3049
-                            for ($s = $fe_s_pos + 1; $s < $length; $s++) {
3050
-                                $category = $this->getElementCategory($this->stack[$s]->nodeName);
3049
+            for ($s = $fe_s_pos + 1; $s < $length; $s++) {
3050
+                $category = $this->getElementCategory($this->stack[$s]->nodeName);
3051 3051
 
3052
-                                if ($category !== self::PHRASING && $category !== self::FORMATTING) {
3053
-                                    $furthest_block = $this->stack[$s];
3054
-                                }
3055
-                            }
3052
+                if ($category !== self::PHRASING && $category !== self::FORMATTING) {
3053
+                    $furthest_block = $this->stack[$s];
3054
+                }
3055
+            }
3056 3056
 
3057
-                            /* 3. If there is no furthest block, then the UA must
3057
+            /* 3. If there is no furthest block, then the UA must
3058 3058
                             skip the subsequent steps and instead just pop all
3059 3059
                             the nodes from the bottom of the stack of open
3060 3060
                             elements, from the current node up to the formatting
3061 3061
                             element, and remove the formatting element from the
3062 3062
                             list of active formatting elements. */
3063
-                            if (!isset($furthest_block)) {
3064
-                                for ($n = $length - 1; $n >= $fe_s_pos; $n--) {
3065
-                                    array_pop($this->stack);
3066
-                                }
3063
+            if (!isset($furthest_block)) {
3064
+                for ($n = $length - 1; $n >= $fe_s_pos; $n--) {
3065
+                    array_pop($this->stack);
3066
+                }
3067 3067
 
3068
-                                unset($this->a_formatting[$fe_af_pos]);
3069
-                                $this->a_formatting = array_merge($this->a_formatting);
3070
-                                break;
3071
-                            }
3068
+                unset($this->a_formatting[$fe_af_pos]);
3069
+                $this->a_formatting = array_merge($this->a_formatting);
3070
+                break;
3071
+            }
3072 3072
 
3073
-                            /* 4. Let the common ancestor be the element
3073
+            /* 4. Let the common ancestor be the element
3074 3074
                             immediately above the formatting element in the stack
3075 3075
                             of open elements. */
3076
-                            $common_ancestor = $this->stack[$fe_s_pos - 1];
3076
+            $common_ancestor = $this->stack[$fe_s_pos - 1];
3077 3077
 
3078
-                            /* 5. If the furthest block has a parent node, then
3078
+            /* 5. If the furthest block has a parent node, then
3079 3079
                             remove the furthest block from its parent node. */
3080
-                            if ($furthest_block->parentNode !== null) {
3081
-                                $furthest_block->parentNode->removeChild($furthest_block);
3082
-                            }
3080
+            if ($furthest_block->parentNode !== null) {
3081
+                $furthest_block->parentNode->removeChild($furthest_block);
3082
+            }
3083 3083
 
3084
-                            /* 6. Let a bookmark note the position of the
3084
+            /* 6. Let a bookmark note the position of the
3085 3085
                             formatting element in the list of active formatting
3086 3086
                             elements relative to the elements on either side
3087 3087
                             of it in the list. */
3088
-                            $bookmark = $fe_af_pos;
3088
+            $bookmark = $fe_af_pos;
3089 3089
 
3090
-                            /* 7. Let node and last node  be the furthest block.
3090
+            /* 7. Let node and last node  be the furthest block.
3091 3091
                             Follow these steps: */
3092
-                            $node = $furthest_block;
3093
-                            $last_node = $furthest_block;
3092
+            $node = $furthest_block;
3093
+            $last_node = $furthest_block;
3094 3094
 
3095
-                            while (true) {
3096
-                                for ($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
3097
-                                    /* 7.1 Let node be the element immediately
3095
+            while (true) {
3096
+                for ($n = array_search($node, $this->stack, true) - 1; $n >= 0; $n--) {
3097
+                    /* 7.1 Let node be the element immediately
3098 3098
                                     prior to node in the stack of open elements. */
3099
-                                    $node = $this->stack[$n];
3099
+                    $node = $this->stack[$n];
3100 3100
 
3101
-                                    /* 7.2 If node is not in the list of active
3101
+                    /* 7.2 If node is not in the list of active
3102 3102
                                     formatting elements, then remove node from
3103 3103
                                     the stack of open elements and then go back
3104 3104
                                     to step 1. */
3105
-                                    if (!in_array($node, $this->a_formatting, true)) {
3106
-                                        unset($this->stack[$n]);
3107
-                                        $this->stack = array_merge($this->stack);
3105
+                    if (!in_array($node, $this->a_formatting, true)) {
3106
+                        unset($this->stack[$n]);
3107
+                        $this->stack = array_merge($this->stack);
3108 3108
 
3109
-                                    } else {
3110
-                                        break;
3111
-                                    }
3112
-                                }
3109
+                    } else {
3110
+                        break;
3111
+                    }
3112
+                }
3113 3113
 
3114
-                                /* 7.3 Otherwise, if node is the formatting
3114
+                /* 7.3 Otherwise, if node is the formatting
3115 3115
                                 element, then go to the next step in the overall
3116 3116
                                 algorithm. */
3117
-                                if ($node === $formatting_element) {
3118
-                                    break;
3117
+                if ($node === $formatting_element) {
3118
+                    break;
3119 3119
 
3120
-                                    /* 7.4 Otherwise, if last node is the furthest
3120
+                    /* 7.4 Otherwise, if last node is the furthest
3121 3121
                                     block, then move the aforementioned bookmark to
3122 3122
                                     be immediately after the node in the list of
3123 3123
                                     active formatting elements. */
3124
-                                } elseif ($last_node === $furthest_block) {
3125
-                                    $bookmark = array_search($node, $this->a_formatting, true) + 1;
3126
-                                }
3124
+                } elseif ($last_node === $furthest_block) {
3125
+                    $bookmark = array_search($node, $this->a_formatting, true) + 1;
3126
+                }
3127 3127
 
3128
-                                /* 7.5 If node has any children, perform a
3128
+                /* 7.5 If node has any children, perform a
3129 3129
                                 shallow clone of node, replace the entry for
3130 3130
                                 node in the list of active formatting elements
3131 3131
                                 with an entry for the clone, replace the entry
3132 3132
                                 for node in the stack of open elements with an
3133 3133
                                 entry for the clone, and let node be the clone. */
3134
-                                if ($node->hasChildNodes()) {
3135
-                                    $clone = $node->cloneNode();
3136
-                                    $s_pos = array_search($node, $this->stack, true);
3137
-                                    $a_pos = array_search($node, $this->a_formatting, true);
3138
-
3139
-                                    $this->stack[$s_pos] = $clone;
3140
-                                    $this->a_formatting[$a_pos] = $clone;
3141
-                                    $node = $clone;
3142
-                                }
3134
+                if ($node->hasChildNodes()) {
3135
+                    $clone = $node->cloneNode();
3136
+                    $s_pos = array_search($node, $this->stack, true);
3137
+                    $a_pos = array_search($node, $this->a_formatting, true);
3138
+
3139
+                    $this->stack[$s_pos] = $clone;
3140
+                    $this->a_formatting[$a_pos] = $clone;
3141
+                    $node = $clone;
3142
+                }
3143 3143
 
3144
-                                /* 7.6 Insert last node into node, first removing
3144
+                /* 7.6 Insert last node into node, first removing
3145 3145
                                 it from its previous parent node if any. */
3146
-                                if ($last_node->parentNode !== null) {
3147
-                                    $last_node->parentNode->removeChild($last_node);
3148
-                                }
3146
+                if ($last_node->parentNode !== null) {
3147
+                    $last_node->parentNode->removeChild($last_node);
3148
+                }
3149 3149
 
3150
-                                $node->appendChild($last_node);
3150
+                $node->appendChild($last_node);
3151 3151
 
3152
-                                /* 7.7 Let last node be node. */
3153
-                                $last_node = $node;
3154
-                            }
3152
+                /* 7.7 Let last node be node. */
3153
+                $last_node = $node;
3154
+            }
3155 3155
 
3156
-                            /* 8. Insert whatever last node ended up being in
3156
+            /* 8. Insert whatever last node ended up being in
3157 3157
                             the previous step into the common ancestor node,
3158 3158
                             first removing it from its previous parent node if
3159 3159
                             any. */
3160
-                            if ($last_node->parentNode !== null) {
3161
-                                $last_node->parentNode->removeChild($last_node);
3162
-                            }
3160
+            if ($last_node->parentNode !== null) {
3161
+                $last_node->parentNode->removeChild($last_node);
3162
+            }
3163 3163
 
3164
-                            $common_ancestor->appendChild($last_node);
3164
+            $common_ancestor->appendChild($last_node);
3165 3165
 
3166
-                            /* 9. Perform a shallow clone of the formatting
3166
+            /* 9. Perform a shallow clone of the formatting
3167 3167
                             element. */
3168
-                            $clone = $formatting_element->cloneNode();
3168
+            $clone = $formatting_element->cloneNode();
3169 3169
 
3170
-                            /* 10. Take all of the child nodes of the furthest
3170
+            /* 10. Take all of the child nodes of the furthest
3171 3171
                             block and append them to the clone created in the
3172 3172
                             last step. */
3173
-                            while ($furthest_block->hasChildNodes()) {
3174
-                                $child = $furthest_block->firstChild;
3175
-                                $furthest_block->removeChild($child);
3176
-                                $clone->appendChild($child);
3177
-                            }
3173
+            while ($furthest_block->hasChildNodes()) {
3174
+                $child = $furthest_block->firstChild;
3175
+                $furthest_block->removeChild($child);
3176
+                $clone->appendChild($child);
3177
+            }
3178 3178
 
3179
-                            /* 11. Append that clone to the furthest block. */
3180
-                            $furthest_block->appendChild($clone);
3179
+            /* 11. Append that clone to the furthest block. */
3180
+            $furthest_block->appendChild($clone);
3181 3181
 
3182
-                            /* 12. Remove the formatting element from the list
3182
+            /* 12. Remove the formatting element from the list
3183 3183
                             of active formatting elements, and insert the clone
3184 3184
                             into the list of active formatting elements at the
3185 3185
                             position of the aforementioned bookmark. */
3186
-                            $fe_af_pos = array_search($formatting_element, $this->a_formatting, true);
3187
-                            unset($this->a_formatting[$fe_af_pos]);
3188
-                            $this->a_formatting = array_merge($this->a_formatting);
3186
+            $fe_af_pos = array_search($formatting_element, $this->a_formatting, true);
3187
+            unset($this->a_formatting[$fe_af_pos]);
3188
+            $this->a_formatting = array_merge($this->a_formatting);
3189 3189
 
3190
-                            $af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1);
3191
-                            $af_part2 = array_slice($this->a_formatting, $bookmark, count($this->a_formatting));
3192
-                            $this->a_formatting = array_merge($af_part1, array($clone), $af_part2);
3190
+            $af_part1 = array_slice($this->a_formatting, 0, $bookmark - 1);
3191
+            $af_part2 = array_slice($this->a_formatting, $bookmark, count($this->a_formatting));
3192
+            $this->a_formatting = array_merge($af_part1, array($clone), $af_part2);
3193 3193
 
3194
-                            /* 13. Remove the formatting element from the stack
3194
+            /* 13. Remove the formatting element from the stack
3195 3195
                             of open elements, and insert the clone into the stack
3196 3196
                             of open elements immediately after (i.e. in a more
3197 3197
                             deeply nested position than) the position of the
3198 3198
                             furthest block in that stack. */
3199
-                            $fe_s_pos = array_search($formatting_element, $this->stack, true);
3200
-                            $fb_s_pos = array_search($furthest_block, $this->stack, true);
3201
-                            unset($this->stack[$fe_s_pos]);
3199
+            $fe_s_pos = array_search($formatting_element, $this->stack, true);
3200
+            $fb_s_pos = array_search($furthest_block, $this->stack, true);
3201
+            unset($this->stack[$fe_s_pos]);
3202 3202
 
3203
-                            $s_part1 = array_slice($this->stack, 0, $fb_s_pos);
3204
-                            $s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack));
3205
-                            $this->stack = array_merge($s_part1, array($clone), $s_part2);
3203
+            $s_part1 = array_slice($this->stack, 0, $fb_s_pos);
3204
+            $s_part2 = array_slice($this->stack, $fb_s_pos + 1, count($this->stack));
3205
+            $this->stack = array_merge($s_part1, array($clone), $s_part2);
3206 3206
 
3207
-                            /* 14. Jump back to step 1 in this series of steps. */
3208
-                            unset($formatting_element, $fe_af_pos, $fe_s_pos, $furthest_block);
3209
-                        }
3210
-                        break;
3207
+            /* 14. Jump back to step 1 in this series of steps. */
3208
+            unset($formatting_element, $fe_af_pos, $fe_s_pos, $furthest_block);
3209
+            }
3210
+            break;
3211 3211
 
3212
-                    /* An end tag token whose tag name is one of: "button",
3212
+            /* An end tag token whose tag name is one of: "button",
3213 3213
                     "marquee", "object" */
3214
-                    case 'button':
3215
-                    case 'marquee':
3216
-                    case 'object':
3217
-                        /* If the stack of open elements has an element in scope whose
3214
+            case 'button':
3215
+            case 'marquee':
3216
+            case 'object':
3217
+            /* If the stack of open elements has an element in scope whose
3218 3218
                         tag name matches the tag name of the token, then generate implied
3219 3219
                         tags. */
3220
-                        if ($this->elementInScope($token['name'])) {
3221
-                            $this->generateImpliedEndTags();
3220
+            if ($this->elementInScope($token['name'])) {
3221
+            $this->generateImpliedEndTags();
3222 3222
 
3223
-                            /* Now, if the current node is not an element with the same
3223
+            /* Now, if the current node is not an element with the same
3224 3224
                             tag name as the token, then this is a parse error. */
3225
-                            // k
3225
+            // k
3226 3226
 
3227
-                            /* Now, if the stack of open elements has an element in scope
3227
+            /* Now, if the stack of open elements has an element in scope
3228 3228
                             whose tag name matches the tag name of the token, then pop
3229 3229
                             elements from the stack until that element has been popped from
3230 3230
                             the stack, and clear the list of active formatting elements up
3231 3231
                             to the last marker. */
3232
-                            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3233
-                                if ($this->stack[$n]->nodeName === $token['name']) {
3234
-                                    $n = -1;
3235
-                                }
3232
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3233
+                if ($this->stack[$n]->nodeName === $token['name']) {
3234
+                    $n = -1;
3235
+                }
3236 3236
 
3237
-                                array_pop($this->stack);
3238
-                            }
3237
+                array_pop($this->stack);
3238
+            }
3239 3239
 
3240
-                            $marker = end(array_keys($this->a_formatting, self::MARKER, true));
3240
+            $marker = end(array_keys($this->a_formatting, self::MARKER, true));
3241 3241
 
3242
-                            for ($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
3243
-                                array_pop($this->a_formatting);
3244
-                            }
3245
-                        }
3246
-                        break;
3242
+            for ($n = count($this->a_formatting) - 1; $n > $marker; $n--) {
3243
+                array_pop($this->a_formatting);
3244
+            }
3245
+            }
3246
+            break;
3247 3247
 
3248
-                    /* Or an end tag whose tag name is one of: "area", "basefont",
3248
+            /* Or an end tag whose tag name is one of: "area", "basefont",
3249 3249
                     "bgsound", "br", "embed", "hr", "iframe", "image", "img",
3250 3250
                     "input", "isindex", "noembed", "noframes", "param", "select",
3251 3251
                     "spacer", "table", "textarea", "wbr" */
3252
-                    case 'area':
3253
-                    case 'basefont':
3254
-                    case 'bgsound':
3255
-                    case 'br':
3256
-                    case 'embed':
3257
-                    case 'hr':
3258
-                    case 'iframe':
3259
-                    case 'image':
3260
-                    case 'img':
3261
-                    case 'input':
3262
-                    case 'isindex':
3263
-                    case 'noembed':
3264
-                    case 'noframes':
3265
-                    case 'param':
3266
-                    case 'select':
3267
-                    case 'spacer':
3268
-                    case 'table':
3269
-                    case 'textarea':
3270
-                    case 'wbr':
3271
-                        // Parse error. Ignore the token.
3272
-                        break;
3252
+            case 'area':
3253
+            case 'basefont':
3254
+            case 'bgsound':
3255
+            case 'br':
3256
+            case 'embed':
3257
+            case 'hr':
3258
+            case 'iframe':
3259
+            case 'image':
3260
+            case 'img':
3261
+            case 'input':
3262
+            case 'isindex':
3263
+            case 'noembed':
3264
+            case 'noframes':
3265
+            case 'param':
3266
+            case 'select':
3267
+            case 'spacer':
3268
+            case 'table':
3269
+            case 'textarea':
3270
+            case 'wbr':
3271
+            // Parse error. Ignore the token.
3272
+            break;
3273 3273
 
3274
-                    /* An end tag token not covered by the previous entries */
3275
-                    default:
3276
-                        for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3277
-                            /* Initialise node to be the current node (the bottommost
3274
+            /* An end tag token not covered by the previous entries */
3275
+            default:
3276
+            for ($n = count($this->stack) - 1; $n >= 0; $n--) {
3277
+            /* Initialise node to be the current node (the bottommost
3278 3278
                             node of the stack). */
3279
-                            $node = end($this->stack);
3279
+            $node = end($this->stack);
3280 3280
 
3281
-                            /* If node has the same tag name as the end tag token,
3281
+            /* If node has the same tag name as the end tag token,
3282 3282
                             then: */
3283
-                            if ($token['name'] === $node->nodeName) {
3284
-                                /* Generate implied end tags. */
3285
-                                $this->generateImpliedEndTags();
3283
+            if ($token['name'] === $node->nodeName) {
3284
+                /* Generate implied end tags. */
3285
+                $this->generateImpliedEndTags();
3286 3286
 
3287
-                                /* If the tag name of the end tag token does not
3287
+                /* If the tag name of the end tag token does not
3288 3288
                                 match the tag name of the current node, this is a
3289 3289
                                 parse error. */
3290
-                                // k
3290
+                // k
3291 3291
 
3292
-                                /* Pop all the nodes from the current node up to
3292
+                /* Pop all the nodes from the current node up to
3293 3293
                                 node, including node, then stop this algorithm. */
3294
-                                for ($x = count($this->stack) - $n; $x >= $n; $x--) {
3295
-                                    array_pop($this->stack);
3296
-                                }
3294
+                for ($x = count($this->stack) - $n; $x >= $n; $x--) {
3295
+                    array_pop($this->stack);
3296
+                }
3297 3297
 
3298
-                            } else {
3299
-                                $category = $this->getElementCategory($node);
3298
+            } else {
3299
+                $category = $this->getElementCategory($node);
3300 3300
 
3301
-                                if ($category !== self::SPECIAL && $category !== self::SCOPING) {
3302
-                                    /* Otherwise, if node is in neither the formatting
3301
+                if ($category !== self::SPECIAL && $category !== self::SCOPING) {
3302
+                    /* Otherwise, if node is in neither the formatting
3303 3303
                                     category nor the phrasing category, then this is a
3304 3304
                                     parse error. Stop this algorithm. The end tag token
3305 3305
                                     is ignored. */
3306
-                                    return false;
3307
-                                }
3308
-                            }
3309
-                        }
3310
-                        break;
3306
+                    return false;
3311 3307
                 }
3308
+            }
3309
+            }
3310
+            break;
3311
+            }
3312 3312
                 break;
3313 3313
         }
3314 3314
     }
Please login to merge, or discard this patch.