Sha256: 6853fc52ac2e44de67cecabd211e233b071f111cf5420e2410f31a7fa4a9949e

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 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
            warn "#{x['id']}: mismatch of callouts and annotations"
          end
        end
      end

      def style_warning(node, msg, text = nil)
        return if @novalid
        w = "ISO style: WARNING (#{Utils::current_location(node)}): #{msg}"
        w += ": #{text}" if text
        warn 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.select { |n| n.name != "clause" }.empty?
          style_warning(c, "Hanging paragraph in clause")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
metanorma-standoc-1.3.20 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.3.19 lib/asciidoctor/standoc/validate_section.rb
metanorma-standoc-1.3.18 lib/asciidoctor/standoc/validate_section.rb