Nokogiri saves XML attributes with double quotes, even if DOM it read had single quotes.
This is totally legitimate of course, but it introduces annoying changes to file contents even when DOM didn’t change, making it harder for tools like diff and git to figure out what happened.
Can I force it to use single quotes (or even better, keep whatever quoting style there was in the original if nothing was modified)?
REXML has this for setting single/double quote:
doc.context[:attribute_quote] = :quote
I couldn’t find anything similar for nokogiri.
Is it possible to have it save documents with single quotes?
It looks like the answer is no; not as the library is currently written, and maybe not at all. Tracing the call path for a node’s serialization:
Nokogiri::XML::Node#to_scallsto_xmlNokogiri::XML::Node#to_xmlcallsserialize(sets a few default options)Nokogiri::XML::Node#serializecallswrite_toNokogiri::XML::Node#write_tocallsnative_write_toNokogiri::XML::Node#native_write_tocallsnative_write_to, which looks like this:&bsp;
So, you are at the mercy of libxml at this point. Googling for libxml serialize single quote attributes does not immediately turn up any smoking guns.
I think you should file a feature request and see what sort of tenderlovin’ you can get. 🙂