module Webgen::ContentProcessor::Xmllint

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

Public Class Methods

call(context) click to toggle source

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

# File lib/webgen/content_processor/xmllint.rb, line 12
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