Sha256: 7456622e8c31d203e1aac0adca1ad746a7d337818b4e59f5c65a6799f3201db1

Contents?: true

Size: 1.25 KB

Versions: 36

Compression:

Stored size: 1.25 KB

Contents

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

module IsoDoc
  class HeadlessHtmlConvert < ::IsoDoc::Convert

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

    def tmpimagedir_suffix
      "_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)
      FileUtils.rm_rf dir
      strip_head(filename + ".tmp.html", outname_html + ".headless.html")
      FileUtils.rm_rf ["#{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

36 entries across 36 versions & 1 rubygems

Version Path
isodoc-1.0.25 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.24 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.23 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.22 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.21 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.20 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.19 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.18 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.17 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.16 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.15 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.14 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.13 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.12 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.11 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.10 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.9 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.8 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.7 lib/isodoc/headlesshtml_convert.rb
isodoc-1.0.6 lib/isodoc/headlesshtml_convert.rb