| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Provide general element functions. |
| 5 |
*/ |
| 6 |
namespace WindPressPackages\Masterminds\HTML5; |
| 7 |
|
| 8 |
/** |
| 9 |
* This class provides general information about HTML5 elements, |
| 10 |
* including syntactic and semantic issues. |
| 11 |
* Parsers and serializers can |
| 12 |
* use this class as a reference point for information about the rules |
| 13 |
* of various HTML5 elements. |
| 14 |
* |
| 15 |
* @todo consider using a bitmask table lookup. There is enough overlap in |
| 16 |
* naming that this could significantly shrink the size and maybe make it |
| 17 |
* faster. See the Go teams implementation at https://code.google.com/p/go/source/browse/html/atom. |
| 18 |
*/ |
| 19 |
class Elements |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Indicates an element is described in the specification. |
| 23 |
*/ |
| 24 |
const KNOWN_ELEMENT = 1; |
| 25 |
// From section 8.1.2: "script", "style" |
| 26 |
// From 8.2.5.4.7 ("in body" insertion mode): "noembed" |
| 27 |
// From 8.4 "style", "xmp", "iframe", "noembed", "noframes" |
| 28 |
/** |
| 29 |
* Indicates the contained text should be processed as raw text. |
| 30 |
*/ |
| 31 |
const TEXT_RAW = 2; |
| 32 |
// From section 8.1.2: "textarea", "title" |
| 33 |
/** |
| 34 |
* Indicates the contained text should be processed as RCDATA. |
| 35 |
*/ |
| 36 |
const TEXT_RCDATA = 4; |
| 37 |
/** |
| 38 |
* Indicates the tag cannot have content. |
| 39 |
*/ |
| 40 |
const VOID_TAG = 8; |
| 41 |
// "address", "article", "aside", "blockquote", "center", "details", "dialog", "dir", "div", "dl", |
| 42 |
// "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", |
| 43 |
// "nav", "ol", "p", "section", "summary", "ul" |
| 44 |
// "h1", "h2", "h3", "h4", "h5", "h6" |
| 45 |
// "pre", "listing" |
| 46 |
// "form" |
| 47 |
// "plaintext" |
| 48 |
/** |
| 49 |
* Indicates that if a previous event is for a P tag, that element |
| 50 |
* should be considered closed. |
| 51 |
*/ |
| 52 |
const AUTOCLOSE_P = 16; |
| 53 |
/** |
| 54 |
* Indicates that the text inside is plaintext (pre). |
| 55 |
*/ |
| 56 |
const TEXT_PLAINTEXT = 32; |
| 57 |
// See https://developer.mozilla.org/en-US/docs/HTML/Block-level_elements |
| 58 |
/** |
| 59 |
* Indicates that the tag is a block. |
| 60 |
*/ |
| 61 |
const BLOCK_TAG = 64; |
| 62 |
/** |
| 63 |
* Indicates that the tag allows only inline elements as child nodes. |
| 64 |
*/ |
| 65 |
const BLOCK_ONLY_INLINE = 128; |
| 66 |
/** |
| 67 |
* Elements with optional end tags that cause auto-closing of previous and parent tags, |
| 68 |
* as example most of the table related tags, see https://www.w3.org/TR/html401/struct/tables.html |
| 69 |
* Structure is as follows: |
| 70 |
* TAG-NAME => [PARENT-TAG-NAME-TO-CLOSE1, PARENT-TAG-NAME-TO-CLOSE2, ...]. |
| 71 |
* |
| 72 |
* Order is important, after auto-closing one parent with might have to close also their parent. |
| 73 |
* |
| 74 |
* @var array<string, string[]> |
| 75 |
*/ |
| 76 |
public static $optionalEndElementsParentsToClose = array('tr' => array('td', 'tr'), 'td' => array('td', 'th'), 'th' => array('td', 'th'), 'tfoot' => array('td', 'th', 'tr', 'tbody', 'thead'), 'tbody' => array('td', 'th', 'tr', 'thead')); |
| 77 |
/** |
| 78 |
* The HTML5 elements as defined in http://dev.w3.org/html5/markup/elements.html. |
| 79 |
* |
| 80 |
* @var array |
| 81 |
*/ |
| 82 |
public static $html5 = array( |
| 83 |
'a' => 1, |
| 84 |
'abbr' => 1, |
| 85 |
'address' => 65, |
| 86 |
// NORMAL | BLOCK_TAG |
| 87 |
'area' => 9, |
| 88 |
// NORMAL | VOID_TAG |
| 89 |
'article' => 81, |
| 90 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 91 |
'aside' => 81, |
| 92 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 93 |
'audio' => 1, |
| 94 |
// NORMAL |
| 95 |
'b' => 1, |
| 96 |
'base' => 9, |
| 97 |
// NORMAL | VOID_TAG |
| 98 |
'bdi' => 1, |
| 99 |
'bdo' => 1, |
| 100 |
'blockquote' => 81, |
| 101 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 102 |
'body' => 1, |
| 103 |
'br' => 9, |
| 104 |
// NORMAL | VOID_TAG |
| 105 |
'button' => 1, |
| 106 |
'canvas' => 65, |
| 107 |
// NORMAL | BLOCK_TAG |
| 108 |
'caption' => 1, |
| 109 |
'cite' => 1, |
| 110 |
'code' => 1, |
| 111 |
'col' => 9, |
| 112 |
// NORMAL | VOID_TAG |
| 113 |
'colgroup' => 1, |
| 114 |
'command' => 9, |
| 115 |
// NORMAL | VOID_TAG |
| 116 |
// "data" => 1, // This is highly experimental and only part of the whatwg spec (not w3c). See https://developer.mozilla.org/en-US/docs/HTML/Element/data |
| 117 |
'datalist' => 1, |
| 118 |
'dd' => 65, |
| 119 |
// NORMAL | BLOCK_TAG |
| 120 |
'del' => 1, |
| 121 |
'details' => 17, |
| 122 |
// NORMAL | AUTOCLOSE_P, |
| 123 |
'dfn' => 1, |
| 124 |
'dialog' => 17, |
| 125 |
// NORMAL | AUTOCLOSE_P, |
| 126 |
'div' => 81, |
| 127 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 128 |
'dl' => 81, |
| 129 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 130 |
'dt' => 1, |
| 131 |
'em' => 1, |
| 132 |
'embed' => 9, |
| 133 |
// NORMAL | VOID_TAG |
| 134 |
'fieldset' => 81, |
| 135 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 136 |
'figcaption' => 81, |
| 137 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 138 |
'figure' => 81, |
| 139 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 140 |
'footer' => 81, |
| 141 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 142 |
'form' => 81, |
| 143 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 144 |
'h1' => 81, |
| 145 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 146 |
'h2' => 81, |
| 147 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 148 |
'h3' => 81, |
| 149 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 150 |
'h4' => 81, |
| 151 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 152 |
'h5' => 81, |
| 153 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 154 |
'h6' => 81, |
| 155 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 156 |
'head' => 1, |
| 157 |
'header' => 81, |
| 158 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 159 |
'hgroup' => 81, |
| 160 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 161 |
'hr' => 73, |
| 162 |
// NORMAL | VOID_TAG |
| 163 |
'html' => 1, |
| 164 |
'i' => 1, |
| 165 |
'iframe' => 3, |
| 166 |
// NORMAL | TEXT_RAW |
| 167 |
'img' => 9, |
| 168 |
// NORMAL | VOID_TAG |
| 169 |
'input' => 9, |
| 170 |
// NORMAL | VOID_TAG |
| 171 |
'kbd' => 1, |
| 172 |
'ins' => 1, |
| 173 |
'keygen' => 9, |
| 174 |
// NORMAL | VOID_TAG |
| 175 |
'label' => 1, |
| 176 |
'legend' => 1, |
| 177 |
'li' => 1, |
| 178 |
'link' => 9, |
| 179 |
// NORMAL | VOID_TAG |
| 180 |
'map' => 1, |
| 181 |
'mark' => 1, |
| 182 |
'menu' => 17, |
| 183 |
// NORMAL | AUTOCLOSE_P, |
| 184 |
'meta' => 9, |
| 185 |
// NORMAL | VOID_TAG |
| 186 |
'meter' => 1, |
| 187 |
'nav' => 17, |
| 188 |
// NORMAL | AUTOCLOSE_P, |
| 189 |
'noscript' => 65, |
| 190 |
// NORMAL | BLOCK_TAG |
| 191 |
'object' => 1, |
| 192 |
'ol' => 81, |
| 193 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 194 |
'optgroup' => 1, |
| 195 |
'option' => 1, |
| 196 |
'output' => 65, |
| 197 |
// NORMAL | BLOCK_TAG |
| 198 |
'p' => 209, |
| 199 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG | BLOCK_ONLY_INLINE |
| 200 |
'param' => 9, |
| 201 |
// NORMAL | VOID_TAG |
| 202 |
'pre' => 81, |
| 203 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 204 |
'progress' => 1, |
| 205 |
'q' => 1, |
| 206 |
'rp' => 1, |
| 207 |
'rt' => 1, |
| 208 |
'ruby' => 1, |
| 209 |
's' => 1, |
| 210 |
'samp' => 1, |
| 211 |
'script' => 3, |
| 212 |
// NORMAL | TEXT_RAW |
| 213 |
'section' => 81, |
| 214 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 215 |
'select' => 1, |
| 216 |
'small' => 1, |
| 217 |
'source' => 9, |
| 218 |
// NORMAL | VOID_TAG |
| 219 |
'span' => 1, |
| 220 |
'strong' => 1, |
| 221 |
'style' => 3, |
| 222 |
// NORMAL | TEXT_RAW |
| 223 |
'sub' => 1, |
| 224 |
'summary' => 17, |
| 225 |
// NORMAL | AUTOCLOSE_P, |
| 226 |
'sup' => 1, |
| 227 |
'table' => 65, |
| 228 |
// NORMAL | BLOCK_TAG |
| 229 |
'tbody' => 1, |
| 230 |
'td' => 1, |
| 231 |
'textarea' => 5, |
| 232 |
// NORMAL | TEXT_RCDATA |
| 233 |
'tfoot' => 65, |
| 234 |
// NORMAL | BLOCK_TAG |
| 235 |
'th' => 1, |
| 236 |
'thead' => 1, |
| 237 |
'time' => 1, |
| 238 |
'title' => 5, |
| 239 |
// NORMAL | TEXT_RCDATA |
| 240 |
'tr' => 1, |
| 241 |
'track' => 9, |
| 242 |
// NORMAL | VOID_TAG |
| 243 |
'u' => 1, |
| 244 |
'ul' => 81, |
| 245 |
// NORMAL | AUTOCLOSE_P | BLOCK_TAG |
| 246 |
'var' => 1, |
| 247 |
'video' => 1, |
| 248 |
'wbr' => 9, |
| 249 |
// NORMAL | VOID_TAG |
| 250 |
// Legacy? |
| 251 |
'basefont' => 8, |
| 252 |
// VOID_TAG |
| 253 |
'bgsound' => 8, |
| 254 |
// VOID_TAG |
| 255 |
'noframes' => 2, |
| 256 |
// RAW_TEXT |
| 257 |
'frame' => 9, |
| 258 |
// NORMAL | VOID_TAG |
| 259 |
'frameset' => 1, |
| 260 |
'center' => 16, |
| 261 |
'dir' => 16, |
| 262 |
'listing' => 16, |
| 263 |
// AUTOCLOSE_P |
| 264 |
'plaintext' => 48, |
| 265 |
// AUTOCLOSE_P | TEXT_PLAINTEXT |
| 266 |
'applet' => 0, |
| 267 |
'marquee' => 0, |
| 268 |
'isindex' => 8, |
| 269 |
// VOID_TAG |
| 270 |
'xmp' => 20, |
| 271 |
// AUTOCLOSE_P | VOID_TAG | RAW_TEXT |
| 272 |
'noembed' => 2, |
| 273 |
); |
| 274 |
/** |
| 275 |
* The MathML elements. |
| 276 |
* See http://www.w3.org/wiki/MathML/Elements. |
| 277 |
* |
| 278 |
* In our case we are only concerned with presentation MathML and not content |
| 279 |
* MathML. There is a nice list of this subset at https://developer.mozilla.org/en-US/docs/MathML/Element. |
| 280 |
* |
| 281 |
* @var array |
| 282 |
*/ |
| 283 |
public static $mathml = array('maction' => 1, 'maligngroup' => 1, 'malignmark' => 1, 'math' => 1, 'menclose' => 1, 'merror' => 1, 'mfenced' => 1, 'mfrac' => 1, 'mglyph' => 1, 'mi' => 1, 'mlabeledtr' => 1, 'mlongdiv' => 1, 'mmultiscripts' => 1, 'mn' => 1, 'mo' => 1, 'mover' => 1, 'mpadded' => 1, 'mphantom' => 1, 'mroot' => 1, 'mrow' => 1, 'ms' => 1, 'mscarries' => 1, 'mscarry' => 1, 'msgroup' => 1, 'msline' => 1, 'mspace' => 1, 'msqrt' => 1, 'msrow' => 1, 'mstack' => 1, 'mstyle' => 1, 'msub' => 1, 'msup' => 1, 'msubsup' => 1, 'mtable' => 1, 'mtd' => 1, 'mtext' => 1, 'mtr' => 1, 'munder' => 1, 'munderover' => 1); |
| 284 |
/** |
| 285 |
* The svg elements. |
| 286 |
* |
| 287 |
* The Mozilla documentation has a good list at https://developer.mozilla.org/en-US/docs/SVG/Element. |
| 288 |
* The w3c list appears to be lacking in some areas like filter effect elements. |
| 289 |
* That list can be found at http://www.w3.org/wiki/SVG/Elements. |
| 290 |
* |
| 291 |
* Note, FireFox appears to do a better job rendering filter effects than chrome. |
| 292 |
* While they are in the spec I'm not sure how widely implemented they are. |
| 293 |
* |
| 294 |
* @var array |
| 295 |
*/ |
| 296 |
public static $svg = array( |
| 297 |
'a' => 1, |
| 298 |
'altGlyph' => 1, |
| 299 |
'altGlyphDef' => 1, |
| 300 |
'altGlyphItem' => 1, |
| 301 |
'animate' => 1, |
| 302 |
'animateColor' => 1, |
| 303 |
'animateMotion' => 1, |
| 304 |
'animateTransform' => 1, |
| 305 |
'circle' => 1, |
| 306 |
'clipPath' => 1, |
| 307 |
'color-profile' => 1, |
| 308 |
'cursor' => 1, |
| 309 |
'defs' => 1, |
| 310 |
'desc' => 1, |
| 311 |
'ellipse' => 1, |
| 312 |
'feBlend' => 1, |
| 313 |
'feColorMatrix' => 1, |
| 314 |
'feComponentTransfer' => 1, |
| 315 |
'feComposite' => 1, |
| 316 |
'feConvolveMatrix' => 1, |
| 317 |
'feDiffuseLighting' => 1, |
| 318 |
'feDisplacementMap' => 1, |
| 319 |
'feDistantLight' => 1, |
| 320 |
'feFlood' => 1, |
| 321 |
'feFuncA' => 1, |
| 322 |
'feFuncB' => 1, |
| 323 |
'feFuncG' => 1, |
| 324 |
'feFuncR' => 1, |
| 325 |
'feGaussianBlur' => 1, |
| 326 |
'feImage' => 1, |
| 327 |
'feMerge' => 1, |
| 328 |
'feMergeNode' => 1, |
| 329 |
'feMorphology' => 1, |
| 330 |
'feOffset' => 1, |
| 331 |
'fePointLight' => 1, |
| 332 |
'feSpecularLighting' => 1, |
| 333 |
'feSpotLight' => 1, |
| 334 |
'feTile' => 1, |
| 335 |
'feTurbulence' => 1, |
| 336 |
'filter' => 1, |
| 337 |
'font' => 1, |
| 338 |
'font-face' => 1, |
| 339 |
'font-face-format' => 1, |
| 340 |
'font-face-name' => 1, |
| 341 |
'font-face-src' => 1, |
| 342 |
'font-face-uri' => 1, |
| 343 |
'foreignObject' => 1, |
| 344 |
'g' => 1, |
| 345 |
'glyph' => 1, |
| 346 |
'glyphRef' => 1, |
| 347 |
'hkern' => 1, |
| 348 |
'image' => 1, |
| 349 |
'line' => 1, |
| 350 |
'linearGradient' => 1, |
| 351 |
'marker' => 1, |
| 352 |
'mask' => 1, |
| 353 |
'metadata' => 1, |
| 354 |
'missing-glyph' => 1, |
| 355 |
'mpath' => 1, |
| 356 |
'path' => 1, |
| 357 |
'pattern' => 1, |
| 358 |
'polygon' => 1, |
| 359 |
'polyline' => 1, |
| 360 |
'radialGradient' => 1, |
| 361 |
'rect' => 1, |
| 362 |
'script' => 3, |
| 363 |
// NORMAL | RAW_TEXT |
| 364 |
'set' => 1, |
| 365 |
'stop' => 1, |
| 366 |
'style' => 3, |
| 367 |
// NORMAL | RAW_TEXT |
| 368 |
'svg' => 1, |
| 369 |
'switch' => 1, |
| 370 |
'symbol' => 1, |
| 371 |
'text' => 1, |
| 372 |
'textPath' => 1, |
| 373 |
'title' => 1, |
| 374 |
'tref' => 1, |
| 375 |
'tspan' => 1, |
| 376 |
'use' => 1, |
| 377 |
'view' => 1, |
| 378 |
'vkern' => 1, |
| 379 |
); |
| 380 |
/** |
| 381 |
* Some attributes in SVG are case sensitive. |
| 382 |
* |
| 383 |
* This map contains key/value pairs with the key as the lowercase attribute |
| 384 |
* name and the value with the correct casing. |
| 385 |
*/ |
| 386 |
public static $svgCaseSensitiveAttributeMap = array('attributename' => 'attributeName', 'attributetype' => 'attributeType', 'basefrequency' => 'baseFrequency', 'baseprofile' => 'baseProfile', 'calcmode' => 'calcMode', 'clippathunits' => 'clipPathUnits', 'contentscripttype' => 'contentScriptType', 'contentstyletype' => 'contentStyleType', 'diffuseconstant' => 'diffuseConstant', 'edgemode' => 'edgeMode', 'externalresourcesrequired' => 'externalResourcesRequired', 'filterres' => 'filterRes', 'filterunits' => 'filterUnits', 'glyphref' => 'glyphRef', 'gradienttransform' => 'gradientTransform', 'gradientunits' => 'gradientUnits', 'kernelmatrix' => 'kernelMatrix', 'kernelunitlength' => 'kernelUnitLength', 'keypoints' => 'keyPoints', 'keysplines' => 'keySplines', 'keytimes' => 'keyTimes', 'lengthadjust' => 'lengthAdjust', 'limitingconeangle' => 'limitingConeAngle', 'markerheight' => 'markerHeight', 'markerunits' => 'markerUnits', 'markerwidth' => 'markerWidth', 'maskcontentunits' => 'maskContentUnits', 'maskunits' => 'maskUnits', 'numoctaves' => 'numOctaves', 'pathlength' => 'pathLength', 'patterncontentunits' => 'patternContentUnits', 'patterntransform' => 'patternTransform', 'patternunits' => 'patternUnits', 'pointsatx' => 'pointsAtX', 'pointsaty' => 'pointsAtY', 'pointsatz' => 'pointsAtZ', 'preservealpha' => 'preserveAlpha', 'preserveaspectratio' => 'preserveAspectRatio', 'primitiveunits' => 'primitiveUnits', 'refx' => 'refX', 'refy' => 'refY', 'repeatcount' => 'repeatCount', 'repeatdur' => 'repeatDur', 'requiredextensions' => 'requiredExtensions', 'requiredfeatures' => 'requiredFeatures', 'specularconstant' => 'specularConstant', 'specularexponent' => 'specularExponent', 'spreadmethod' => 'spreadMethod', 'startoffset' => 'startOffset', 'stddeviation' => 'stdDeviation', 'stitchtiles' => 'stitchTiles', 'surfacescale' => 'surfaceScale', 'systemlanguage' => 'systemLanguage', 'tablevalues' => 'tableValues', 'targetx' => 'targetX', 'targety' => 'targetY', 'textlength' => 'textLength', 'viewbox' => 'viewBox', 'viewtarget' => 'viewTarget', 'xchannelselector' => 'xChannelSelector', 'ychannelselector' => 'yChannelSelector', 'zoomandpan' => 'zoomAndPan'); |
| 387 |
/** |
| 388 |
* Some SVG elements are case sensitive. |
| 389 |
* This map contains these. |
| 390 |
* |
| 391 |
* The map contains key/value store of the name is lowercase as the keys and |
| 392 |
* the correct casing as the value. |
| 393 |
*/ |
| 394 |
public static $svgCaseSensitiveElementMap = array('altglyph' => 'altGlyph', 'altglyphdef' => 'altGlyphDef', 'altglyphitem' => 'altGlyphItem', 'animatecolor' => 'animateColor', 'animatemotion' => 'animateMotion', 'animatetransform' => 'animateTransform', 'clippath' => 'clipPath', 'feblend' => 'feBlend', 'fecolormatrix' => 'feColorMatrix', 'fecomponenttransfer' => 'feComponentTransfer', 'fecomposite' => 'feComposite', 'feconvolvematrix' => 'feConvolveMatrix', 'fediffuselighting' => 'feDiffuseLighting', 'fedisplacementmap' => 'feDisplacementMap', 'fedistantlight' => 'feDistantLight', 'feflood' => 'feFlood', 'fefunca' => 'feFuncA', 'fefuncb' => 'feFuncB', 'fefuncg' => 'feFuncG', 'fefuncr' => 'feFuncR', 'fegaussianblur' => 'feGaussianBlur', 'feimage' => 'feImage', 'femerge' => 'feMerge', 'femergenode' => 'feMergeNode', 'femorphology' => 'feMorphology', 'feoffset' => 'feOffset', 'fepointlight' => 'fePointLight', 'fespecularlighting' => 'feSpecularLighting', 'fespotlight' => 'feSpotLight', 'fetile' => 'feTile', 'feturbulence' => 'feTurbulence', 'foreignobject' => 'foreignObject', 'glyphref' => 'glyphRef', 'lineargradient' => 'linearGradient', 'radialgradient' => 'radialGradient', 'textpath' => 'textPath'); |
| 395 |
/** |
| 396 |
* Check whether the given element meets the given criterion. |
| 397 |
* |
| 398 |
* Example: |
| 399 |
* |
| 400 |
* Elements::isA('script', Elements::TEXT_RAW); // Returns true. |
| 401 |
* |
| 402 |
* Elements::isA('script', Elements::TEXT_RCDATA); // Returns false. |
| 403 |
* |
| 404 |
* @param string $name The element name. |
| 405 |
* @param int $mask One of the constants on this class. |
| 406 |
* |
| 407 |
* @return bool true if the element matches the mask, false otherwise. |
| 408 |
*/ |
| 409 |
public static function isA($name, $mask) |
| 410 |
{ |
| 411 |
return (static::element($name) & $mask) === $mask; |
| 412 |
} |
| 413 |
/** |
| 414 |
* Test if an element is a valid html5 element. |
| 415 |
* |
| 416 |
* @param string $name The name of the element. |
| 417 |
* |
| 418 |
* @return bool true if a html5 element and false otherwise. |
| 419 |
*/ |
| 420 |
public static function isHtml5Element($name) |
| 421 |
{ |
| 422 |
// html5 element names are case insensitive. Forcing lowercase for the check. |
| 423 |
// Do we need this check or will all data passed here already be lowercase? |
| 424 |
return isset(static::$html5[strtolower($name)]); |
| 425 |
} |
| 426 |
/** |
| 427 |
* Test if an element name is a valid MathML presentation element. |
| 428 |
* |
| 429 |
* @param string $name The name of the element. |
| 430 |
* |
| 431 |
* @return bool true if a MathML name and false otherwise. |
| 432 |
*/ |
| 433 |
public static function isMathMLElement($name) |
| 434 |
{ |
| 435 |
// MathML is case-sensitive unlike html5 elements. |
| 436 |
return isset(static::$mathml[$name]); |
| 437 |
} |
| 438 |
/** |
| 439 |
* Test if an element is a valid SVG element. |
| 440 |
* |
| 441 |
* @param string $name The name of the element. |
| 442 |
* |
| 443 |
* @return bool true if a SVG element and false otherise. |
| 444 |
*/ |
| 445 |
public static function isSvgElement($name) |
| 446 |
{ |
| 447 |
// SVG is case-sensitive unlike html5 elements. |
| 448 |
return isset(static::$svg[$name]); |
| 449 |
} |
| 450 |
/** |
| 451 |
* Is an element name valid in an html5 document. |
| 452 |
* This includes html5 elements along with other allowed embedded content |
| 453 |
* such as svg and mathml. |
| 454 |
* |
| 455 |
* @param string $name The name of the element. |
| 456 |
* |
| 457 |
* @return bool true if valid and false otherwise. |
| 458 |
*/ |
| 459 |
public static function isElement($name) |
| 460 |
{ |
| 461 |
return static::isHtml5Element($name) || static::isMathMLElement($name) || static::isSvgElement($name); |
| 462 |
} |
| 463 |
/** |
| 464 |
* Get the element mask for the given element name. |
| 465 |
* |
| 466 |
* @param string $name The name of the element. |
| 467 |
* |
| 468 |
* @return int the element mask. |
| 469 |
*/ |
| 470 |
public static function element($name) |
| 471 |
{ |
| 472 |
if (isset(static::$html5[$name])) { |
| 473 |
return static::$html5[$name]; |
| 474 |
} |
| 475 |
if (isset(static::$svg[$name])) { |
| 476 |
return static::$svg[$name]; |
| 477 |
} |
| 478 |
if (isset(static::$mathml[$name])) { |
| 479 |
return static::$mathml[$name]; |
| 480 |
} |
| 481 |
return 0; |
| 482 |
} |
| 483 |
/** |
| 484 |
* Normalize a SVG element name to its proper case and form. |
| 485 |
* |
| 486 |
* @param string $name The name of the element. |
| 487 |
* |
| 488 |
* @return string the normalized form of the element name. |
| 489 |
*/ |
| 490 |
public static function normalizeSvgElement($name) |
| 491 |
{ |
| 492 |
$name = strtolower($name); |
| 493 |
if (isset(static::$svgCaseSensitiveElementMap[$name])) { |
| 494 |
$name = static::$svgCaseSensitiveElementMap[$name]; |
| 495 |
} |
| 496 |
return $name; |
| 497 |
} |
| 498 |
/** |
| 499 |
* Normalize a SVG attribute name to its proper case and form. |
| 500 |
* |
| 501 |
* @param string $name The name of the attribute. |
| 502 |
* |
| 503 |
* @return string The normalized form of the attribute name. |
| 504 |
*/ |
| 505 |
public static function normalizeSvgAttribute($name) |
| 506 |
{ |
| 507 |
$name = strtolower($name); |
| 508 |
if (isset(static::$svgCaseSensitiveAttributeMap[$name])) { |
| 509 |
$name = static::$svgCaseSensitiveAttributeMap[$name]; |
| 510 |
} |
| 511 |
return $name; |
| 512 |
} |
| 513 |
/** |
| 514 |
* Normalize a MathML attribute name to its proper case and form. |
| 515 |
* Note, all MathML element names are lowercase. |
| 516 |
* |
| 517 |
* @param string $name The name of the attribute. |
| 518 |
* |
| 519 |
* @return string The normalized form of the attribute name. |
| 520 |
*/ |
| 521 |
public static function normalizeMathMlAttribute($name) |
| 522 |
{ |
| 523 |
$name = strtolower($name); |
| 524 |
// Only one attribute has a mixed case form for MathML. |
| 525 |
if ('definitionurl' === $name) { |
| 526 |
$name = 'definitionURL'; |
| 527 |
} |
| 528 |
return $name; |
| 529 |
} |
| 530 |
} |
| 531 |
|