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

Unexpected automatically added new lines #103

Closed
RenWenshan opened this issue May 13, 2014 · 5 comments
Closed

Unexpected automatically added new lines #103

RenWenshan opened this issue May 13, 2014 · 5 comments

Comments

@RenWenshan
Copy link

After sanitizing, a one liner html string become a multiple line string, for example:

Sanitize.clean("Best fit for:<ul><li>US Dollars</li><li>Australian Dollars</li><li>Canadian Dollars</li><li>New Zealand Dollars</li><li>Russian Rubles</li><li>and currencies up to 8.5cm</li></ul>", :elements => %w(div span strong br p a ul li em b i), :attributes => {'a' => ['href', 'title', 'target'], :all => ['class', 'id', 'style', 'data-show']})
 => "Best fit for:<ul>\n<li>US Dollars</li>\n<li>Australian Dollars</li>\n<li>Canadian Dollars</li>\n<li>New Zealand Dollars</li>\n<li>Russian Rubles</li>\n<li>and currencies up to 8.5cm</li>\n</ul>" 

Can I pass some argument in to avoid this? I'd like to keep it one-liner.

@rgrove
Copy link
Owner

rgrove commented May 13, 2014

Sadly, this is being done by Nokogiri and isn't something Sanitize has control over. Sorry.

Nokogiri::HTML::DocumentFragment.parse("Best fit for:<ul><li>US Dollars</li><li>Australian Dollars</li><li>Canadian Dollars</li><li>New Zealand Dollars</li><li>Russian Rubles</li><li>and currencies up to 8.5cm</li></ul>").to_html
=> "Best fit for:<ul>\n<li>US Dollars</li>\n<li>Australian Dollars</li>\n<li>Canadian Dollars</li>\n<li>New Zealand Dollars</li>\n<li>Russian Rubles</li>\n<li>and currencies up to 8.5cm</li>\n</ul>"

@rgrove
Copy link
Owner

rgrove commented May 18, 2014

@RenWenshan I lied! Turns out there is a (fairly obscure) way Sanitize can control this. This'll be fixed in 3.0.0.

@rgrove rgrove closed this as completed in ab2f5fa Jun 21, 2014
@abhi-patel
Copy link

I am still facing the similar issue with latest version 4.2.0

Sanitize.document('<html>Hello</html>', Sanitize::Config::RELAXED)
==> "<html><head></head><body>Hello</body></html>\n"

Am I missing anything here?

@rgrove
Copy link
Owner

rgrove commented Aug 27, 2016

@abhi-patel Is calling strip not an option for some reason?

Sanitize.document('<html>Hello</html>', Sanitize::Config::RELAXED).strip
# => "<html><head></head><body>Hello</body></html>"

@abhi-patel
Copy link

Should be fine I guess. I just wanted to confirm if the response I am getting is correct or there are other options/flags to resolve this.

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

No branches or pull requests

3 participants