Then /^the markup should be valid$/ do
  document = Nokogiri::XML(page.source)
  expect(document.errors).to be_empty
end

Then /^the markup should be valid$/ do
  tags = %w[header nav main details summary section footer]
  pattern = /\ATag (?:#{tags.join('|')}) invalid\z/
  filter = -> (error){ error.message =~ pattern }

  document = Nokogiri::HTML(page.source)
  expect(document.errors.reject(&filter)).to be_empty
end

Use HTML parser to validate document markup
Use HTML parser to validate document markup

As the status of polyglot markup is either deprecated or undefined it's
better to use a HTML parser to validate the markup. The issue is that it
seems that Nokogiri doesn't support any HTML5 tags so we need to filter
out the errors created by those. Adding the tags to Nokogiri directly
appears to be non-trivial.
