lib/metanorma/collection_fileprocess.rb in metanorma-1.2.6pre vs lib/metanorma/collection_fileprocess.rb in metanorma-1.2.6

- old
+ new

@@ -1,8 +1,9 @@ # frozen_string_literal: true require "isodoc" +require "metanorma-utils" module Metanorma # XML collection renderer class CollectionRenderer # hash for each document in collection of document identifier to: @@ -129,13 +130,34 @@ def update_xrefs(file, identifier, internal_refs) docxml = Nokogiri::XML(file) update_indirect_refs_to_docs(docxml, internal_refs) add_document_suffix(identifier, docxml) update_direct_refs_to_docs(docxml, identifier) + svgmap_resolve(datauri_encode(docxml)) docxml.xpath(ns("//references[not(./bibitem[not(@hidden) or @hidden = 'false'])]")).each do |f| f["hidden"] = "true" end docxml.to_xml + end + + def datauri_encode(docxml) + docxml.xpath(ns("//image")).each { |i| i["src"] = Metanorma::Utils::datauri(i["src"]) } + docxml + end + + def svgmap_resolve(docxml) + isodoc = IsoDoc::Convert.new({}) + docxml.xpath(ns("//svgmap//eref")).each do |e| + href = isodoc.eref_target(e) + next if href == "#" + e["bibitemid"] + if href.match(/^#/) + next unless docxml.at("//*[@id = '#{href.sub(/^#/, '')}']") + end + e["target"] = href.strip + e.name = "link" + e&.elements&.remove + end + Metanorma::Utils::svgmap_rewrite(docxml, "") end # repo(current-metanorma-collection/ISO 17301-1:2016) # replaced by bibdata of "ISO 17301-1:2016" in situ as bibitem. # Any erefs to that bibitem id are replaced with relative URL