diff options
Diffstat (limited to 'src/HTML5/Elements.php')
-rw-r--r-- | src/HTML5/Elements.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/HTML5/Elements.php b/src/HTML5/Elements.php index d437960..ad58363 100644 --- a/src/HTML5/Elements.php +++ b/src/HTML5/Elements.php @@ -1,6 +1,13 @@ <?php namespace HTML5; +/** + * Provide general element functions. + * + * @todo consider using a bitmask table lookup. There is enought overlap in + * naming that this could significantly shrink the size and maybe make it + * faster. See the Go teams implementation at https://code.google.com/p/go/source/browse/html/atom. + */ class Elements { const TEXT_RAW = 0x01; @@ -126,6 +133,56 @@ class Elements { ); /** + * The MathML elements. See http://www.w3.org/wiki/MathML/Elements. + * + * In our case we are only concerned with presentation MathML and not content + * MathML. There is a nice list of this subset at https://developer.mozilla.org/en-US/docs/MathML/Element. + * + * @var array + */ + 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, + ); + + /** * Test if an element is a valid html5 element. * * @param string $name @@ -140,4 +197,35 @@ class Elements { // Do we need this check or will all data passed here already be lowercase? return isset(self::$elements[strtolower($name)]); } + + /** + * Test if an element name is a valid MathML presentation element. + * + * @param string $name + * The name of the element. + * + * @return bool + * True if a MathML name and false otherwise. + */ + public static function isMathMLElement($name) { + + // MathML is case-sensetitive unlike html5 elements. + return isset(self::$mathml[$name]); + } + + /** + * Is an element name valid in an html5 document. + * + * This includes html5 elements along with other allowed embedded content + * such as svg and mathml. + * + * @param string $name + * The name of the element. + * + * @return bool + * True if valid and false otherwise. + */ + public function isElement($name) { + return self::isHtml5Element($name) || self::isMathMLElement($name); + } } |