require "fileutils" require "base64" module IsoDoc::HtmlFunction module Html def make_body1(body, _docxml) body.div **{ class: "title-section" } do |div1| div1.p { |p| p << " " } # placeholder end section_break(body) end def make_body2(body, docxml) body.div **{ class: "prefatory-section" } do |div2| div2.p { |p| p << " " } # placeholder end section_break(body) end def make_body3(body, docxml) body.div **{ class: "main-section" } do |div3| abstract docxml, div3 foreword docxml, div3 introduction docxml, div3 middle docxml, div3 footnotes div3 comments div3 end end def postprocess(result, filename, dir) result = from_xhtml(cleanup(to_xhtml(result))) toHTML(result, filename) @files_to_delete.each { |f| FileUtils.rm_rf f } end def script_cdata(result) result.gsub(%r{}, ""). gsub(%r{]*)>}m, "\s*\]\]>}, "") end def toHTML(result, filename) result = (from_xhtml(html_cleanup(to_xhtml(result)))) result = populate_template(result, :html) result = from_xhtml(move_images(to_xhtml(result))) result = html5(script_cdata(inject_script(result))) File.open("#{filename}.html", "w:UTF-8") { |f| f.write(result) } end def html5(doc) doc.sub(%r{]+>}, ""). sub(%r{<\?xml[^>]+>}, "") end def html_cleanup(x) footnote_backlinks(html_toc( term_header((html_footnote_filter(html_preface(htmlstyle(x)))))) ) end MATHJAX_ADDR = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js".freeze MATHJAX = <<~"MATHJAX".freeze MATHJAX def mathjax(open, close) MATHJAX.gsub("OPEN", open).gsub("CLOSE", close) end def term_header(docxml) %w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h| docxml.xpath("//p[@class = 'TermNum'][../#{h}]").each do |p| p.name = "h#{h[1].to_i + 1}" end end docxml end def googlefonts() <<~HEAD.freeze HEAD end def html_head() <<~HEAD.freeze