module Metanorma
module ITU
class Converter < Standoc::Converter
def sections_cleanup(xml)
super
insert_missing_sections(xml) unless @no_insert_missing_sections
insert_empty_clauses(xml)
resolution_inline_header(xml)
end
def resolution_inline_header(xml)
@doctype == "resolution" or return
xml.xpath("//clause//clause").each do |c|
(title = c.at("./title")) && !title.text&.empty? and next
c["inline-header"] = true
end
end
def insert_missing_sections(xml)
xml.at("//metanorma-extension/semantic-metadata/" \
"headless[text() = 'true']") and return nil
insert_scope(xml)
insert_norm_ref(xml)
insert_terms(xml)
insert_symbols(xml)
insert_conventions(xml)
end
def add_id
%(id="_#{UUIDTools::UUID.random_create}")
end
def insert_scope(xml)
xml.at("./*/sections") or
xml.at("./*/preface | ./*/boilerplate | ./*/bibdata").next =
" " \
"#{@i18n.clause_empty} " \
"#{@i18n.clause_empty}
#{text}
" end def termdef_boilerplate_cleanup(xmldoc); end def terms_extract(div) internal = div.at("./terms[@type = 'internal']/title") external = div.at("./terms[@type = 'external']/title") [internal, external] end def term_defs_boilerplate(div, _source, _term, _preface, _isodoc) internal, external = terms_extract(div.parent) internal&.next_element&.name == "term" and internal.next = "#{@i18n.internal_terms_boilerplate}
" internal and internal&.next_element == nil and internal.next = "#{@i18n.no_terms_boilerplate}
" external&.next_element&.name == "term" and external.next = "#{@i18n.external_terms_boilerplate}
" external and external&.next_element == nil and external.next = "#{@i18n.no_terms_boilerplate}
" !internal and !external and %w(term terms).include? div&.next_element&.name and div.next = "#{@i18n.term_def_boilerplate}
" end def section_names_terms_cleanup(xml) super replace_title( xml, "//terms[@type = 'internal'] | " \ "//clause[./terms[@type = 'internal']]" \ "[not(./terms[@type = 'external'])]", @i18n&.internal_termsdef ) replace_title( xml, "//terms[@type = 'external'] | " \ "//clause[./terms[@type = 'external']]" \ "[not(./terms[@type = 'internal'])]", @i18n&.external_termsdef ) end def symbols_cleanup(xmldoc) sym = xmldoc.at("//definitions/title") sym and sym&.next_element&.name == "dl" and sym.next = "#{@i18n.symbols_boilerplate}
" end def sections_names_pref_cleanup(xml) super t = xml.at("//preface//abstract") or return t["id"] == "_summary" and replace_title(xml, "//preface//abstract", @i18n&.summary) end end end end