lib/isodoc/presentation_function/block.rb in isodoc-1.5.3 vs lib/isodoc/presentation_function/block.rb in isodoc-1.5.4

- old
+ new

@@ -1,26 +1,32 @@ +require "base64" + module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert def lower2cap(s) return s if /^[[:upper:]][[:upper:]]/.match(s) s.capitalize end def figure(docxml) - docxml.xpath(ns("//figure")).each do |f| - figure1(f) - end + docxml.xpath(ns("//image")).each { |f| svg_extract(f) } + docxml.xpath(ns("//figure")).each { |f| figure1(f) } docxml.xpath(ns("//svgmap")).each do |s| if f = s.at(ns("./figure")) then s.replace(f) else s.remove end end end + def svg_extract(f) + return unless %r{^data:image/svg\+xml;base64,}.match(f["src"]) + svg = Base64.strict_decode64(f["src"].sub(%r{^data:image/svg\+xml;base64,}, "")) + f.replace(svg.sub(/<\?xml[^>]*>/, "")) + end + def figure1(f) - return sourcecode1(f) if f["class"] == "pseudocode" || - f["type"] == "pseudocode" + return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode" return if labelled_ancestor(f) && f.ancestors("figure").empty? return if f.at(ns("./figure")) and !f.at(ns("./name")) lbl = @xrefs.anchor(f['id'], :label, false) or return prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name") end