Class: Opmac2html::Converter

Inherits:
Object
  • Object
show all
Includes:
MacroParser, ParagraphParser, TextCutter
Defined in:
lib/opmac2html/converter.rb

Overview

Converter from OPmac to html markup

Constant Summary

Constants included from MacroParser

MacroParser::IN_PAR_MACROS, MacroParser::TITLES

Instance Method Summary collapse

Methods included from MacroParser

#build_table, #parse_image, #parse_label, #parse_list, #parse_list_items, #parse_macro, #parse_other, #parse_table, #parse_table_caption, #parse_table_cells, #parse_title, #parse_ttchar, #parse_verbatim, #process_list_item, #title_level, #verbinput, #verbinput_range

Methods included from ParagraphParser

#dump_all, #dump_to_space, #extract_from_braces, #par_macro, #par_special, #par_verbatim, #parse_clickable, #parse_code, #parse_fnote, #parse_format, #parse_format_block, #parse_link, #parse_math, #parse_par, #parse_par_macros, #parse_ulink, #parse_url

Methods included from TextCutter

#cut_at, #cut_at_match_with_start, #cut_at_matching, #cut_at_with_sep

Constructor Details

#initialize(input_file, output_file) ⇒ Converter

Returns a new instance of Converter.



17
18
19
20
21
22
23
24
# File 'lib/opmac2html/converter.rb', line 17

def initialize(input_file, output_file)
  @input = read_input input_file
  @preproc = Preprocessor.new
  @input = @preproc.run @input
  @builder = HtmlBuilder.new
  @output_file = output_file
  @ttchar = '"'
end

Instance Method Details

#convertObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/opmac2html/converter.rb', line 34

def convert
  until @input.empty?
    if @input.start_with? '%', "\n"
      cut_at "\n"
    else
      parse
    end
    @input.lstrip!
  end
  write_output @builder.to_s
end

#err(text) ⇒ Object



54
55
56
# File 'lib/opmac2html/converter.rb', line 54

def err(text)
  puts "Unsupported control sequence: #{text}"
end

#parseObject



46
47
48
49
50
51
52
# File 'lib/opmac2html/converter.rb', line 46

def parse
  if @input.start_with? '\\'
    parse_macro
  else
    parse_par
  end
end

#read_input(filename) ⇒ Object



26
27
28
# File 'lib/opmac2html/converter.rb', line 26

def read_input(filename)
  File.open(filename, 'r') { |input| input.readlines.join }
end

#write_output(output) ⇒ Object



30
31
32
# File 'lib/opmac2html/converter.rb', line 30

def write_output(output)
  File.open(@output_file, 'w') { |file| file << output }
end