lib/asciidoctor/converter/manpage.rb in asciidoctor-2.0.10 vs lib/asciidoctor/converter/manpage.rb in asciidoctor-2.0.11
- old
+ new
@@ -13,11 +13,11 @@
ET = ' ' * 8
ESC = ?\u001b # troff leader marker
ESC_BS = %(#{ESC}\\) # escaped backslash (indicates troff formatting sequence)
ESC_FS = %(#{ESC}.) # escaped full stop (indicates troff macro)
- LiteralBackslashRx = /(?:\A|[^#{ESC}])\\/
+ LiteralBackslashRx = /\A\\|(#{ESC})?\\/
LeadingPeriodRx = /^\./
EscapedMacroRx = /^(?:#{ESC}\\c\n)?#{ESC}\.((?:URL|MTO) "#{CC_ANY}*?" "#{CC_ANY}*?" )( |[^\s]*)(#{CC_ANY}*?)(?: *#{ESC}\\c)?$/
MockBoundaryRx = /<\/?BOUNDARY>/
EmDashCharRefRx = /—(?:​)?/
EllipsisCharRefRx = /…(?:​)?/
@@ -245,11 +245,13 @@
.B #{manify node.captioned_title}
.br) if node.title?
result << %(.sp
.if n .RS 4
.nf
+.fam C
#{manify node.content, whitespace: :preserve}
+.fam
.fi
.if n .RE)
result.join LF
end
@@ -259,11 +261,13 @@
.B #{manify node.title}
.br) if node.title?
result << %(.sp
.if n .RS 4
.nf
+.fam C
#{manify node.content, whitespace: :preserve}
+.fam
.fi
.if n .RE)
result.join LF
end
@@ -282,19 +286,20 @@
result = []
result << %(.sp
.B #{manify node.title}
.br) if node.title?
+ start = (node.attr 'start', 1).to_i
node.items.each_with_index do |item, idx|
result << %(.sp
.RS 4
.ie n \\{\\
-\\h'-04' #{idx + 1}.\\h'+01'\\c
+\\h'-04' #{numeral = idx + start}.\\h'+01'\\c
.\\}
.el \\{\\
. sp -1
-. IP " #{idx + 1}." 4.2
+. IP " #{numeral}." 4.2
.\\}
#{manify item.text, whitespace: :normalize})
result << item.content if item.blocks?
result << '.RE'
end
@@ -578,15 +583,11 @@
target = target.sub '@', %[#{ESC_BS}(at] if macro == 'MTO'
%(#{ESC_BS}c#{LF}#{ESC_FS}#{macro} "#{target}" "#{text}" )
when :xref
unless (text = node.text)
refid = node.attributes['refid']
- if AbstractNode === (ref = (@refs ||= node.document.catalog[:refs])[refid])
- text = (ref.xreftext node.attr('xrefstyle', nil, true)) || %([#{refid}])
- else
- text = %([#{refid}])
- end
+ text = %([#{refid}]) unless AbstractNode === (ref = (@refs ||= node.document.catalog[:refs])[refid]) && (@resolving_xref ||= outer = true) && outer && (text = ref.xreftext node.attr 'xrefstyle', nil, true)
end
text
when :ref, :bibref
# These are anchor points, which shouldn't be visible
''
@@ -697,11 +698,12 @@
str = str.gsub WrappedIndentRx, LF
else
str = str.tr_s WHITESPACE, ' '
end
str = str.
- gsub(LiteralBackslashRx, '\&(rs'). # literal backslash (not a troff escape sequence)
+ 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 \&.
# drop orphaned \c escape lines, unescape troff macro, quote adjacent character, isolate macro line
gsub(EscapedMacroRx) { (rest = $3.lstrip).empty? ? %(.#$1"#$2") : %(.#$1"#$2"#{LF}#{rest}) }.
gsub('-', '\-').
gsub('<', '<').
@@ -715,16 +717,15 @@
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(EllipsisCharRefRx, '...'). # horizontal ellipsis
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('&', '&'). # literal ampersand (NOTE must take place after any other replacement that includes &)
gsub('\'', '\(aq'). # apostrophe-quote
gsub(MockBoundaryRx, ''). # 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