Sha256: b0362240d3d2698da2ee7233527202fa1c3c7c00c3b74c52a01bd6be09f536bf

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

require "nokogiri"

module Asciidoctor
  module Standoc
    module Validate
      def section_validate(doc)
        sourcecode_style(doc.root)
        hanging_para_style(doc.root)
        asset_style(doc.root)
      end

      def sourcecode_style(root)
        root.xpath("//sourcecode").each do |x|
          callouts = x.elements.select { |e| e.name == "callout" }
          annotations = x.elements.select { |e| e.name == "annotation" }
          if callouts.size != annotations.size
        @log.add("AsciiDoc Input", x, "mismatch of callouts and annotations")
          end
        end
      end

      def style_warning(node, msg, text = nil)
        w = msg
        w += ": #{text}" if text
        @log.add("Metanorma XML Style Warning", node, w)
      end

      def asset_title_style(root)
        root.xpath("//figure[image][not(name)]").each do |node|
          style_warning(node, "Figure should have title", nil)
        end
        root.xpath("//table[not(name)]").each do |node|
          style_warning(node, "Table should have title", nil)
        end
      end

      def asset_style(root)
        asset_title_style(root)
      end

      def hanging_para_style(root)
        root.xpath("//clause | //annex | //foreword | //introduction | "\
                   "//acknowledgements").each do |c|
          next unless c.at("./clause")
          next if c.elements.reject { |n| %w(clause title).include? n.name }.empty?

          style_warning(c, "Hanging paragraph in clause")
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
metanorma-standoc-1.10.7 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.10.6 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.10.5 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.10.4.1 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.10.4 lib/asciidoctor/standoc/validate_section.rb