require_relative "cleanup_ref"
require_relative "term_lookup_cleanup"
module Metanorma
module Ieee
class Converter < Standoc::Converter
def initial_boilerplate(xml, isodoc)
intro_boilerplate(xml, isodoc)
super if @document_scheme == "ieee-sa-2021"
xml.at("//boilerplate") or return
initial_note(xml)
word_usage(xml)
participants(xml)
footnote_boilerplate_renumber(xml)
end
def footnote_boilerplate_renumber(xml)
xml.xpath("//boilerplate//fn").each_with_index do |f, i|
f["reference"] = "_boilerplate_#{i + 1}"
end
end
def intro_boilerplate(xml, isodoc)
intro = xml.at("//introduction/title") or return
template = <<~ADM
This introduction is not part of P{{ docnumeric }}{% if draft %}/D{{ draft }}{% endif %}, {{ full_doctitle }}
ADM
adm = isodoc.populate_template(template)
intro.next = " #{@i18n.note_inform_fn}
See Footnote #{seen[content]}.
" else seen[content] = idx end fnote["reference"] = (idx - 1 + "a".ord).chr fnote["table"] = true [idx, seen] end def other_footnote_renumber1(fnote, idx, seen) fnote["table"] and return [idx, seen] content = footnote_content(fnote) idx += 1 if seen[content] fnote.children = "See Footnote #{seen[content]}.
" else seen[content] = idx end fnote["reference"] = idx.to_s [idx, seen] end TERM_CLAUSE = "//sections//terms".freeze def termdef_boilerplate_insert(xmldoc, isodoc, once = false) once = true super end def term_defs_boilerplate_cont(src, term, isodoc); end def termlookup_cleanup(xmldoc) Metanorma::Ieee::TermLookupCleanup.new(xmldoc, @log).call end def boilerplate_isodoc(xmldoc) x = xmldoc.dup x.root.add_namespace(nil, self.class::XML_NAMESPACE) xml = Nokogiri::XML(x.to_xml) i = isodoc(@lang, @script, @locale) i.bibdata_i18n(xml.at("//xmlns:bibdata")) i.info(xml, nil) i end PARTICIPANT_BOILERPLATE_LOCATIONS = { "boilerplate-participants-wg": "working group", "boilerplate-participants-bg": "balloting group", "boilerplate-participants-sb": "standards board", "boilerplate-participants-blank": nil }.freeze def participants(xml) @document_scheme == "ieee-sa-2021" or return PARTICIPANT_BOILERPLATE_LOCATIONS.each do |k, v| populate_participants(xml, k.to_s, v) end p = xml.at(".//p[@type = 'emeritus_sign']") ul = xml.at("//clause[@id = 'boilerplate-participants-sb']//ul") p && ul and ul.next = p xml.at("//sections//clause[@type = 'participants']")&.remove end def populate_participants(xml, target, subtitle) t = xml.at("//clause[@id = '#{target}']/membership") or return s = xml.xpath("//clause[@type = 'participants']/clause").detect do |x| n = x.at("./title") and n.text.strip.downcase == subtitle end t.replace(populate_participants1(s || t)) end def populate_participants1(clause) participants_dl_to_ul(clause) clause.xpath(".//ul | .//ol").each do |ul| ul.name = "ul" ul.xpath("./li").each { |li| populate_participants2(li) } ul.xpath(".//p[normalize-space() = '']").each(&:remove) end clause.at("./title")&.remove clause.children.to_xml end def participants_dl_to_ul(clause) clause.xpath(".//dl").each do |dl| dl.ancestors("dl, ul, ol").empty? or next dl.name = "ul" dl.xpath("./dt").each(&:remove) dl.xpath("./dd").each { |li| li.name = "li" } end end def populate_participants2(list) curr = list p = curr.at("./p[text() != '']") and curr = p if dl = curr.at("./dl") ret = extract_participants(dl) dl.children = ret.keys.map do |k| "#{ret[k]}
#{curr.children.to_xml}" \ "
member