Module: Webgen::ContentProcessor::Xmllint

Defined in:
lib/webgen/content_processor/xmllint.rb

Overview

Uses the external xmllint program to check if the content is valid (X)HTML.

Class Method Summary collapse

Class Method Details

.call(context) ⇒ Object

Checks the content of context with the xmllint program for validness.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/webgen/content_processor/xmllint.rb', line 13

def self.call(context)
  Webgen::Utils::ExternalCommand.ensure_available!('xmllint', '--version')

  cmd = "xmllint #{context.website.config['content_processor.xmllint.options']} -"
  status, _stdout, stderr = systemu(cmd, 'stdin' => context.content)
  if status.exitstatus != 0
    stderr.scan(/^-:(\d+):(.*?\n)(.*?\n)/).each do |line, error_msg, line_context|
      context.website.logger.warn do
        "xmllint reported problems for <#{context.dest_node.alcn}:~#{line}>: #{error_msg.strip} (context: #{line_context.strip})"
      end
    end
  end
  context
end