#!/usr/local/bin/perl -w
#Add special markup to document
#- Add keyword "Example:" before examples for non-CSS UAs
# $id$
# Ian Jacobs (ij@w3.org)

use DB_File;
use lib 'bin';
use utils;
use English;

$PROG = substr($0, rindex($0, "/") + 1);
$USAGE = "Usage: $PROG input [output]\n";

if ($#ARGV >= 0) {$input = $ARGV[0]; shift;} else {die $USAGE;}
if ($#ARGV >= 0) {$output = $ARGV[0]; shift;} else {$output = '-';}
if ($#ARGV >= 0) {die $USAGE;}

#Copy file in memory
$buf = readfile($input);

$attrs = "\\s+class\\s*=\\s*\"?example\"?";
$buf =~ s/<div$attrs>/$&<P style="display:none">Example(s):<\/P>/sgio;
$attrs = "\\s+class\\s*=\\s*\"?illegal-example\"?";
$buf =~ s/<div$attrs>/$&<P style="display:none">Illegal example(s):<\/P>/sgio;

open(OUTPUT, "> $output") || die "Cannot open for output: $output\n";
print OUTPUT $buf;
close(OUTPUT);
