Class: HTML2AsciiMath::Converter
- Inherits:
-
Object
- Object
- HTML2AsciiMath::Converter
- Defined in:
- lib/html2asciimath/converter.rb
Overview
This class is responsible for converting HTML math expressions to AsciiMath.
It runs two small parsers: first HTMLparser deals with HTML syntax, and then HTMLTextParser processes textual content found between HTML elements. Thanks to this two-phase processing, HTMLTextParser receives input which is already decoded (i.e. without any HTML entities), which in turn allows to keep its grammar simple.
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#ast_stack ⇒ Object
readonly
Returns the value of attribute ast_stack.
-
#html_parser ⇒ Object
readonly
Returns the value of attribute html_parser.
-
#variable_mode ⇒ Object
Returns the value of attribute variable_mode.
Instance Method Summary collapse
- #close_group ⇒ Object
-
#initialize(str) ⇒ Converter
constructor
A new instance of Converter.
- #open_group ⇒ Object
- #parse ⇒ Object
- #push(*objs) ⇒ Object
- #to_asciimath ⇒ Object
- #transform ⇒ Object
Constructor Details
#initialize(str) ⇒ Converter
Returns a new instance of Converter.
21 22 23 |
# File 'lib/html2asciimath/converter.rb', line 21 def initialize(str) @html_parser = HTMLParser.new(str, self) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
18 19 20 |
# File 'lib/html2asciimath/converter.rb', line 18 def ast @ast end |
#ast_stack ⇒ Object (readonly)
Returns the value of attribute ast_stack.
18 19 20 |
# File 'lib/html2asciimath/converter.rb', line 18 def ast_stack @ast_stack end |
#html_parser ⇒ Object (readonly)
Returns the value of attribute html_parser.
18 19 20 |
# File 'lib/html2asciimath/converter.rb', line 18 def html_parser @html_parser end |
#variable_mode ⇒ Object
Returns the value of attribute variable_mode.
19 20 21 |
# File 'lib/html2asciimath/converter.rb', line 19 def variable_mode @variable_mode end |
Instance Method Details
#close_group ⇒ Object
33 34 35 |
# File 'lib/html2asciimath/converter.rb', line 33 def close_group push ast_stack.pop end |
#open_group ⇒ Object
29 30 31 |
# File 'lib/html2asciimath/converter.rb', line 29 def open_group ast_stack.push AST.new end |
#parse ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/html2asciimath/converter.rb', line 46 def parse return if @ast @ast = AST.new @ast_stack = [@ast] @variable_mode = false html_parser.parse end |
#push(*objs) ⇒ Object
37 38 39 |
# File 'lib/html2asciimath/converter.rb', line 37 def push(*objs) ast_stack.last.push(*objs) end |
#to_asciimath ⇒ Object
41 42 43 44 |
# File 'lib/html2asciimath/converter.rb', line 41 def to_asciimath parse ast.to_asciimath end |
#transform ⇒ Object
25 26 27 |
# File 'lib/html2asciimath/converter.rb', line 25 def transform to_asciimath end |