class IsoDoc::HeadlessHtmlConvert

Public Class Methods

new(options) click to toggle source
Calls superclass method IsoDoc::Convert::new
# File lib/isodoc/headlesshtml_convert.rb, line 16
def initialize(options)
  @format = :html
  @suffix = "headless.html"
  super
end

Public Instance Methods

convert(input_filename, file = nil, debug = false, output_filename = nil) click to toggle source
# File lib/isodoc/headlesshtml_convert.rb, line 22
def convert(input_filename, file = nil, debug = false, output_filename = nil)
  file = File.read(input_filename, encoding: "utf-8") if file.nil?
  @openmathdelim, @closemathdelim = extract_delims(file)
  docxml, filename, dir = convert_init(file, input_filename, debug)
  result = convert1(docxml, filename, dir)
  return result if debug

  postprocess(result, "#{filename}.tmp.html", dir)
  FileUtils.rm_rf dir
  strip_head("#{filename}.tmp.html",
             output_filename || "#{filename}.#{@suffix}")
  FileUtils.rm_rf ["#{filename}.tmp.html", tmpimagedir]
end
strip_head(input, output) click to toggle source
# File lib/isodoc/headlesshtml_convert.rb, line 36
def strip_head(input, output)
  file = File.read(input, encoding: "utf-8")
  doc = Nokogiri::XML(file)
  doc.xpath("//head").each(&:remove)
  doc.xpath("//html").each { |x| x.name = "div" }
  body = doc.at("//body")
  body.replace(body.children)
  File.open(output, "w") { |f| f.write(doc.to_xml) }
end
tmpimagedir_suffix() click to toggle source
# File lib/isodoc/headlesshtml_convert.rb, line 12
def tmpimagedir_suffix
  "_headlessimages"
end