require_relative "base_convert" require_relative "init" require "isodoc" module IsoDoc module Iso class HtmlConvert < IsoDoc::HtmlConvert def initialize(options) @libdir = File.dirname(__FILE__) super end def googlefonts <<~HEAD.freeze HEAD end def default_fonts(options) { bodyfont: (if options[:script] == "Hans" '"Source Han Sans",serif' else options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif' end), headerfont: (if options[:script] == "Hans" '"Source Han Sans",sans-serif' else options[:alt] ? '"Lato",sans-serif' : '"Cambria",serif' end), monospacefont: (if options[:alt] '"Space Mono",monospace' else '"Courier New",monospace' end), normalfontsize: "1.0em", smallerfontsize: "0.9em", footnotefontsize: "0.9em", monospacefontsize: "0.8em", } end def default_file_locations(options) { htmlstylesheet: (if options[:alt] html_doc_path("style-human.scss") else html_doc_path("style-iso.scss") end), htmlcoverpage: html_doc_path("html_iso_titlepage.html"), htmlintropage: html_doc_path("html_iso_intro.html"), } end def footnote_reference_format(link) link.content += ")" end def html_toc_entry(level, header) content = header.at("./following-sibling::p" \ "[@class = 'variant-title-toc']") || header if level == "h1" && header.parent.name != "main" && header.parent.at(".//h2#{toc_exclude_class}") <<~HDR
  • #{header_strip(content)}
  • HDR else %(
  • \ #{header_strip(content)}
  • ) end end def html_toc(docxml) super docxml.xpath("//div[@id = 'toc']/ul[li[@class = 'h2']]").each do |u| html_toc1(u) end docxml end def middle(isoxml, out) middle_title(isoxml, out) middle_admonitions(isoxml, out) scope isoxml, out, 0 norm_ref isoxml, out, 0 clause_etc isoxml, out, 0 annex isoxml, out bibliography isoxml, out indexsect isoxml, out end def html_toc1(ulist) u2 = nil ulist.xpath("./li").each do |l| if l["class"] != "h2" u2 = nil elsif u2 then u2.add_child(l.remove) else u2 = l.replace("").first p = u2.previous_element and p << u2 end end end def inject_script(doc) scr = <<~HEAD.freeze HEAD a = super.split(%r{}) "#{a[0]}#{scr}#{a[1]}" end def table_th_center(docxml) docxml.xpath("//thead//th | //thead//td").each do |th| th["style"] += ";text-align:center;vertical-align:middle;" end end def ol_attrs(node) ret = super ret.merge(class: OL_STYLE.invert[ret[:type]]) end include BaseConvert include Init end end end