module Asciidoctor
module ITU
class Converter < Standoc::Converter
def sections_cleanup(x)
super
x.xpath("//*[@inline-header]").each do |h|
h.delete("inline-header")
end
insert_missing_sections(x) unless @no_insert_missing_sections
end
def table_cleanup(xmldoc)
super
xmldoc.xpath("//thead/tr[1]/th | //thead/tr[1]/td").each do |t|
text = t.at("./descendant::text()") or next
text.replace(text.text.titlecase)
end
end
def insert_missing_sections(x)
insert_scope(x)
insert_norm_ref(x)
insert_terms(x)
insert_symbols(x)
insert_conventions(x)
end
def insert_scope(x)
x.at("./*/sections") or
x.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
" "\
"#{@labels['clause_empty']} "\
"#{@labels['clause_empty']} "\
"#{@labels['clause_empty']} "\
"#{@labels['clause_empty']} "\
"#{@labels['clause_empty']}
#{@symbols_boilerplate}
" end PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze def pub_class(bib) return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ITU']") return 1 if bib.at("#{PUBLISHER}[name = 'International "\ "Telecommunication Union']") return 2 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']") return 2 if bib.at("#{PUBLISHER}[name = 'International Organization "\ "for Standardization']") return 3 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']") return 3 if bib.at("#{PUBLISHER}[name = 'International "\ "Electrotechnical Commission']") return 4 if bib.at("./docidentifier[@type][not(@type = 'DOI' or "\ "@type = 'metanorma' or @type = 'ISSN' or @type = "\ "'ISBN')]") 5 end def sort_biblio(bib) bib.sort do |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) end end # sort by: doc class (ITU, ISO, IEC, other standard (not DOI &c), other # then standard class (docid class other than DOI &c) # then alphanumeric doc id (not DOI &c) # then title def sort_biblio_key(bib) pubclass = pub_class(bib) num = bib&.at("./docnumber")&.text id = bib&.at("./docidentifier[not(@type = 'DOI' or @type = "\ "'metanorma' or @type = 'ISSN' or @type = 'ISBN')]") metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text abbrid = metaid unless /^\[\d+\]$/.match(metaid) type = id['type'] if id title = bib&.at("./title[@type = 'main']")&.text || bib&.at("./title")&.text || bib&.at("./formattedref")&.text "#{pubclass} :: #{type} :: #{id&.text || metaid} :: #{title}" end def biblio_reorder(xmldoc) xmldoc.xpath("//references").each do |r| biblio_reorder1(r) end end end end end