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

Formatting of html document is not well preserved #234

Closed
max-las opened this issue Mar 29, 2024 · 2 comments · Fixed by #235
Closed

Formatting of html document is not well preserved #234

max-las opened this issue Mar 29, 2024 · 2 comments · Fixed by #235

Comments

@max-las
Copy link

max-las commented Mar 29, 2024

Sanitize seems to break formatting around elements such as html, head and body.

Most obvious example would be the one in the readme :

html = %[
  <!DOCTYPE html>
  <html>
    <b><a href="http://foo.com/">foo</a></b><img src="bar.jpg">
  </html>
]

Sanitize.document(html,
  :allow_doctype => true,
  :elements      => ['html']
)

actually returns

<!DOCTYPE html><html>foo
  
</html>

instead of alleged

<!DOCTYPE html>
<html>foo

</html>

Here's a more complete example :

html = <<~HTML.chomp
  <!DOCTYPE html>
  <html>
    <head>
      <meta charset="UTF-8">
    </head>
    <body>
      <p>Hello</p>
    </body>
  </html>
HTML

Sanitize.document(html,
  allow_doctype: true,
  elements: %w[html head meta body p],
  attributes: { 'meta' => %w[charset] }
)

returns

<!DOCTYPE html><html><head>
    <meta charset="UTF-8">
  </head>
  <body>
    <p>Hello</p>
  
</body></html>
@rgrove
Copy link
Owner

rgrove commented Mar 30, 2024

Thanks for pointing this out!

Sanitize doesn't claim to be able to preserve formatting, but I agree it's awkward that the example output in the readme no longer matches the actual output.

flavorjones added a commit to flavorjones/sanitize that referenced this issue Apr 7, 2024
@flavorjones
Copy link
Contributor

I've opened #234 to fix the formatting in the README.

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

Successfully merging a pull request may close this issue.

3 participants