lib/draftjs_html/node.rb in draftjs_html-0.5.1 vs lib/draftjs_html/node.rb in draftjs_html-0.6.0

- old
+ new

@@ -5,11 +5,17 @@ end end StringNode = Struct.new(:raw) do def to_nokogiri(document) - raw - Nokogiri::XML::Text.new(raw, document) + lines = raw.lines + text_nodes = lines.flat_map.with_index do |text, i| + nodes = [Nokogiri::XML::Text.new(text.chomp, document)] + nodes << Nokogiri::XML::Node.new('br', document) if i < lines.size - 1 + nodes + end + + Nokogiri::XML::NodeSet.new(document, text_nodes) end end Node = Struct.new(:element_name, :attributes, :content) do def self.of(thing)