module Metanorma module Standoc module Cleanup def bibdata_cleanup(xmldoc) bibdata_anchor_cleanup(xmldoc) bibdata_docidentifier_cleanup(xmldoc) bibdata_embed_hdr_cleanup(xmldoc) # feeds bibdata_embed_id_cleanup bibdata_embed_id_cleanup(xmldoc) biblio_indirect_erefs(xmldoc, @internal_eref_namespaces&.uniq) end def bibdata_anchor_cleanup(xmldoc) xmldoc.xpath("//bibdata//bibitem | //bibdata//note").each do |b| b.delete("id") end end def bibdata_docidentifier_cleanup(xmldoc) ins = xmldoc.at("//bibdata/docidentifier") xmldoc.xpath("//bibdata/docidentifier").each_with_index do |b, i| i.zero? and next ins.next = b.remove ins = ins.next end end def gather_indirect_erefs(xmldoc, prefix) xmldoc.xpath("//eref[@type = '#{prefix}']") .each_with_object({}) do |e, m| e.delete("type") m[e["bibitemid"]] = true end.keys end def insert_indirect_biblio(xmldoc, refs, prefix) i = xmldoc.at("bibliography") or xmldoc.root << "" and i = xmldoc.at("bibliography") i = i.add_child("