Sha256: 2de1c40f620c8cfb11aaf2a58c6741b8ab9a2bef33bf9c822c1c99bcda0d49a4

Contents?: true

Size: 1.85 KB

Versions: 14

Compression:

Stored size: 1.85 KB

Contents

module Asciidoctor
  module Standoc
    module Cleanup
      def svgmap_cleanup(xmldoc)
        svgmap_moveattrs(xmldoc)
        svgmap_populate(xmldoc)
        Metanorma::Utils::svgmap_rewrite(xmldoc, @localdir)
      end

      def guid?(str)
        /^_[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
          .match(str)
      end

      def svgmap_moveattrs(xmldoc)
        xmldoc.xpath("//svgmap").each do |s|
          f = s.at(".//figure") or next
          if (t = s.at("./name")) && !f.at("./name")
            f.children.first.previous = t.remove
          end
          if s["id"] && guid?(f["id"])
            f["id"] = s["id"]
            s.delete("id")
          end
          svgmap_moveattrs1(s, f)
        end
      end

      def svgmap_moveattrs1(s, f)
        %w(unnumbered number subsequence keep-with-next
           keep-lines-together).each do |a|
          next if f[a] || !s[a]

          f[a] = s[a]
          s.delete(a)
        end
      end

      def svgmap_populate(xmldoc)
        xmldoc.xpath("//svgmap").each do |s|
          s1 = s.dup
          s.children.remove
          f = s1.at(".//figure") and s << f
          s1.xpath(".//li").each do |li|
            t = li&.at(".//eref | .//link | .//xref") or next
            href = t.xpath("./following-sibling::node()")
            href.empty? or
              s << %[<target href="#{svgmap_target(href)}">#{t.to_xml}</target>]
          end
        end
      end

      def svgmap_target(nodeset)
        nodeset.each do |n|
          next unless n.name == "link"

          n.children = n["target"]
        end
        nodeset.text.sub(/^[,; ]/, "").strip
      end

      def img_cleanup(xmldoc)
        return xmldoc unless @datauriimage

        xmldoc.xpath("//image").each do |i|
          i["src"] = Metanorma::Utils::datauri(i["src"], @localdir)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
metanorma-standoc-1.10.7 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.6 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.5 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.4.1 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.4 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.3.1 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.3 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.2 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.1 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.10.0 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.9.4 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.9.3 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.9.2 lib/asciidoctor/standoc/cleanup_image.rb
metanorma-standoc-1.9.1 lib/asciidoctor/standoc/cleanup_image.rb