lib/asciidoctor/converter/manpage.rb in asciidoctor-1.5.4 vs lib/asciidoctor/converter/manpage.rb in asciidoctor-1.5.5
- old
+ new
@@ -12,10 +12,17 @@
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}])\\/
+ LeadingPeriodRx = /^\./
+ EscapedMacroRx = /^(?:#{ESC}\\c\n)?#{ESC}\.((?:URL|MTO) ".*?" ".*?" )( |[^\s]*)(.*?)(?: *#{ESC}\\c)?$/
+ MockBoundaryRx = /<\/?BOUNDARY>/
+ EmDashCharRefRx = /—(?:;​)?/
+ EllipsisCharRefRx = /…(?:​)?/
+
# Converts HTML entity references back to their original form, escapes
# special man characters and strips trailing whitespace.
#
# It's crucial that text only ever pass through manify once.
#
@@ -24,38 +31,36 @@
# * :preserve_space a Boolean that indicates whether to preserve spaces (only expanding tabs) if true
# or to collapse all adjacent whitespace to a single space if false (default: true)
# * :append_newline a Boolean that indicates whether to append an endline to the result (default: false)
def manify str, opts = {}
str = ((opts.fetch :preserve_space, true) ? (str.gsub TAB, ET) : (str.tr_s WHITESPACE, ' ')).
- gsub(/(?:\A|[^#{ESC}])\\/, '\&(rs'). # literal backslash (not a troff escape sequence)
- gsub(/^\./, '\\\&.'). # leading . is used in troff for macro call or other formatting; replace with \&.
+ gsub(LiteralBackslashRx, '\&(rs'). # literal backslash (not a troff escape sequence)
+ 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(/^(?:#{ESC}\\c\n)?#{ESC}\.((?:URL|MTO) ".*?" ".*?" )( |[^\s]*)(.*?)(?: *#{ESC}\\c)?$/) {
- (rest = $3.lstrip).empty? ? %(.#$1"#$2") : %(.#$1"#$2"#{LF}#{rest})
- }.
+ gsub(EscapedMacroRx) { (rest = $3.lstrip).empty? ? %(.#$1"#$2") : %(.#$1"#$2"#{LF}#{rest}) }.
gsub('-', '\-').
gsub('<', '<').
gsub('>', '>').
gsub(' ', '\~'). # non-breaking space
gsub('©', '\(co'). # copyright sign
gsub('®', '\(rg'). # registered sign
gsub('™', '\(tm'). # trademark sign
gsub(' ', ' '). # thin space
gsub('–', '\(en'). # en dash
- gsub(/—(?:;​)?/, '\(em'). # em 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(/…(?:​)?/, '...'). # horizontal ellipsis
+ 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('\'', '\(aq'). # apostrophe-quote
- gsub(/<\/?BOUNDARY>/, '').# artificial boundary
- gsub(ESC_BS, '\\'). # unescape troff backslash (NOTE update if more escaped are added)
+ gsub(MockBoundaryRx, ''). # mock boundary
+ gsub(ESC_BS, '\\'). # unescape troff backslash (NOTE update if more escapes are added)
rstrip # strip trailing space
opts[:append_newline] ? %(#{str}#{LF}) : str
end
def skip_with_warning node, name = nil