Skip to content

Commit a40cc07

Browse files
committed
[css2] Added check for HTML examples. TODO: check XML and CSS examples
--HG-- extra : convert_revision : svn%3A73dc7c4b-06e6-40f3-b4f7-9ed1dbc14bfc/trunk%40586
1 parent 57a364a commit a40cc07

4 files changed

Lines changed: 364 additions & 5 deletions

File tree

css2/DOC/CONVENTIONS

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,22 @@ Examples
174174
* In accordance with the HTML spec, use uppercase for
175175
HTML element names and lowercase for HTML attribute names.
176176

177+
* Markup CSS examples with the classes "example",
178+
"deprecated-example", "illegal-example".
179+
180+
* Markup HTML examples with the classes "html-example",
181+
"deprecated-html-example", "illegal-html-example".
182+
183+
* Markup XML examples with the classes "xml-example",
184+
"deprecated-xml-example", "illegal-xml-example".
185+
186+
177187
<div class="example"><P>
178188
<pre>
179189
...
180190
</pre>
181191
</div>
182192

183-
Deprecated examples should be as follows:
184193

185194
<div class="deprecated-example"><P>
186195
<span class="example-title">DEPRECATED EXAMPLE:</span><br>
@@ -189,8 +198,6 @@ Deprecated examples should be as follows:
189198
</pre>
190199
</div>
191200

192-
Illegal examples should be as follows:
193-
194201
<div class="illegal-example"><P>
195202
<span class="example-title">ILLEGAL EXAMPLE:</span><br>
196203
<pre>
@@ -248,7 +255,7 @@ Document HEAD
248255

249256
<!DOCTYPE HTML SYSTEM "http://www.w3.org/TR/WD-html40/sgml/HTML4.dtd">
250257
<html lang="en">
251-
<!-- $Id: CONVENTIONS,v 1.12 1997-12-09 00:08:30 ijacobs Exp $ -->
258+
<!-- $Id: CONVENTIONS,v 1.13 1997-12-29 21:10:48 ijacobs Exp $ -->
252259
<HEAD>
253260
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
254261
<TITLE>CSS2 Specification</TITLE>

css2/Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile to generate the CSS2 document based on its "source files"
22
# Arnaud Le Hors - lehors@w3.org
3-
# $Id: Makefile,v 1.61 1997-12-28 23:38:10 ijacobs Exp $
3+
# $Id: Makefile,v 1.62 1997-12-29 21:10:41 ijacobs Exp $
44

55
# what needs to be set for every new release:
66
THIS_VERSION= http://www.w3.org/Style/Group/9712/WD-css2-971211
@@ -119,6 +119,7 @@ PERL= perl5
119119
NSGMLS=nsgmls
120120
LINKLINT=$(PERL) bin/linklint
121121
SPELL = ispell -l -p
122+
DIFF = diff
122123

123124
# HTML include preprocessor (for includes)
124125
HIPP= $(PERL) ./bin/hipp
@@ -482,6 +483,25 @@ checkprops: $(SPECSRCS) $(PROPSRC) $(DESCSRC)
482483
-@$(CHKPROPS) $(DESCSRC) descinst $(SPECSRCS)
483484
-@echo "# End checking descriptors."
484485

486+
# Check examples (CSS, HTML, XML, etc.)
487+
488+
build/xamples.ok: $(SPECSRCS)
489+
@for i in $(SPECSRCS) ; \
490+
do $(PERL) bin/xextr $$i build; done;
491+
@touch build/xamples.ok
492+
493+
build/checkx.out: build/xamples.ok
494+
$(RM) build/checkx.out
495+
-@echo Begin checking HTML examples.
496+
-@for i in build/?*xampl*.html ; \
497+
do echo checking $$i...; \
498+
$(NSGMLS) -s -c sgml/HTML4.cat sgml/HTML4.decl $$i >> build/checkx.out 2>&1; \
499+
done;
500+
501+
checkx: build/checkx.out
502+
@$(DIFF) checkx.out build/checkx.out >build/checkx.diff \
503+
|| echo output differs, see build/checkx.diff for details.
504+
485505
# get cvs logs
486506

487507
FROMDATE=1 week ago

css2/bin/Attic/xextr

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#!/usr/local/bin/perl -w
2+
# Extract examples from an HTML document
3+
#
4+
# extract the content of the blocks:
5+
# <div class="example"> ... </div>
6+
# and put their contents into separate files
7+
#
8+
# Arnaud Le Hors - lehors@w3.org
9+
# $Id: xextr,v 1.1 1997-12-29 21:10:46 ijacobs Exp $
10+
11+
$PROGNAME = substr($0, rindex($0, "/") + 1);
12+
13+
if (!$ARGV[0]) {
14+
print "Usage: $PROGNAME file [tgt_dir]\n";
15+
exit 1;
16+
}
17+
18+
# copy file in memory
19+
if (!open(INPUT, $ARGV[0])) {
20+
print "$PROGNAME Error: Cannot open file: $ARGV[0]\n";
21+
exit 1;
22+
}
23+
$buf = "";
24+
while (<INPUT>) {
25+
$buf .= $_;
26+
}
27+
close(INPUT);
28+
29+
$path = "";
30+
if ($ARGV[1]) {
31+
$path = "$ARGV[1]";
32+
}
33+
34+
@paths = split(/\//, $ARGV[0]);
35+
$path .= "/" . $paths[$#paths] . "_xampl";
36+
37+
sub process_html_block {
38+
my ($file, $block, $deprecated) = @_;
39+
40+
# comment out undesired block
41+
$block =~ s/<em>(.*?)<\/em>/<!-- $1 -->/sigo;
42+
43+
# map characters
44+
$block =~ s/&lt;/</g;
45+
$block =~ s/&gt;/>/g;
46+
$block =~ s/&quot;/\"/g;
47+
$block =~ s/&copy;/(C)/g;
48+
$block =~ s/&amp;/\&/g;
49+
50+
# make sure it does form a complete document
51+
if (!($_ = $block, /<!doctype/i)) {
52+
if (($_ = $block, /frameset/i)) {
53+
$doctype =
54+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Frameset//EN\">";
55+
} elsif ($deprecated || ($_ = $block, /noframe|iframe/i)) {
56+
$doctype =
57+
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
58+
} else {
59+
$doctype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">";
60+
if (!($_ = $block, /<head>/i) &&
61+
(substr($block, 0, 1) ne "<" ||
62+
substr($block, 0, 2) eq "<!" ||
63+
substr($block, 0, 2) eq "<?")) {
64+
$block = "<p>\n$block";
65+
}
66+
}
67+
$block = "$doctype\n$block";
68+
}
69+
if (!($_ = $block, /<title>/i)) {
70+
if (!($_ = $block, /<head>/i)) {
71+
$block =~ s/<!doctype.*?>/$&\n<title>example<\/title>/i;
72+
} else {
73+
$block =~ s/<head>/<head>\n<title>example<\/title>/i;
74+
}
75+
}
76+
77+
# print file out
78+
print "\tHTML extracting$file\n";
79+
open(OUTPUT, "> $file") || die "failed to create $file\n";
80+
print OUTPUT $block;
81+
close(OUTPUT);
82+
}
83+
84+
sub process_xml_block {
85+
warn "XML extraction not implemented yet...\n";
86+
}
87+
88+
sub process_css_block {
89+
warn "CSS extraction not implemented yet...\n";
90+
}
91+
92+
93+
# Extract different types of blocks: css, html, xml.
94+
# If the type is "html" or "xml" at the DIV level,
95+
# assume that *all* pre elements within are "html" or
96+
# "xml" respectively. If the type is unknown,
97+
# assume css, but allow internal pre elements to
98+
# override this.
99+
100+
sub get_lang {
101+
$pattern =$_[0];
102+
if ( $pattern =~ /html/io ){
103+
return "html";
104+
} elsif ( $pattern =~ /xml/io ){
105+
return "xml";
106+
} else {
107+
return "css";
108+
}
109+
}
110+
111+
sub process_pre_block {
112+
($preclass, $preblock) = @_;
113+
$lang = get_lang($preclass);
114+
$output = "$path$num.$subnum.$lang";
115+
$deprecated = ($preclass =~ /deprecated/io) ? 1 : 0;
116+
if ($lang eq "html") {
117+
process_html_block("$output", $preblock, $deprecated);
118+
} elsif ($lang eq "xml") {
119+
process_xml_block("$output", $preblock, $deprecated);
120+
} elsif ($lang eq "css") {
121+
process_css_block("$output", $preblock, $deprecated);
122+
} else {
123+
warn "Unknown language $lang";
124+
}
125+
}
126+
127+
128+
129+
$preblockst = "(?:<pre>|(?:<pre\\s+class\\s*=\\s*\"?(example|deprecated-example|html-example|deprecated-html-example|xml-example|deprecated-xml-example)\"?\\s*>))\n?";
130+
$preblocket = "\n?<\/pre>";
131+
132+
# Arguments:
133+
# 0: DIV class value
134+
# 1: DIV content
135+
sub process_pre_blocks {
136+
($divclass, $divcontent) = @_;
137+
while ($divcontent =~ /$preblockst(.*?)$preblocket/iso) {
138+
$subnum++;
139+
process_pre_block(($1 || $divclass), $2);
140+
$divcontent = $'
141+
}
142+
}
143+
144+
$divblockst = "<(div|pre)\\s+class\\s*=\\s*\"?(example|deprecated-example|html-example|deprecated-html-example|xml-example|deprecated-xml-example)\"?\\s*>\n?";
145+
$divblocket = "\n?<\/\\1>";
146+
147+
$_ = $buf;
148+
$num = 0;
149+
$subnum = 0;
150+
151+
while (/$divblockst(.*?)$divblocket/iso) {
152+
$continue = $';
153+
$element = $1;
154+
$class = $2;
155+
$block = $3;
156+
$num++;
157+
$subnum = 0;
158+
# If DIV, process internal PRE blocks,
159+
# otherwise, process PRE block directly.
160+
if ($element =~ /div/io) {
161+
process_pre_blocks($class, $block);
162+
} else {
163+
process_pre_block($class, $block);
164+
}
165+
$_ = $continue;
166+
}

0 commit comments

Comments
 (0)