class Nokogiri::HTML::Document
def title=(text)
encoding/charset tag if any, and before any text node or
is inside a head element if any, right after a meta
place supplying head and/or html elements as necessary, which
Otherwise, this method tries to create one at an appropriate
with the given text.
If a title element is already present, its content is replaced
Set the title string of this document.
##
def title=(text) tnode = XML::Text.new(text, self) if title = at('//title') title.children = tnode return text end title = XML::Node.new('title', self) << tnode case when head = at('//head') head << title when meta = at('//meta[@charset]') || meta_content_type # better put after charset declaration meta.add_next_sibling(title) else set_metadata_element(title) end text end