def document node
result = []
if (root_tag_name = node.doctype) == 'manpage'
root_tag_name = 'refentry'
end
result << '<?xml version="1.0" encoding="UTF-8"?>'
if (doctype_line = doctype_declaration root_tag_name)
result << doctype_line
end
if node.attr? 'toc'
if node.attr? 'toclevels'
result << %(<?asciidoc-toc maxdepth="#{node.attr 'toclevels'}"?>)
else
result << '<?asciidoc-toc?>'
end
end
if node.attr? 'sectnums'
if node.attr? 'sectnumlevels'
result << %(<?asciidoc-numbered maxdepth="#{node.attr 'sectnumlevels'}"?>)
else
result << '<?asciidoc-numbered?>'
end
end
lang_attribute = (node.attr? 'nolang') ? nil : %( #{lang_attribute_name}="#{node.attr 'lang', 'en'}")
result << %(<#{root_tag_name}#{document_ns_attributes node}#{lang_attribute}>)
result << (document_info_element node, root_tag_name)
result << node.content if node.blocks?
unless (footer_docinfo = node.docinfo :footer).empty?
result << footer_docinfo
end
result << %(</#{root_tag_name}>)
result * EOL
end