Module: RTeX::Escaping
- Included in:
- Document
- Defined in:
- lib/rtex/escaping.rb
Instance Method Summary collapse
-
#escape(text) ⇒ Object
Escape text using
replacements
. -
#replacements ⇒ Object
List of replacements.
Instance Method Details
#escape(text) ⇒ Object
Escape text using replacements
6 7 8 9 10 |
# File 'lib/rtex/escaping.rb', line 6 def escape(text) replacements.inject(text.to_s) do |corpus, (pattern, replacement)| corpus.gsub(pattern, replacement) end end |
#replacements ⇒ Object
List of replacements
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rtex/escaping.rb', line 13 def replacements @replacements ||= [ [/([{}])/, '\\\\\1'], [/\\/, '\textbackslash{}'], [/\^/, '\textasciicircum{}'], [/~/, '\textasciitilde{}'], [/\|/, '\textbar{}'], [/\</, '\textless{}'], [/\>/, '\textgreater{}'], [/([_$&%#])/, '\\\\\1'] ] end |