lib/asciidoctor/itu/converter.rb in metanorma-itu-1.1.3 vs lib/asciidoctor/itu/converter.rb in metanorma-itu-1.2.0

- old
+ new

@@ -54,13 +54,16 @@ end def outputs(node, ret) File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) } presentation_xml_converter(node).convert(@filename + ".xml") - html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html") - doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc") - pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf") + html_converter(node).convert(@filename + ".presentation.xml", + nil, false, "#{@filename}.html") + doc_converter(node).convert(@filename + ".presentation.xml", + nil, false, "#{@filename}.doc") + pdf_converter(node)&.convert(@filename + ".presentation.xml", + nil, false, "#{@filename}.pdf") end def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), @@ -74,66 +77,43 @@ def sectiontype_streamline(ret) case ret when "definitions" then "terms and definitions" when "abbreviations and acronyms" then "symbols and abbreviated terms" when "references" then "normative references" + when "terms defined elsewhere" then "terms and definitions" + when "terms defined in this recommendation" then "terms and definitions" else super end end - def term_def_title(toplevel, node) - return node.title unless toplevel - "Definitions" - end - - def terms_extract(div) - internal = nil - external = nil - div.parent.xpath("./terms/title").each do |t| - case t&.text&.downcase - when "terms defined elsewhere" then external = t - when "terms defined in this recommendation" then internal = t - end + def term_def_subclause_parse(attrs, xml, node) + case clausetype = sectiontype1(node) + when "terms defined in this recommendation" + term_def_parse(attrs.merge(type: "internal"), xml, node, false) + when "terms defined elsewhere" + term_def_parse(attrs.merge(type: "external"), xml, node, false) + else + super end - [internal, external] end - def term_defs_boilerplate(div, source, term, preface, isodoc) - internal, external = terms_extract(div) - internal&.next_element&.name == "term" and - internal.next = "<p>#{@internal_terms_boilerplate}</p>" - internal and internal&.next_element == nil and - internal.next = "<p>#{@no_terms_boilerplate}</p>" - external&.next_element&.name == "term" and - external.next = "<p>#{@external_terms_boilerplate}</p>" - external and external&.next_element == nil and - external.next = "<p>#{@no_terms_boilerplate}</p>" - !internal and !external and - %w(term terms).include? div&.next_element&.name and - div.next = "<p>#{@term_def_boilerplate}</p>" - end - - def load_yaml(lang, script) - y = if @i18nyaml then YAML.load_file(@i18nyaml) - elsif lang == "en" - YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) - else - YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) - end - @symbols_boilerplate = y["symbols_boilerplate"] || "" - super.merge(y) - end - - def i18n_init(lang, script) - super - end - def metadata_keywords(node, xml) return unless node.attr("keywords") node.attr("keywords").split(/,[ ]*/).sort.each_with_index do |kw, i| xml.keyword (i == 0 ? kw.capitalize : kw) end + end + + def clause_parse(attrs, xml, node) + case clausetype = sectiontype1(node) + when "conventions" then attrs = attrs.merge(type: "conventions") + when "history" + attrs[:preface] and attrs = attrs.merge(type: "history") + when "source" + attrs[:preface] and attrs = attrs.merge(type: "source") + end + super end def html_extract_attributes(node) super.merge(hierarchical_assets: node.attr("hierarchical-object-numbering")) end