Browse Source

Ignore id links

renovate/configure
Yota Toyama 8 years ago
parent
commit
88d7f672b8
  1. 18
      examples/html.feature
  2. 5
      file_checker.go
  3. 2
      file_checker_test.go

18
examples/html.feature

@ -22,3 +22,21 @@ Feature: HTML
"""
When I successfully run `liche foo.html`
Then the stderr should contain exactly ""
Scenario: Ignore id reference
Given a file named "foo.html" with:
"""
<!DOCTYPE html>
<html>
<head>
<title>My title</title>
</head>
<body>
<div id="foo">
<a href="#foo">Google</a>
</div>
</body>
</html>
"""
When I successfully run `liche foo.html`
Then the stderr should contain exactly ""

5
file_checker.go

@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"net/url"
"strings"
"sync"
"time"
@ -118,6 +119,10 @@ func extractURLs(n *html.Node) []string {
}
func isURL(s string) bool {
if strings.HasPrefix(s, "#") {
return false
}
u, err := url.Parse(s)
return err == nil && (u.Scheme == "" || u.Scheme == "http" || u.Scheme == "https")
}

2
file_checker_test.go

@ -53,7 +53,7 @@ func TestIsURL(t *testing.T) {
assert.True(t, isURL(s))
}
for _, s := range []string{"ftp://foo.com", "file://file-path"} {
for _, s := range []string{"ftp://foo.com", "file://file-path", "#foo"} {
assert.False(t, isURL(s))
}
}

Loading…
Cancel
Save