html-proofer 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile +0 -2
- data/README.md +27 -1
- data/lib/html/proofer.rb +1 -0
- data/lib/html/proofer/check_runner.rb +2 -1
- data/lib/html/proofer/checkable.rb +14 -6
- data/lib/html/proofer/checks/scripts.rb +1 -1
- data/lib/html/proofer/version.rb +1 -1
- data/spec/html/proofer/checkable_spec.rb +37 -1
- data/spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html +4 -0
- data/spec/html/proofer/scripts_spec.rb +6 -0
- data/spec/html/proofer_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5d2a78c7071f5534b4fb0d22c34337d9b92a6c
|
4
|
+
data.tar.gz: 4e89db1b52488116724d07608297d3abfb6581bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e99216d622692010d127c80f4cf4a128b5391535169418a9715d99f1d0ccdfcbe3edf976ee769ce2d5021b1989c6e232d00de72ae8574f82eb29b925a0e269
|
7
|
+
data.tar.gz: 57e675836bb4a138dcfd84a0751772bbd99d05d3605dc8c1f922197683fe92a65563f0618393720a5ed3f44101025977f94f2dbf7cba96161def098148ad98ce
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ If you generate HTML files, _then this tool might be for you_.
|
|
4
4
|
|
5
5
|
`HTML::Proofer` is a set of tests to validate your HTML output. These tests check if your image references are legitimate, if they have alt tags, if your internal links are working, and so on. It's intended to be an all-in-one checker for your output.
|
6
6
|
|
7
|
-
[![Build Status](https://travis-ci.org/gjtorikian/html-proofer.svg?branch=master)](https://travis-ci.org/gjtorikian/html-proofer) [![Gem Version](https://badge.fury.io/rb/html-proofer.svg)](http://badge.fury.io/rb/html-proofer)
|
7
|
+
[![Build Status](https://travis-ci.org/gjtorikian/html-proofer.svg?branch=master)](https://travis-ci.org/gjtorikian/html-proofer) [![Gem Version](https://badge.fury.io/rb/html-proofer.svg)](http://badge.fury.io/rb/html-proofer)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -149,6 +149,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
|
|
149
149
|
| `href_ignore` | An array of Strings or RegExps containing `href`s that are safe to ignore. Note that non-HTTP(S) URIs are always ignored. | `[]` |
|
150
150
|
| `href_swap` | A hash containing key-value pairs of `RegExp => String`. It transforms links that match `RegExp` into `String` via `gsub`. | `{}` |
|
151
151
|
| `only_4xx` | Only reports errors for links that fall within the 4xx status code range. | `false` |
|
152
|
+
| `url_ignore` | An array of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored. | `[]` |
|
152
153
|
| `check_favicon` | Enables the favicon checker. | `false` |
|
153
154
|
| `check_html` | Enables HTML validation errors from Nokogiri | `false` |
|
154
155
|
| `verbose` | If `true`, outputs extra information as the checking happens. Useful for debugging. | `false` |
|
@@ -237,3 +238,28 @@ class MailToOctocat < ::HTML::Proofer::CheckRunner
|
|
237
238
|
end
|
238
239
|
end
|
239
240
|
```
|
241
|
+
|
242
|
+
## Troubleshooting
|
243
|
+
|
244
|
+
### Certificates
|
245
|
+
|
246
|
+
To ignore certificates turn off the Typhoeus SSL verification:
|
247
|
+
|
248
|
+
``` ruby
|
249
|
+
HTML::Proofer.new("out/", {
|
250
|
+
:typhoeus => {
|
251
|
+
:ssl_verifypeer => false,
|
252
|
+
:ssl_verifyhost => 0}
|
253
|
+
}).run
|
254
|
+
```
|
255
|
+
|
256
|
+
### User-Agent
|
257
|
+
|
258
|
+
To change the User-Agent used by Typhoeus:
|
259
|
+
|
260
|
+
``` ruby
|
261
|
+
HTML::Proofer.new("out/", {
|
262
|
+
:typhoeus => {
|
263
|
+
:headers => { "User-Agent" => "Mozilla/5.0 (compatible; My New User-Agent)" }
|
264
|
+
}}).run
|
265
|
+
```
|
data/lib/html/proofer.rb
CHANGED
@@ -6,7 +6,7 @@ module HTML
|
|
6
6
|
class CheckRunner
|
7
7
|
|
8
8
|
attr_reader :issues, :src, :path, :options, :typhoeus_opts, :hydra_opts, :parallel_opts, \
|
9
|
-
:external_urls, :href_ignores, :alt_ignores, :empty_alt_ignore
|
9
|
+
:external_urls, :href_ignores, :url_ignores, :alt_ignores, :empty_alt_ignore
|
10
10
|
|
11
11
|
def initialize(src, path, html, options, typhoeus_opts, hydra_opts, parallel_opts)
|
12
12
|
@src = src
|
@@ -18,6 +18,7 @@ module HTML
|
|
18
18
|
@parallel_opts = parallel_opts
|
19
19
|
@issues = []
|
20
20
|
@href_ignores = @options[:href_ignore]
|
21
|
+
@url_ignores = @options[:url_ignore]
|
21
22
|
@alt_ignores = @options[:alt_ignore]
|
22
23
|
@empty_alt_ignore = @options[:empty_alt_ignore]
|
23
24
|
@external_urls = {}
|
@@ -13,7 +13,7 @@ module HTML
|
|
13
13
|
instance_variable_set("@#{attribute.tr('-:', '_')}".to_sym, value.value)
|
14
14
|
end
|
15
15
|
|
16
|
-
@
|
16
|
+
@text = obj.content
|
17
17
|
@check = check
|
18
18
|
@checked_paths = {}
|
19
19
|
@type = self.class.name
|
@@ -66,13 +66,21 @@ module HTML
|
|
66
66
|
def ignore?
|
67
67
|
return true if @data_proofer_ignore
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
# ignore base64 encoded images
|
70
|
+
if %w(ImageCheckable FaviconCheckable).include? @type
|
71
71
|
return true if url.match(/^data:image/)
|
72
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
# ignore user defined URLs
|
75
|
+
return true if ignores_pattern_check(@check.url_ignores)
|
76
|
+
|
77
|
+
# ignore user defined hrefs
|
78
|
+
if 'LinkCheckable' === @type
|
73
79
|
return true if ignores_pattern_check(@check.href_ignores)
|
74
|
-
|
75
|
-
|
80
|
+
end
|
81
|
+
|
82
|
+
# ignore user defined alts
|
83
|
+
if 'ImageCheckable' === @type
|
76
84
|
return true if ignores_pattern_check(@check.alt_ignores)
|
77
85
|
end
|
78
86
|
end
|
data/lib/html/proofer/version.rb
CHANGED
@@ -2,10 +2,46 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe HTML::Proofer::Checkable do
|
4
4
|
describe '#initialize' do
|
5
|
-
it 'accepts xmlns attribute' do
|
5
|
+
it 'accepts the xmlns attribute' do
|
6
6
|
nokogiri = Nokogiri::HTML '<a xmlns:cc="http://creativecommons.org/ns#">Creative Commons</a>'
|
7
7
|
checkable = HTML::Proofer::Checkable.new nokogiri.css('a').first, nil
|
8
8
|
expect(checkable.instance_variable_get(:@xmlns_cc)).to eq 'http://creativecommons.org/ns#'
|
9
9
|
end
|
10
|
+
it 'assignes the text node' do
|
11
|
+
nokogiri = Nokogiri::HTML '<p>One'
|
12
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('p').first, nil
|
13
|
+
expect(checkable.instance_variable_get(:@text)).to eq 'One'
|
14
|
+
end
|
15
|
+
it 'accepts the content attribute' do
|
16
|
+
nokogiri = Nokogiri::HTML '<meta name="twitter:card" content="summary">'
|
17
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('meta').first, nil
|
18
|
+
expect(checkable.instance_variable_get(:@content)).to eq 'summary'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe '#ignores_pattern_check' do
|
22
|
+
it 'works for regex patterns' do
|
23
|
+
nokogiri = Nokogiri::HTML '<script src=/assets/main.js></script>'
|
24
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('script').first, nil
|
25
|
+
expect(checkable.ignores_pattern_check([/\/assets\/.*(js|css|png|svg)/])).to eq true
|
26
|
+
end
|
27
|
+
it 'works for string patterns' do
|
28
|
+
nokogiri = Nokogiri::HTML '<script src=/assets/main.js></script>'
|
29
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('script').first, nil
|
30
|
+
expect(checkable.ignores_pattern_check(['/assets/main.js'])).to eq true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe '#url' do
|
34
|
+
it 'works for src attributes' do
|
35
|
+
nokogiri = Nokogiri::HTML '<img src=image.png />'
|
36
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('img').first, nil
|
37
|
+
expect(checkable.url).to eq 'image.png'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
describe '#ignore' do
|
41
|
+
it 'works for twitter cards' do
|
42
|
+
nokogiri = Nokogiri::HTML '<meta name="twitter:url" data-proofer-ignore content="http://example.com/soon-to-be-published-url">'
|
43
|
+
checkable = HTML::Proofer::Checkable.new nokogiri.css('meta').first, nil
|
44
|
+
expect(checkable.ignore?).to eq true
|
45
|
+
end
|
10
46
|
end
|
11
47
|
end
|
@@ -38,4 +38,10 @@ describe 'Scripts test' do
|
|
38
38
|
expect(proofer.failed_tests).to eq []
|
39
39
|
end
|
40
40
|
|
41
|
+
it 'ignores links via url_ignore' do
|
42
|
+
ignorableLinks = "#{FIXTURES_DIR}/scripts/ignorableLinksViaOptions.html"
|
43
|
+
proofer = run_proofer(ignorableLinks, { :url_ignore => [/\/assets\/.*(js|css|png|svg)/] })
|
44
|
+
expect(proofer.failed_tests).to eq []
|
45
|
+
end
|
46
|
+
|
41
47
|
end
|
data/spec/html/proofer_spec.rb
CHANGED
@@ -68,9 +68,9 @@ describe HTML::Proofer do
|
|
68
68
|
expect(output.strip).to eq('''
|
69
69
|
- -1
|
70
70
|
* spec/html/proofer/fixtures/sorting/status/broken_link.html: internally linking to nowhere.fooof, which does not exist (line 3)
|
71
|
-
-
|
72
|
-
* spec/html/proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed:
|
73
|
-
* spec/html/proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed:
|
71
|
+
- 301
|
72
|
+
* spec/html/proofer/fixtures/sorting/status/a_404.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/not_here.png failed: 301 No error
|
73
|
+
* spec/html/proofer/fixtures/sorting/status/broken_link.html: External link http://upload.wikimedia.org/wikipedia/en/thumb/fooooof.png failed: 301 No error
|
74
74
|
'''.strip)
|
75
75
|
end
|
76
76
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-proofer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|
@@ -302,6 +302,7 @@ files:
|
|
302
302
|
- spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg
|
303
303
|
- spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html
|
304
304
|
- spec/html/proofer/fixtures/resources/gpl.png
|
305
|
+
- spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html
|
305
306
|
- spec/html/proofer/fixtures/scripts/script.js
|
306
307
|
- spec/html/proofer/fixtures/scripts/script_broken_external.html
|
307
308
|
- spec/html/proofer/fixtures/scripts/script_content.html
|
@@ -459,6 +460,7 @@ test_files:
|
|
459
460
|
- spec/html/proofer/fixtures/resources/books/assets/version-control-with-git.jpg
|
460
461
|
- spec/html/proofer/fixtures/resources/books/nestedRelativeImages.html
|
461
462
|
- spec/html/proofer/fixtures/resources/gpl.png
|
463
|
+
- spec/html/proofer/fixtures/scripts/ignorableLinksViaOptions.html
|
462
464
|
- spec/html/proofer/fixtures/scripts/script.js
|
463
465
|
- spec/html/proofer/fixtures/scripts/script_broken_external.html
|
464
466
|
- spec/html/proofer/fixtures/scripts/script_content.html
|