Create a script tag, wrap the contents in CDATA (with the appropriate JavaScript comments) and watch Nokogiri just wreck the output when using to_xhtml.