Class: Opmac2html::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/opmac2html/preprocessor.rb

Overview

A preprocessor for HTML and TeX special characters

Constant Summary collapse

G_SUBST =
{ '<' => '&lt;', '>' => '&gt;', '&' => '&amp;' }
TEXT_SUBST =
{ '~' => '&nbsp;', '--' => '&ndash;', '---' => '&mdash',
'\\,' => '&#8239;', '\\-' => '', '\\TeX{}' => 'TeX',
'\\LaTeX{}' => 'LaTeX', '\\csplain{}' => 'CSplain' }
TS_REG =
Regexp.new('~|---?|([^\\\\][%].*)|^%.*|\s%.*|\\\\[,-]|' \
'\\\\(La)?TeX\{\}|\\\\csplain\{\}|^\{|\s\{|^\}|\s\}')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePreprocessor

Returns a new instance of Preprocessor.



14
15
16
# File 'lib/opmac2html/preprocessor.rb', line 14

def initialize
  @ttchar = '"'
end

Instance Attribute Details

#ttcharObject

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