Masterminds / html5-php

An HTML5 parser and serializer for PHP.
http://masterminds.github.io/html5-php/
Other
1.55k stars 114 forks source link

Question #212

Closed Lofesa closed 1 month ago

Lofesa commented 2 years ago

Hi I come here to ask a, maybe, dumb question. I used a WP plugin that uses this library to make changes to the html. This html contain inlined svg like:

< svg xmlns= "https://www.w3.org/2000/svg" some stuff here ></svg>

After get parsed this becomes:

< svg some stuff here /></svg>

Is there any way to preserve the xmlns attribute and don´t set the autoclosig / ?

Thx in advance.

stof commented 1 year ago

Are you using $dom->saveHTML() or $html5->saveHTML($dom); to generate the output ? Using DOMDocument::saveHTML is known to produce a wrong output because the DOMDocument implementation in PHP is not aware of HTML5 rules.

Lofesa commented 1 year ago

The plugin uses html5->saveHTML($dom);

stof commented 1 year ago

Can you provide an actual reproducer ?

Lofesa commented 1 year ago

Yes this url https://intersindicalrm.org/la-intersindical-se-extiende-al-servicio-murciano-de-salud/ These icons in the image have the xmlns attribute but get stripped

Captura de pantalla 2023-01-12 133330
stof commented 1 year ago

When I take this URL, the SVG icons don't have the xmlns attribute.

Lofesa commented 1 year ago

Yes, because are striped

For example, the arrow up svg, the original is

$output = '<svg viewBox="0 0 330 512" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414"><path d="M305.863 314.916c0 2.266-1.133 4.815-2.832 6.514l-14.157 14.163c-1.699 1.7-3.964 2.832-6.513 2.832-2.265 0-4.813-1.133-6.512-2.832L164.572 224.276 53.295 335.593c-1.699 1.7-4.247 2.832-6.512 2.832-2.265 0-4.814-1.133-6.513-2.832L26.113 321.43c-1.699-1.7-2.831-4.248-2.831-6.514s1.132-4.816 2.831-6.515L158.06 176.408c1.699-1.7 4.247-2.833 6.512-2.833 2.265 0 4.814 1.133 6.513 2.833L303.03 308.4c1.7 1.7 2.832 4.249 2.832 6.515z" fill-rule="nonzero" /></svg>';

stof commented 1 year ago

If you give me a URL which shows the HTML being the output of the library, that's not a reproducing case.

stof commented 1 year ago

The xmlns is not rendered in the output of the library because it is useless when using a svg tag inside HTML: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg

goetas commented 1 month ago

closing as not able to reproduce