def document node
unless node.attr? 'mantitle'
raise 'asciidoctor: ERROR: doctype must be set to manpage when using manpage backend'
end
mantitle = node.attr 'mantitle'
manvolnum = node.attr 'manvolnum', '1'
manname = node.attr 'manname', mantitle
docdate = (node.attr? 'reproducible') ? nil : (node.attr 'docdate')
result = [%('\\" t
.\\" Title: #{mantitle}
.\\" Author: #{(node.attr? 'authors') ? (node.attr 'authors') : '[see the "AUTHORS" section]'}
.\\" Generator: Asciidoctor #{node.attr 'asciidoctor-version'})]
result << %(.\\" Date: #{docdate}) if docdate
result << %(.\\" Manual: #{(manual = node.attr 'manmanual') || '\ \&'}
.\\" Source: #{(source = node.attr 'mansource') || '\ \&'}
.\\" Language: English
.\\")
result << %(.TH "#{manify manname.upcase}" "#{manvolnum}" "#{docdate}" "#{source ? (manify source) : '\ \&'}" "#{manual ? (manify manual) : '\ \&'}")
result << '.ie \n(.g .ds Aq \(aq'
result << '.el .ds Aq \''
result << '.ss \n[.ss] 0'
result << '.nh'
result << '.ad l'
result << '.de URL
\\\\$2 \(laURL: \\\\$1 \(ra\\\\$3
..
.if \n[.g] .mso www.tmac'
result << %(.LINKSTYLE #{node.attr 'man-linkstyle', 'blue R < >'})
unless node.noheader
if node.attr? 'manpurpose'
result << %(.SH "#{node.attr 'manname-title'}"
#{manify mantitle} \\- #{manify node.attr 'manpurpose'})
end
end
result << node.content
if node.footnotes? && !(node.attr? 'nofootnotes')
result << '.SH "NOTES"'
result.concat(node.footnotes.map {|fn| %(#{fn.index}. #{fn.text}) })
end
if node.attr? 'authors'
result << %(.SH "AUTHOR(S)"
.sp
\\fB#{node.attr 'authors'}\\fP
.RS 4
Author(s).
.RE)
end
result * LF
end