Masterminds/html5-php

img inside a figure will create an opening and closing img tag

creutz opened this issue · 5 comments

<figure><img src=""></figure> will create <figure><img src=""></img></figure>. Is this by design?

I have tried and i'm not able to reproduce it. for me <figure><img src=""></figure> it is serialized correctly as <figure><img src=""/></figure>.

can you please provide a failing test case?

stof commented

I cannot reproduce this when using $html5->saveHTML($dom);

Using $dom->saveHTML() indeed produces <figure><img src=""></img></figure>, but this is because it does not use the HTML5 renderer. The built-in PHP HTML renderer uses XHTML, not HTML5.

Thanks for replying so quickly. I had this code:

$html5 = new HTML5();
$doc = $html5->loadHTML($string);
echo $html5->saveHTML($doc);

where $string is some HTML without doctype, html, body.

but this is because it does not use the HTML5 renderer. The built-in PHP HTML renderer uses XHTML, not HTML5.

But I used the methods described in the documentation?

I tried ivopetkov/html5-dom-document-php and that worked better for me. I dont know if this here is a bug or if I am too stupid to use this lib.

I also was not able to reproduce this behavior.

<?php
require 'vendor/autoload.php';
$html5 = new Masterminds\HTML5();
$string = '<figure><img src=""></figure>';
$doc = $html5->loadHTML($string);
echo $html5->saveHTML($doc);

outputs

<!DOCTYPE html>
<html><figure><img src=""></figure></html>

By using DOMDocumentFragment it is possible to focus on the submitted fragment only.

<?php
require 'vendor/autoload.php';
$html5 = new Masterminds\HTML5();
$string = '<figure><img src=""></figure>';
$fragment = $html5->parseFragment($string);
echo $html5->saveHTML($fragment);

outputs

<figure><img src=""></figure>

closing as "can not reproduce"