Sha256: 9989a27b129af7381ed3c43036d15331b035e649f5153fad9586ae7a2d6ea1ae

Contents?: true

Size: 962 Bytes

Versions: 6

Compression:

Stored size: 962 Bytes

Contents

module Metanorma
  module Standoc
    module Validate
      def repeat_id_validate1(elem)
        if @doc_ids[elem["id"]]
          @log.add("Anchors", elem, "Anchor #{elem['id']} has already been " \
                                    "used at line #{@doc_ids[elem['id']]}")
          @fatalerror << "Multiple instances of same ID: #{elem['id']}"
        end
        @doc_ids[elem["id"]] = elem.line
      end

      def repeat_id_validate(doc)
        @doc_ids = {}
        doc.xpath("//*[@id]").each do |x|
          repeat_id_validate1(x)
        end
      end

      # manually check for xref/@target, xref/@to integrity
      def xref_validate(doc)
        @doc_xrefs = doc.xpath("//xref/@target | //xref/@to")
          .each_with_object({}) do |x, m|
          m[x.text] = x
          @doc_ids[x.text] and next
          @log.add("Anchors", x.parent,
                   "Crossreference target #{x} is undefined")
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metanorma-standoc-2.4.8 lib/metanorma/standoc/validate_xref.rb
metanorma-standoc-2.4.7 lib/metanorma/standoc/validate_xref.rb
metanorma-standoc-2.4.6 lib/metanorma/standoc/validate_xref.rb
metanorma-standoc-2.4.5 lib/metanorma/standoc/validate_xref.rb
metanorma-standoc-2.4.4 lib/metanorma/standoc/validate_xref.rb
metanorma-standoc-2.4.3 lib/metanorma/standoc/validate_xref.rb