require "isodoc" module Asciidoctor module M3d # A {Converter} implementation that generates M3D output, and a document # schema encapsulation of the document for validation class M3dConvert < IsoDoc::Convert def initialize(options) super set_metadata(:status, "XXX") end def init_metadata super end def title(isoxml, _out) main = isoxml&.at(ns("//title[@language='en']"))&.text set_metadata(:doctitle, main) end def subtitle(_isoxml, _out) nil end def author(isoxml, _out) set_metadata(:tc, "XXXX") tc = isoxml.at(ns("//editorialgroup/technical-committee")) set_metadata(:tc, tc.text) if tc end def docid(isoxml, _out) docnumber = isoxml.at(ns("//bibdata/docidentifier")) docstatus = isoxml.at(ns("//bibdata/status")) dn = docnumber&.text if docstatus set_metadata(:status, status_print(docstatus.text)) abbr = status_abbr(docstatus.text) dn = "#{dn}(#{abbr})" unless abbr.empty? end set_metadata(:docnumber, dn) end def status_print(status) status.split(/-/).map{ |w| w.capitalize }.join(" ") end def status_abbr(status) case status when "working-draft" then "wd" when "committee-draft" then "cd" when "draft-standard" then "d" else "" end end def pre_parse(node, out) out.pre node.text # content.gsub(//, ">") end def term_defs_boilerplate(div, source, term) if source.empty? && term.nil? div << @no_terms_boilerplate else div << term_defs_boilerplate_cont(source, term) end end def i18n_init(lang, script) super @annex_lbl = "Appendix" end def error_parse(node, out) # catch elements not defined in ISO case node.name when "pre" pre_parse(node, out) when "keyword" out.span node.text, **{ class: "keyword" } else super end end HEAD = <<~HEAD.freeze HEAD BUTTON = ''.freeze def html_main(docxml) d = docxml.at('//div[@class="WordSection3"]') s = d.replace("
") s.first.children = d s.first.children.first.previous = BUTTON end def html_preface(docxml) super docxml.at("//head").add_child(HEAD) html_main(docxml) docxml end def make_body(xml, docxml) body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72", "xml:lang": "EN-US", class: "container" } xml.body **body_attr do |body| make_body1(body, docxml) make_body2(body, docxml) make_body3(body, docxml) end end def html_toc(docxml) docxml end end end end