File: w3html

package info (click to toggle)
surfraw 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,624 kB
  • sloc: sh: 7,977; perl: 824; makefile: 277
file content (117 lines) | stat: -rwxr-xr-x 4,190 bytes parent folder | download | duplicates (3)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
# $Id$
# elvis: w3html		-- Validate a web page URL with the w3c validator (validator.w3.org)
# ianb@erislabs.net 20040906
. surfraw || exit 1

w3_config_hook () {
def    SURFRAW_w3html_encoding "%28detect+automatically%29"
def    SURFRAW_w3html_doctype  "Inline"
defyn  SURFRAW_w3html_verbose             1
defyn  SURFRAW_w3html_encodingfallback    0
defyn  SURFRAW_w3html_doctypefallback     0
defyn  SURFRAW_w3html_showsource          0
defyn  SURFRAW_w3html_showparsetree       0
defyn  SURFRAW_w3html_showoutline         0
defyn  SURFRAW_w3html_excludeattributes   0
defyn  SURFRAW_w3html_validateerror       0
defyn  SURFRAW_w3html_usage               0
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [URL]
Description:
  Validate a web page URL with the w3c validator (validator.w3.org)
Local options:
  -usage                        Go to help page for validator.
  -encoding=ENCODING            Set page encoding.
                                Default: autodetect
                                Environment: SURFRAW_w3html_encoding
  -encfb                        Fall back to encoding rather than override.
                                Environment: SURFRAW_w3html_encodingfallback
  -doctype="DOCTYPE"            Set page doctype.
                                Default: SURFRAW_w3html_doctype
  -docfb                        Fall back to doctype rather than override.
                                Environment: SURFRAW_w3html_doctypefallback
  -nv                           Be less verbose.
                                Environment: SURFRAW_w3html_verbose
  -showsource                   Show page source.
                                Environment: SURFRAW_w3html_showsource
  -showoutline                  Show page outline (headings)
                                Environment: SURFRAW_w3html_showoutline
  -showparsetree                Show parse tree.
                                Environment: SURFRAW_w3html_showparsetree
  -excludeatt                   Exclude attributes from parse tree.
                                Environment: SURFRAW_w3html_excludeattributes
  -err                          Validate Error (404) pages.
                                Environment: SURFRAW_w3html_validateerror
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -enco*=*)   setopt    SURFRAW_w3html_encoding `w3_url_escape "$optarg"` ;;
	-docty*=*)  setopt    SURFRAW_w3html_doctype  `w3_url_escape "$optarg"` ;;
	-encfb)     setoptyn  SURFRAW_w3html_encodingfallback    1 ;;
	-docfb)     setoptyn  SURFRAW_w3html_doctypefallback     1 ;;
	-shows*)    setoptyn  SURFRAW_w3html_showsource          1 ;;
	-showp*)    setoptyn  SURFRAW_w3html_showparsetree       1 ;;
	-showo*)    setoptyn  SURFRAW_w3html_showoutline         1 ;;
	-exc*)      setoptyn  SURFRAW_w3html_excludeattributes   1 ;;
	-err*)      setoptyn  SURFRAW_w3html_validateerror       1 ;;
	-nv*)       setoptyn  SURFRAW_w3html_verbose             0 ;;
	-us*)       setoptyn  SURFRAW_w3html_usage               1 ;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if [ $SURFRAW_w3html_usage -eq 1 ]; then
	w3_browse_url "https://validator.w3.org/docs/users.html#Options"
elif test -z "$w3_args"; then
    w3_browse_url "https://validator.w3.org/"
else
    escaped_args=`w3_url_of_arg $w3_args`
	url="https://validator.w3.org/check?uri=${escaped_args}&charset=${SURFRAW_w3html_encoding}&doctype=${SURFRAW_w3html_doctype}"
	if [ $SURFRAW_w3html_encodingfallback -eq 1 ]
	then
		url="${url}&fbc=1"
	fi
	if [ $SURFRAW_w3html_doctypefallback -eq 1 ]
	then
		url="${url}&fbd=1"
	fi
	if [ $SURFRAW_w3html_showsource -eq 1 ]
	then
		url="${url}&ss=1"
	fi
	if [ $SURFRAW_w3html_showparsetree -eq 1 ]
	then
		url="${url}&sp=1"
	fi
	if [ $SURFRAW_w3html_showoutline -eq 1 ]
	then
		url="${url}&outline=1"
	fi
	if [ $SURFRAW_w3html_excludeattributes -eq 1 ]
	then
		url="${url}&noatt=1"
	fi
	if [ $SURFRAW_w3html_validateerror -eq 1 ]
	then
		url="${url}&No200=1"
	fi
	if [ $SURFRAW_w3html_verbose -eq 1 ]
	then
		url="${url}&verbose=1"
	fi

	w3_browse_url "${url}"
fi