require_relative "init"
require "isodoc"
module IsoDoc
module NIST
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
def convert1(docxml, filename, dir)
info docxml, nil
insert_preface_sections(docxml)
super
end
def insert_preface_sections(docxml)
insert_keywords(docxml)
end
def wrap_brackets(txt)
return txt if /^\[.*\]$/.match txt
"[#{txt}]"
end
def get_linkend(node)
contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
return unless contents.empty?
link = anchor_linkend(node, docid_l10n(node["target"] || wrap_brackets(node['citeas'])))
link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link)
non_locality_elems(node).each { |n| n.remove }
node.add_child(link)
end
def annex1(f)
lbl = @xrefs.anchor(f['id'], :label)
if t = f.at(ns("./title"))
t.children = "#{t.children.to_xml}"
end
prefix_name(f, " — ", lbl, "title")
t = f.at(ns("./title"))
t["xref"] = lbl.gsub(/<[^>]+>/, "")
end
def keyword_clause(kw)
<<~END
#{@i18n.keywords}
#{@i18n.keywords_intro}
#{@i18n.l10n(kw.join("; "))}
END
end
def insert_keywords(docxml)
kw = @meta.get[:keywords]
kw.empty? and return
if abstract = docxml.at(ns("//preface/abstract"))
abstract.next = keyword_clause(kw)
elsif foreword = docxml.at(ns("//preface/foreword"))
foreword.next = keyword_clause(kw)
else
preface_init_insert_pt(docxml)&.children&.first&.add_previous_sibling(keyword_clause(kw))
end
end
def preface_init_insert_pt(docxml)
docxml.at(ns("//preface")) || docxml.at(ns("//sections")).add_previous_sibling(" ").first
end
def clause1(f)
return if f.name == "references" && suppress_biblio_title(f)
super
end
def references(docxml)
docxml.xpath(ns("//references/bibitem")).each do |x|
bibitem(x)
end
@xrefs.parse docxml
end
def bracket_if_num(x)
return nil if x.nil?
x = x.text.sub(/^\[/, "").sub(/\]$/, "")
"[#{x}]"
end
def bibitem(x)
if f = x.at(ns("./formattedref"))
code = render_identifier(bibitem_ref_code(x))
f << " [#{code[1]}] " if code[1]
else
x.children = ::Iso690Render.render(x.to_xml)
end
if id = x.at(ns("./docidentifier[@type = 'metanorma']"))
id["display"] = "true"
id.children = bracket_if_num(id)
end
end
include Init
end
end
end