class Opmac2html::HtmlBuilder

Builder for the resulting document

Constants

MATH_JAX
TAIL

Attributes

anchors[R]

Public Class Methods

new() click to toggle source
# File lib/opmac2html/html_builder.rb, line 17
def initialize
  @document = []
  @fnotes = ListBuilder.new 'n'
  @fnote_count = 0
  @anchors = []
end

Public Instance Methods

add_anchor(id) click to toggle source
# File lib/opmac2html/html_builder.rb, line 77
def add_anchor(id)
  @anchors << id
  @document << ["span id=\"#{id}\"", '']
end
add_figure(filename, caption) click to toggle source
# File lib/opmac2html/html_builder.rb, line 70
def add_figure(filename, caption)
  img = "<img src=\"#{filename}\" " \
      "alt=\"#{caption}\">"
  cap = "<figcaption>#{caption}</figcaption>"
  @document << ['figure', img + "\n" + cap]
end
add_fnote(text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 58
def add_fnote(text)
  @fnote_count += 1
  @fnotes.add_item(text, @fnote_count.to_s)
  @fnote_count
end
add_img(filename) click to toggle source
# File lib/opmac2html/html_builder.rb, line 64
def add_img(filename)
  elem = "<img src=\"#{filename}\" " \
       "alt=\"#{filename[0...filename.rindex('.')]}\">\n"
  @document << [nil, elem]
end
add_list(text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 54
def add_list(text)
  @document << [nil, text]
end
add_par(text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 42
def add_par(text)
  @document << ['p', text]
end
add_table(text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 50
def add_table(text)
  @document << ['table', text]
end
add_title(title) click to toggle source
# File lib/opmac2html/html_builder.rb, line 37
def add_title(title)
  @title ||= title[1]
  @document << [title[0], title[1]]
end
add_verbatim(text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 46
def add_verbatim(text)
  @document << ['pre', text]
end
doc_to_s() click to toggle source
# File lib/opmac2html/html_builder.rb, line 86
def doc_to_s
  @document.map do |e|
    if header?(e)
      header(*e)
    elsif !e[0]
      e[1]
    else
      elem(*e)
    end
  end.join + "<hr>\n" + @fnotes.to_s
end
elem(name, text) click to toggle source
# File lib/opmac2html/html_builder.rb, line 29
def elem(name, text)
  "<#{name}>#{text}</#{name.partition(' ')[0]}>\n\n"
end
head(title) click to toggle source
# File lib/opmac2html/html_builder.rb, line 24
def head(title)
  "<!DOCTYPE html>\n<head>\n<title>#{title}</title>\n" \
    "#{MATH_JAX}\n</head>\n<body>\n"
end
header(number, title) click to toggle source
# File lib/opmac2html/html_builder.rb, line 33
def header(number, title)
  elem "h#{number}", title
end
header?(element) click to toggle source
# File lib/opmac2html/html_builder.rb, line 82
def header?(element)
  element[0].is_a? Numeric
end
to_s() click to toggle source
# File lib/opmac2html/html_builder.rb, line 98
def to_s
  head(@title) + doc_to_s + TAIL
end