Class: Opmac2html::Preprocessor
- Inherits:
-
Object
- Object
- Opmac2html::Preprocessor
- Defined in:
- lib/opmac2html/preprocessor.rb
Overview
A preprocessor for HTML and TeX special characters
Constant Summary collapse
- G_SUBST =
{ '<' => '<', '>' => '>', '&' => '&' }
- TEXT_SUBST =
{ '~' => ' ', '--' => '–', '---' => '&mdash', '\\,' => ' ', '\\-' => '', '\\TeX{}' => 'TeX', '\\LaTeX{}' => 'LaTeX', '\\csplain{}' => 'CSplain' }
- TS_REG =
Regexp.new('~|---?|([^\\\\][%].*)|^%.*|\s%.*|\\\\[,-]|' \ '\\\\(La)?TeX\{\}|\\\\csplain\{\}|^\{|\s\{|^\}|\s\}')
Instance Attribute Summary collapse
-
#ttchar ⇒ Object
Returns the value of attribute ttchar.
Instance Method Summary collapse
-
#initialize ⇒ Preprocessor
constructor
A new instance of Preprocessor.
- #process_text(text) ⇒ Object
- #run(text) ⇒ Object
Constructor Details
#initialize ⇒ Preprocessor
Returns a new instance of Preprocessor.
14 15 16 |
# File 'lib/opmac2html/preprocessor.rb', line 14 def initialize @ttchar = '"' end |
Instance Attribute Details
#ttchar ⇒ Object
Returns the value of attribute ttchar.
4 5 6 |
# File 'lib/opmac2html/preprocessor.rb', line 4 def ttchar @ttchar end |
Instance Method Details
#process_text(text) ⇒ Object
22 23 24 |
# File 'lib/opmac2html/preprocessor.rb', line 22 def process_text(text) text.gsub(TS_REG) { |c| TEXT_SUBST[c] } end |
#run(text) ⇒ Object
18 19 20 |
# File 'lib/opmac2html/preprocessor.rb', line 18 def run(text) text.gsub(/[<>&]/) { |c| G_SUBST[c] } end |