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

Switch to Nokogiri::HTML for html writer #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/approvals/writers/html_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def extension
end

def format(data)
Nokogiri::XML(data.to_s.strip,&:noblanks).to_xhtml(:indent => 2, :encoding => 'UTF-8')
Nokogiri::HTML(data.to_s.strip,&:noblanks).to_xhtml(:indent => 2, :encoding => 'UTF-8')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really like to move to to_html, but only to_xhtml allows for the nice formatting and indenting. Making the switch would be a breaking change.

end

end
Expand Down
11 changes: 11 additions & 0 deletions spec/approvals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def hello.inspect
Approvals.verify html, :format => :html, :namer => namer
end

it "verifies a malformed html fragment" do
html = <<-HTML
<!DOCTYPE html>
<html>
<title>Hoi</title>
<script async defer src="http://foo.com/bar.js"></script>
<h1>yo</h1>
HTML
Approvals.verify html, :format => :html, :namer => namer
end

it "verifies xml" do
xml = "<xml char=\"kiddo\"><node><content name='beatrice' /></node><node aliases='5'><content /></node></xml>"
Approvals.verify xml, :format => :xml, :namer => namer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hoi</title>
<script async="" defer="defer" src="http://foo.com/bar.js"></script>
</head>
<body>
<h1>yo</h1>
</body>
</html>