Browse Source

Check images

renovate/configure
Yota Toyama 8 years ago
parent
commit
3b83424073
  1. 2
      examples/markdown.feature
  2. 24
      main.go

2
examples/markdown.feature

@ -92,4 +92,4 @@ Feature: Markdown
linkcheck -v foo.md 2>&1 | wc -l linkcheck -v foo.md 2>&1 | wc -l
""" """
When I successfully run `sh foo.sh` When I successfully run `sh foo.sh`
Then the stdout should contain exactly "2" Then the stdout should contain exactly "4"

24
main.go

@ -49,11 +49,21 @@ func extractURLs(n *html.Node) []string {
n := ns[i] n := ns[i]
ns = ns[:i] ns = ns[:i]
if n.Type == html.ElementNode && n.Data == "a" { if n.Type == html.ElementNode {
for _, a := range n.Attr { switch n.Data {
if a.Key == "href" && isURL(a.Val) { case "a":
ss[a.Val] = true for _, a := range n.Attr {
break if a.Key == "href" && isURL(a.Val) {
ss[a.Val] = true
break
}
}
case "img":
for _, a := range n.Attr {
if a.Key == "src" && isURL(a.Val) {
ss[a.Val] = true
break
}
} }
} }
} }
@ -74,10 +84,10 @@ func isURL(s string) bool {
func getArgs() map[string]interface{} { func getArgs() map[string]interface{} {
usage := `Link checker for Markdown and HTML usage := `Link checker for Markdown and HTML
Usage: Usage:
linkcheck [-v] <filenames>... linkcheck [-v] <filenames>...
Options: Options:
-v, --verbose Be verbose` -v, --verbose Be verbose`
args, err := docopt.Parse(usage, nil, true, "linkcheck", true) args, err := docopt.Parse(usage, nil, true, "linkcheck", true)

Loading…
Cancel
Save