module Metanorma::Utils

def svgmap_rewrite1(s, svg, path)

def svgmap_rewrite1(s, svg, path)
  targets = s.xpath("./target").each_with_object({}) do |t, m|
    x = t.at("./xref") and m[t["href"]] = "##{x['target']}"
    x = t.at("./link") and m[t["href"]] = x['target']
    t.remove if t.at("./xref | ./link")
  end
  svg.xpath(".//xmlns:a").each do |a|
    x = targets[a["xlink:href"]] and a["xlink:href"] = x
  end
  File.open(path, "w", encoding: "utf-8") { |f| f.write(svg.to_xml) }
end