@@ -98,6 +98,13 @@ class Dom
9898 'wbr '
9999 ];
100100
101+ /**
102+ * A list of tags where there should be no /> at the end (html5 style)
103+ *
104+ * @var array
105+ */
106+ protected $ noSlash = [];
107+
101108 /**
102109 * Returns the inner html of the root node.
103110 *
@@ -275,6 +282,53 @@ public function clearSelfClosingTags()
275282 return $ this ;
276283 }
277284
285+
286+ /**
287+ * Adds a tag to the list of self closing tags that should not have a trailing slash
288+ *
289+ * @param $tag
290+ * @return $this
291+ */
292+ public function addNoSlashTag ($ tag )
293+ {
294+ if ( ! is_array ($ tag )) {
295+ $ tag = [$ tag ];
296+ }
297+ foreach ($ tag as $ value ) {
298+ $ this ->noSlash [] = $ value ;
299+ }
300+
301+ return $ this ;
302+ }
303+
304+ /**
305+ * Removes a tag from the list of no-slash tags.
306+ *
307+ * @param $tag
308+ * @return $this
309+ */
310+ public function removeNoSlashTag ($ tag )
311+ {
312+ if ( ! is_array ($ tag )) {
313+ $ tag = [$ tag ];
314+ }
315+ $ this ->noSlash = array_diff ($ this ->noSlash , $ tag );
316+
317+ return $ this ;
318+ }
319+
320+ /**
321+ * Empties the list of no-slash tags.
322+ *
323+ * @return $this
324+ */
325+ public function clearNoSlashTags ()
326+ {
327+ $ this ->noSlash = [];
328+
329+ return $ this ;
330+ }
331+
278332 /**
279333 * Simple wrapper function that returns the first child.
280334 *
@@ -596,6 +650,13 @@ protected function parseTag()
596650
597651 // We force self closing on this tag.
598652 $ node ->getTag ()->selfClosing ();
653+
654+ // Should this tag use a trailing slash?
655+ if (in_array ($ tag , $ this ->noSlash ))
656+ {
657+ $ node ->getTag ()->noTrailingSlash ();
658+ }
659+
599660 }
600661
601662 $ this ->content ->fastForward (1 );
0 commit comments