Module: RDoc::Generator::Mdoc::Helpers
- Included in:
- Formatter, RenderContext
- Defined in:
- lib/rdoc/generator/mdoc/helpers.rb
Overview
A module of helpers when outputting mdoc formatted text
Instance Method Summary collapse
-
#escape(string) ⇒ Object
Returns a new string where characters that mdoc percieve as special have been escaped.
-
#quote(string) ⇒ Object
Returns a new string enclosed in double quotes.
Instance Method Details
#escape(string) ⇒ Object
Returns a new string where characters that mdoc percieve as special have been escaped.
This is in line with the advice given in mdoc.samples(7):
> To remove the special meaning from a punctuation character escape it > with ‘&’. Troff is limited as a macro language, and has difficulty > when pre‐ sented with a string containing a member of the mathematical, > logical or quotation set: > > +,-,/,*,%,<,>,<=,>=,=,==,&,‘,’,“ > > The problem is that troff may assume it is supposed to actually perform > the operation or evaluation suggested by the characters. To prevent > the accidental evaluation of these characters, escape them with ‘&’. > Typical syntax is shown in the first content macro displayed below, > ‘.Ad’.
23 24 25 |
# File 'lib/rdoc/generator/mdoc/helpers.rb', line 23 def escape(string) string.to_s.gsub(%r|[+\-/*%<>=&`'"]|, '\\\&\0') end |
#quote(string) ⇒ Object
Returns a new string enclosed in double quotes.
29 30 31 |
# File 'lib/rdoc/generator/mdoc/helpers.rb', line 29 def quote(string) string.to_s.gsub(/^|$/, '"') end |