Class: Nanoc::Extra::Checking::Checks::HTML

Inherits:
Nanoc::Extra::Checking::Check show all
Defined in:
lib/nanoc/extra/checking/checks/html.rb

Instance Attribute Summary

Attributes inherited from Nanoc::Extra::Checking::Check

#issues, #site

Instance Method Summary (collapse)

Methods inherited from Nanoc::Extra::Checking::Check

#add_issue, #initialize, #output_filenames

Methods included from PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Constructor Details

This class inherits a constructor from Nanoc::Extra::Checking::Check

Instance Method Details

- (Object) run



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nanoc/extra/checking/checks/html.rb', line 7

def run
  require 'w3c_validators'

  Dir[site.config[:output_dir] + '/**/*.{htm,html}'].each do |filename|
    results = ::W3CValidators::MarkupValidator.new.validate_file(filename)
    lines = File.readlines(filename)
    results.errors.each do |e|
      line_num = e.line.to_i - 1
      line = lines[line_num]
      message = e.message.gsub(%r{\s+}, ' ').strip.sub(/\s+:$/, '')
      desc = "line #{line_num + 1}: #{message}: #{line}"
      add_issue(desc, subject: filename)
    end
  end
end