html5-php icon indicating copy to clipboard operation
html5-php copied to clipboard

Prevent wrapping in <!DOCTYPE html> <html>

Open Yahav opened this issue 1 year ago • 3 comments

Any way to prevent the saveHTML method from wrapping the output in ? inb4 loadHTMLFragment, can't use it since it won't allow to use the getElementsByTagName method.

Yahav avatar Jan 30 '23 19:01 Yahav

It's a workaround but here's how I'm achieving this:

str_replace(
  ['<!DOCTYPE html>', '<html>', '<body>', '</body>', '</html>'],
  '',
  $html->saveHTML($dom)
)

thunderdw avatar Mar 01 '23 20:03 thunderdw

that is not cool

jason-engage avatar May 03 '23 19:05 jason-engage

In my code I can prevent the wrapper markup when I render only the fragment that was parsed:

$events = new DOMTreeBuilder(true, $options);
$scanner = new Scanner('<p>Hello World!</p>');
$parser = new Tokenizer($scanner, $events);

$parser->parse();

$html5 = new HTML5();
echo $html5->saveHTML($events->fragment());

Boldewyn avatar May 08 '23 11:05 Boldewyn