module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert def docid_prefixes(docxml) docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i| i.children = docid_prefix(i["type"], to_xml(i.children)) end end =begin # This is highly specific to ISO, but it's not a bad precedent for # references anyway; keeping here instead of in IsoDoc::Iso for now def docid_l10n(text) text.nil? and return text @i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase) text.size < 20 and text.gsub!(/ /, " ") text end def docid_prefix(prefix, docid) docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) && !/^#{prefix}\b/.match(docid) docid_l10n(docid) end def omit_docid_prefix(prefix) prefix.nil? || prefix.empty? and return true %w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal) .include? prefix end =end def pref_ref_code(bib) bib["suppress_identifier"] == "true" and return nil ret = bib.xpath(ns("./docidentifier[@scope = 'biblio-tag']")) ret.empty? or return ret.map(&:text) ret = pref_ref_code_parse(bib) or return nil ins = bib.at(ns("./docidentifier[last()]")) ret.reverse_each do |r| ins.next = "#{docid_l10n(r)}" end ret end def pref_ref_code_parse(bib) data, = @bibrender.parse(bib) ret = data[:authoritative_identifier] or return nil ret.empty? and return nil ret end # returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers def bibitem_ref_code(bib) id, id1, id2, id3 = bibitem_ref_code_prep(bib) id || id1 || id2 || id3 and return [id, id1, id2, id3] bib["suppress_identifier"] == "true" and return [nil, nil, nil, nil] [nil, no_identifier(bib), nil, nil] end def bibitem_ref_code_prep(bib) id = bib.at(ns("./docidentifier[@type = 'metanorma']")) id1 = pref_ref_code(bib) id2 = bib.at(ns("./docidentifier[#{SKIP_DOCID}]")) id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']")) [id, id1, id2, id3] end def no_identifier(bib) @i18n.no_identifier or return nil id = Nokogiri::XML::Node.new("docidentifier", bib.document) id << @i18n.no_identifier id end def bracket_if_num(num) num.nil? and return nil num = num.text.sub(/^\[/, "").sub(/\]$/, "") /^\d+$/.match?(num) and return "[#{num}]" num end def unbracket1(ident) ident.nil? and return nil ident.is_a?(String) or ident = ident.text ident.sub(/^\[/, "").sub(/\]$/, "") end def unbracket(ident) if ident.respond_to?(:size) ident.map { |x| unbracket1(x) }.join(" / ") else unbracket1(ident) end end def render_identifier(ident) { metanorma: bracket_if_num(ident[0]), sdo: unbracket(ident[1]), doi: unbracket(ident[2]), ordinal: bracket_if_num(ident[3]) } end end end