Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent wrapping in <!DOCTYPE html> <html> #226

Open
Yahav opened this issue Jan 30, 2023 · 3 comments
Open

Prevent wrapping in <!DOCTYPE html> <html> #226

Yahav opened this issue Jan 30, 2023 · 3 comments

Comments

@Yahav
Copy link

Yahav commented Jan 30, 2023

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.

@thunderdw
Copy link

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

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

@jason-engage
Copy link

that is not cool

@Boldewyn
Copy link

Boldewyn commented May 8, 2023

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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants