Sha256: 456f2f808742b067a69a7dd96c6d56698b5c334b85a91328fd7017cb1dc1a0bb

Contents?: true

Size: 1.4 KB

Versions: 24

Compression:

Stored size: 1.4 KB

Contents

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

module IsoDoc
  class HeadlessHtmlConvert < ::IsoDoc::Convert
    include HtmlFunction::Comments
    include HtmlFunction::Footnotes
    include HtmlFunction::Html

    def tmpimagedir_suffix
      "_headlessimages"
    end

    def initialize(options)
      @format = :html
      @suffix = "headless.html"
      super
    end

    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

    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
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
isodoc-1.8.3.3 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.3.2 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.3.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.3 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.2.2 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.2.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.2 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.8.0 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.7 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.6.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.6 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.5 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.4 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.3.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.3 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.2 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.1 lib/isodoc/headlesshtml_convert.rb
isodoc-1.7.0 lib/isodoc/headlesshtml_convert.rb
isodoc-1.6.7.1 lib/isodoc/headlesshtml_convert.rb