require_relative "./image" module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert def lower2cap(text) return text if /^[[:upper:]][[:upper:]]/.match?(text) text.capitalize end def prefix_name(node, delim, number, elem) return if number.nil? || number.empty? unless name = node.at(ns("./#{elem}")) node.children.empty? and node.add_child("<#{elem}>#{elem}>") or node.children.first.previous = "<#{elem}>#{elem}>" name = node.children.first end if name.children.empty? then name.add_child(number) else (name.children.first.previous = "#{number}#{delim}") end end def sourcecode(docxml) docxml.xpath(ns("//sourcecode")).each do |f| sourcecode1(f) end end def sourcecode1(elem) return if labelled_ancestor(elem) return unless elem.ancestors("example").empty? lbl = @xrefs.anchor(elem["id"], :label, false) or return prefix_name(elem, " — ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name") end def formula(docxml) docxml.xpath(ns("//formula")).each do |f| formula1(f) end end # introduce name element def formula1(elem) lbl = @xrefs.anchor(elem["id"], :label, false) prefix_name(elem, "", lbl, "name") end def example(docxml) docxml.xpath(ns("//example")).each do |f| example1(f) end end def termexample(docxml) docxml.xpath(ns("//termexample")).each do |f| example1(f) end end def example1(elem) n = @xrefs.get[elem["id"]] lbl = if n.nil? || n[:label].nil? || n[:label].empty? @i18n.example else l10n("#{@i18n.example} #{n[:label]}") end prefix_name(elem, " — ", lbl, "name") end def note(docxml) docxml.xpath(ns("//note")).each do |f| note1(f) end end # introduce name element def note1(elem) return if elem.parent.name == "bibitem" n = @xrefs.get[elem["id"]] lbl = if n.nil? || n[:label].nil? || n[:label].empty? @i18n.note else l10n("#{@i18n.note} #{n[:label]}") end prefix_name(elem, "", lbl, "name") end def termnote(docxml) docxml.xpath(ns("//termnote")).each do |f| termnote1(f) end end # introduce name element def termnote1(elem) lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???") prefix_name(elem, "", lower2cap(lbl), "name") end def termdefinition(docxml) docxml.xpath(ns("//term[definition]")).each do |f| termdefinition1(f) end end def termdefinition1(elem) return unless elem.xpath(ns("./definition")).size > 1 d = elem.at(ns("./definition")) d = d.replace("