require_relative "cleanup_ref" module Asciidoctor module BSI class Converter < ISO::Converter def cleanup(xmldoc) super ol_cleanup(xmldoc) commentary_cleanup(xmldoc) xmldoc end def ol_cleanup(doc) doc.xpath("//clause[not(.//clause)] | //annex | //preface/* | //note") .each do |c| (c.xpath(".//ol") - c.xpath(".//ul//ol | .//ol//ol")) .each_with_index do |l, i| ol_cleanup1(l, i) end end end def ol_cleanup1(list, idx) styles = %w(alphabet arabic roman) list["type"] = styles[idx % styles.size] (list.xpath(".//ol") - list.xpath(".//ol//ol")).each do |l| ol_cleanup1(l, idx + 1) end end def commentary_cleanup(xmldoc) @isodoc ||= isodoc(@lang, @script) xmldoc.xpath("//admonition[@type = 'commentary'][not(@target)]") .each do |a| a["target"] = @isodoc.get_clause_id(a) end end def get_id_prefix(xmldoc) prefix = [] xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']"\ "/organization").each do |x| x1 = x.at("abbreviation")&.text || x.at("name")&.text x1 == "BSI" and prefix.unshift("BS") or prefix << x1 end prefix end # BS as a prefix goes first def docidentifier_cleanup(xmldoc) prefix = get_id_prefix(xmldoc) id = xmldoc.at("//bibdata/docidentifier[@type = 'BS']") or return id.content = id_prefix(prefix, id) id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and id.content = id_prefix(prefix, id) end def table_footnote_renumber1(fn, i, seen) content = footnote_content(fn) if seen[content] then outnum = seen[content] else i += 1 outnum = i seen[content] = outnum end fn["reference"] = (outnum - 1 + "A".ord).chr fn["table"] = true [i, seen] end # TODO: Rules for structure 10.5 amendments: # cite as BS 6380:2012+A1, reference as BS 6380:2012+A1:2016 # TODO: Rules for structure 16.5.2 wording of terms boilerplate: # "British Standard (part of BS..) end end end