lib/asciidoctor/converter/manpage.rb in asciidoctor-2.0.20 vs lib/asciidoctor/converter/manpage.rb in asciidoctor-2.0.21
- old
+ new
@@ -1,8 +1,8 @@
# frozen_string_literal: true
module Asciidoctor
-# A built-in {Converter} implementation that generates the man page (troff) format.
+# A built-in {Converter} implementation that generates the man page (groff) format.
#
# The output of this converter adheres to the man definition as defined by
# groff and uses the manpage output of the DocBook toolchain as a foundation.
# That means if you've previously been generating man pages using the a2x tool
# from AsciiDoc.py, you should be able to achieve a very similar result
@@ -430,11 +430,11 @@
when :asciidoc
cell_content = cell.content
when :literal
cell_content = %(.nf#{LF}#{manify cell.text, whitespace: :preserve}#{LF}.fi)
else
- cell_content = manify cell.content.join, whitespace: :normalize
+ cell_content = cell.content.map {|p| manify p, whitespace: :normalize }.join %(#{LF}.sp#{LF})
end
row_text[row_index] << %(#{cell_content}#{LF})
else # tsec == :head || tsec == :foot
if row_header[row_index].empty? || row_header[row_index][cell_index].empty?
row_header[row_index][cell_index] << %(#{cell_halign}tB)
@@ -474,25 +474,18 @@
end
row_index += 1
end unless rows.empty?
end
- #row_header.each do |row|
- # result << LF
- # row.each_with_index do |cell, i|
- # result << (cell.join ' ')
- # result << ' ' if row.size > i + 1
- # end
- #end
- # FIXME temporary fix to get basic table to display
- result << LF
- result << ('lt ' * row_header[0].size).chop
-
- result << %(.#{LF})
- row_text.each do |row|
- result << row.join
+ if node.has_header_option && (header_row_text = row_text[0])
+ result << %(#{LF}#{row_header[0].join ' '}.)
+ result << %(#{LF}#{header_row_text.join})
+ result << '.T&'
+ row_text = row_text.slice 1, row_text.length
end
+ result << %(#{LF}#{row_header[0].map { 'lt' }.join ' '}.#{LF})
+ row_text.each {|row| result << row.join }
result << %(.TE#{LF}.sp)
result.join
end
def convert_thematic_break node
@@ -710,43 +703,41 @@
when :normalize
str = str.gsub WrappedIndentRx, LF
else
str = str.tr_s WHITESPACE, ' '
end
- str = str
- .gsub(LiteralBackslashRx) { $1 ? $& : '\\(rs' } # literal backslash (not a troff escape sequence)
- .gsub(EllipsisCharRefRx, '...') # horizontal ellipsis
- .gsub(LeadingPeriodRx, '\\\&.') # leading . is used in troff for macro call or other formatting; replace with \&.
- .gsub(EscapedMacroRx) do # drop orphaned \c escape lines, unescape troff macro, quote adjacent character, isolate macro line
- (rest = $3.lstrip).empty? ? %(.#{$1}"#{$2}") : %(.#{$1}"#{$2.rstrip}"#{LF}#{rest})
- end
- .gsub('-', '\-')
- .gsub('<', '<')
- .gsub('>', '>')
- .gsub('+', '+') # plus sign; alternately could use \c(pl
- .gsub(' ', '\~') # non-breaking space
- .gsub('©', '\(co') # copyright sign
- .gsub('®', '\(rg') # registered sign
- .gsub('™', '\(tm') # trademark sign
- .gsub('°', '\(de') # degree sign
- .gsub(' ', ' ') # thin space
- .gsub('–', '\(en') # en dash
- .gsub(EmDashCharRefRx, '\(em') # em dash
- .gsub('‘', '\(oq') # left single quotation mark
- .gsub('’', '\(cq') # right single quotation mark
- .gsub('“', '\(lq') # left double quotation mark
- .gsub('”', '\(rq') # right double quotation mark
- .gsub('←', '\(<-') # leftwards arrow
- .gsub('→', '\(->') # rightwards arrow
- .gsub('⇐', '\(lA') # leftwards double arrow
- .gsub('⇒', '\(rA') # rightwards double arrow
- .gsub('​', '\:') # zero width space
- .gsub('&', '&') # literal ampersand (NOTE must take place after any other replacement that includes &)
- .gsub('\'', '\*(Aq') # apostrophe / neutral single quote
- .gsub(MockMacroRx, '\1') # mock boundary
- .gsub(ESC_BS, '\\') # unescape troff backslash (NOTE update if more escapes are added)
- .gsub(ESC_FS, '.') # unescape full stop in troff commands (NOTE must take place after gsub(LeadingPeriodRx))
- .rstrip # strip trailing space
+ str = str.
+ gsub(LiteralBackslashRx) { $1 ? $& : '\\(rs' }. # literal backslash (not a troff escape sequence)
+ gsub(EllipsisCharRefRx, '...'). # horizontal ellipsis
+ gsub(LeadingPeriodRx, '\\\&.'). # leading . is used in troff for macro call or other formatting; replace with \&.
+ gsub(EscapedMacroRx) { (rest = $3.lstrip).empty? ? %(.#{$1}"#{$2}") : %(.#{$1}"#{$2.rstrip}"#{LF}#{rest}) }. # drop orphaned \c escape lines, unescape troff macro, quote adjacent character, isolate macro line
+ gsub('-', '\-').
+ gsub('<', '<').
+ gsub('>', '>').
+ gsub('+', '+'). # plus sign; alternately could use \c(pl
+ gsub(' ', '\~'). # non-breaking space
+ gsub('©', '\(co'). # copyright sign
+ gsub('®', '\(rg'). # registered sign
+ gsub('™', '\(tm'). # trademark sign
+ gsub('°', '\(de'). # degree sign
+ gsub(' ', ' '). # thin space
+ gsub('–', '\(en'). # en dash
+ gsub(EmDashCharRefRx, '\(em'). # em dash
+ gsub('‘', '\(oq'). # left single quotation mark
+ gsub('’', '\(cq'). # right single quotation mark
+ gsub('“', '\(lq'). # left double quotation mark
+ gsub('”', '\(rq'). # right double quotation mark
+ gsub('←', '\(<-'). # leftwards arrow
+ gsub('→', '\(->'). # rightwards arrow
+ gsub('⇐', '\(lA'). # leftwards double arrow
+ gsub('⇒', '\(rA'). # rightwards double arrow
+ gsub('​', '\:'). # zero width space
+ gsub('&', '&'). # literal ampersand (NOTE must take place after any other replacement that includes &)
+ gsub('\'', '\*(Aq'). # apostrophe / neutral single quote
+ gsub(MockMacroRx, '\1'). # mock boundary
+ gsub(ESC_BS, '\\'). # unescape troff backslash (NOTE update if more escapes are added)
+ gsub(ESC_FS, '.'). # unescape full stop in troff commands (NOTE must take place after gsub(LeadingPeriodRx))
+ rstrip # strip trailing space
opts[:append_newline] ? %(#{str}#{LF}) : str
end
def uppercase_pcdata string
(XMLMarkupRx.match? string) ? string.gsub(PCDATAFilterRx) { $2 ? $2.upcase : $1 } : string.upcase