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"
initial_note(xml)
word_usage(xml)
participants(xml)
xml.xpath("//dl[not(@id)]").each do |dl|
dl["id"] = "_#{UUIDTools::UUID.random_create}"
end
end
def intro_boilerplate(xml, isodoc)
return unless intro = xml.at("//introduction/title")
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) return [idx, seen] if fnote["table"] 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 def participants(xml) return unless @document_scheme == "ieee-sa-2021" { "boilerplate-participants-wg": "working group", "boilerplate-participants-bg": "balloting group", "boilerplate-participants-sb": "standards board" }.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("//clause[@type = 'participants']")&.remove end def populate_participants(xml, target, subtitle) t = xml.at("//clause[@id = '#{target}']/membership") 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| next unless dl.ancestors("dl, ul, ol").empty? 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") 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