lib/md2man/roff.rb in md2man-2.0.3 vs lib/md2man/roff.rb in md2man-2.0.4
- old
+ new
@@ -40,11 +40,11 @@
def normal_paragraph text
"\n.PP\n#{text}\n"
end
def block_code code, language
- code = escape_backslashes(code)
+ code = escape(code, true)
block_quote "\n.nf\n#{code.chomp}\n.fi\n"
end
def block_quote quote
"\n.PP\n.RS\n#{remove_leading_pp(quote).chomp}\n.RE\n"
@@ -52,11 +52,11 @@
def block_html html
warn "md2man/roff: block_html not implemented: #{html.inspect}"
end
- def header text, level
+ def header text, level, _=nil
macro =
case level
when 1
if @h1_seen
:SH
@@ -159,11 +159,11 @@
def superscript text
warn "md2man/roff: superscript not implemented: #{text.inspect}"
end
def codespan code
- code = escape_backslashes(code)
+ code = escape(code, true)
# NOTE: this double font sequence gives us the best of both worlds:
# man(1) shows it in bold and `groff -Thtml` shows it in monospace
"\\fB\\fC#{code}\\fR"
end
@@ -195,21 +195,11 @@
#---------------------------------------------------------------------------
# low-level processing
#---------------------------------------------------------------------------
def normal_text text
- if text then text.
- # escape backslashes so that they appear in the printable output
- gsub('\\', '\\[rs]').
-
- # inhibit soft-hyphens so that they appear in the printable output
- gsub('-', '\\-').
-
- # inhibit line-beginning control characters (period and single-quote)
- # by prefixing a non-printable, zero-width glyph (backslash-ampersand)
- gsub(/^(?=[.'])/, '\\\\&')
- end
+ escape text, false if text
end
def entity text
if unicode = entity_to_unicode(text)
unicode_to_glyph unicode
@@ -218,11 +208,21 @@
end
end
private
- def escape_backslashes text
- text.gsub(/\\/, '\&\&')
+ def escape text, literally
+ if text then text.
+ # escape backslashes so that they appear in the printable output
+ gsub('\\', literally ? '\&\&' : '\\[rs]').
+
+ # escape soft-hyphens so that they appear in the printable output
+ gsub('-', '\\-').
+
+ # escape line-beginning control characters (period and single quote)
+ # by prefixing a non-printable, zero-width glyph (backslash ampersand)
+ gsub(/^(?=[.'])/, '\\\\&')
+ end
end
def remove_leading_pp text
text.sub(/\A\n\.PP\n/, '')
end