Skip to content

Commit

Permalink
Finally figured out the proper incantation to make Nokogiri stop addi…
Browse files Browse the repository at this point in the history
…ng newlines after certain elements.

Fixes #103.
  • Loading branch information
rgrove committed May 18, 2014
1 parent 4fbc2ad commit ab2f5fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ increment.

* The `:output_encoding` config has been removed. Output is now always UTF-8.

### Other changes

* Fixed: Nokogiri has been smacked and instructed to stop adding newlines after
certain elements, because if people wanted newlines there they'd have put them
there, dammit. [#103][103]

[103]:https://github.com/rgrove/sanitize/issues/103


Version 2.2.0 (git)
-------------------
Expand Down
9 changes: 7 additions & 2 deletions lib/sanitize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ def node!(node)
private

def to_html(node)
so = Nokogiri::XML::Node::SaveOptions

# Serialize to HTML without any formatting to prevent Nokogiri from adding
# newlines after certain tags.
node.to_html(
:encoding => 'utf-8',
:indent => 0
:encoding => 'utf-8',
:indent => 0,
:save_with => so::NO_DECLARATION | so::NO_EMPTY_TAGS | so::AS_HTML
)
end

Expand Down

0 comments on commit ab2f5fa

Please sign in to comment.