Sha256: e21f0d8834f86fb95b574b0d72ec7bd652f3a35325340bdacf86e23dac1965eb

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

require_relative "html_function/comments.rb"
require_relative "html_function/footnotes.rb"
require_relative "html_function/html.rb"

module IsoDoc
  class HeadlessHtmlConvert < ::IsoDoc::Convert

    include HtmlFunction::Comments
    include HtmlFunction::Footnotes
    include HtmlFunction::Html

    def initialize(options)
      super
      @tmpimagedir = "_headlessimages"
    end

    def convert(filename, file = nil, debug = false)
      file = File.read(filename, encoding: "utf-8") if file.nil?
      @openmathdelim, @closemathdelim = extract_delims(file)
      docxml, outname_html, dir = convert_init(file, filename, debug)
      result = convert1(docxml, outname_html, dir)
      return result if debug
      postprocess(result, filename + ".tmp", dir)
      system "rm -fr #{dir}"
      strip_head(filename + ".tmp.html", outname_html + ".headless.html")
      system "rm -r #{filename + '.tmp.html'} #{@tmpimagedir}"
    end

    def strip_head(input, output)
      file = File.read(input, encoding: "utf-8")
      doc = Nokogiri::XML(file)
      doc.xpath("//head").each { |x| x.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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
isodoc-0.9.0 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.13 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.11 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.10 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.9 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.8 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.7 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.6 lib/isodoc/headlesshtml_convert.rb
isodoc-0.8.5 lib/isodoc/headlesshtml_convert.rb