File: html.rb

package info (click to toggle)
ruby-html-proofer 3.19.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,040 kB
  • sloc: ruby: 3,203; sh: 9; makefile: 4; javascript: 1; php: 1
file content (37 lines) | stat: -rw-r--r-- 1,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

class HtmlCheck < ::HTMLProofer::Check
  # tags embedded in scripts are used in templating languages: http://git.io/vOovv
  SCRIPT_EMBEDS_MSG = /Element script embeds close tag/.freeze
  INVALID_TAG_MSG = /Tag ([\w\-:]+) invalid/.freeze
  INVALID_PREFIX = /Namespace prefix/.freeze
  PARSE_ENTITY_REF = /htmlParseEntityRef: no name/.freeze
  DOCTYPE_MSG = /Expected a doctype token/.freeze
  EOF_IN_TAG = /End of input in tag/.freeze
  MISMATCHED_TAGS = /That tag isn't allowed here/.freeze

  def run
    @html.errors.each do |error|
      add_issue(error.message, line: error.line) if report?(error.message)
    end
  end

  def report?(message)
    case message
    when SCRIPT_EMBEDS_MSG
      options[:validation][:report_script_embeds]
    when INVALID_TAG_MSG, INVALID_PREFIX
      options[:validation][:report_invalid_tags]
    when PARSE_ENTITY_REF
      options[:validation][:report_missing_names]
    when DOCTYPE_MSG
      options[:validation][:report_missing_doctype]
    when EOF_IN_TAG
      options[:validation][:report_eof_tags]
    when MISMATCHED_TAGS
      options[:validation][:report_mismatched_tags]
    else
      true
    end
  end
end