diff options
author | Matt Farina <[email protected]> | 2013-05-18 08:55:40 -0400 |
---|---|---|
committer | Matt Farina <[email protected]> | 2013-05-18 08:55:40 -0400 |
commit | 3c3f0503471071565a56ee9ea9c01ca428467ad8 (patch) | |
tree | 61bbbfd1cae9223374692b98525b683de9dc69c7 /src/HTML5/Serializer/Serializer.php | |
parent | 7e8b07cb024b2cc857f19bb9ca7b0b59395e04ee (diff) |
General escaping and full html5 encoding with named character references work.
Diffstat (limited to 'src/HTML5/Serializer/Serializer.php')
-rw-r--r-- | src/HTML5/Serializer/Serializer.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/HTML5/Serializer/Serializer.php b/src/HTML5/Serializer/Serializer.php index f16bbe2..3f9187f 100644 --- a/src/HTML5/Serializer/Serializer.php +++ b/src/HTML5/Serializer/Serializer.php @@ -16,6 +16,7 @@ namespace HTML5\Serializer; class Serializer { protected $dom; protected $pretty = TRUE; + protected $encode = FALSE; /** * Create a serializer. @@ -25,13 +26,24 @@ class Serializer { * * @param DOMNode $dom * A DOMNode-like object. Typically, a DOMDocument should be passed. - * @param boolean $format - * If true, this will format the output (e.g. add indentation). If FALSE, then - * little or no formatting will be done. + * @param array $options + * Options that can be passed into the serializer. These include: + * - format: a bool value to specify if formatting (e.g. add indentation) + * should be used on the output. Defaults to TRUE. + * - encode: Text written to the output is escaped by default and not all + * entities are encoded. If this is set to TRUE all entities will be encoded. + * Defaults to FALSE. */ - public function __construct($dom, $format = TRUE) { + public function __construct($dom, $options = array()) { $this->dom = $dom; - $this->pretty = $format; + + if (isset($options['format']) && is_bool($options['format'])) { + $this->pretty = $options['format']; + } + + if (isset($options['encode']) && is_bool($options['encode'])) { + $this->encode = $options['encode']; + } } /** @@ -53,6 +65,7 @@ class Serializer { } $trav = new Traverser($this->dom, $file); $trav->formatOutput($this->pretty); + $trav->encodeOutput($this->encode); $trav->walk(); |