3 # converts vim documentation to simple html
4 # Sirtaj Singh Kang (taj@kde.org)
6 # Sun Feb 24 14:49:17 CET 2002
9 use vars qw
/%url $date/;
18 if( exists $url{ $tag } ){
21 #warn "Unknown hyperlink target: $tag\n";
25 return "<code class=\"badlink\">$tag</code>";
32 my( $tag, $file, $name );
34 open(TAGS
,"$tagfile") || die "can't read tags\n";
37 next unless /^(\S+)\s+(\S+)\s+/;
41 ($file= $2) =~ s/.txt$/.html/g;
44 $url{ $tag } = "<a href=\"$file#".escurl
($tag)."\">".esctext
($label)."</a>";
77 open(IN
, "$infile" ) || die "Couldn't read from $infile: $!.\n";
79 ($outfile = $infile) =~ s
:.*/::g
;
80 $outfile =~ s/\.txt$//g;
82 open( OUT
, ">$outfile.html" )
83 || die "Couldn't write to $outfile.html: $!.\n";
84 my $head = uc( $outfile );
87 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
90 <title>VIM: $outfile</title>
91 <link rel="stylesheet" href="vim-stylesheet.css" type="text/css">
101 if ( /^\s*[-=]+\s*$/ ) {
102 print OUT
"</pre><hr><pre>";
107 elsif( /^>$/ || /\s>$/ ) {
111 elsif ( $inexample && /^([<\S])/ ) {
113 $_ = $' if $1 eq "<";
118 # Various vim highlights. note that < and > have already been escaped
119 # so that HTML doesn't get screwed up
.
122 # print "Text: $_\n";
124 foreach my $token ( split /((?:\|[^\|]+\|)|(?:\*[^\*]+\*))/ ) {
125 if ( $token =~ /^\|([^\|]+)\|/ ) {
127 push( @out, "|".maplink
( $1 )."|" );
130 elsif ( $token =~ /^\*([^\*]+)\*/ ) {
133 "<b class=\"vimtag\">\*<a name=\"".escurl
($1)."\">".esctext
($1)."<\/a>\*<\/b>");
137 $_ = esctext
($token);
138 s/CTRL-(\w+)/<code class="keystroke">CTRL-$1<\/code>/g
;
140 s/<(.*?)>/<code class="special"><$1><\/code>/g
;
143 s/\{([^}]*)\}/<code class="special">{$1}<\/code>/g
;
146 s/\[(range|line|count|offset|cmd|[-+]?num)\]/<code class="special">\[$1\]<\/code>/g
;
148 s/(Note:?)/<code class="note">$1<\/code>/gi
;
151 s/^(.*)\~$/<code class="section">$1<\/code>/g
;
155 $_ = join( "", @out );
157 if( $inexample == 2 ) {
158 print OUT
"<code class=\"example\">$_</code>\n";
163 $inexample = 2 if $inexample == 1;
167 <p><i>Generated by vim2html on $date</i></p>
177 vim2html.pl: converts vim documentation to HTML.
180 vim2html.pl <tag file> <text files>
187 open( CSS
, ">vim-stylesheet.css" ) || die "Couldn't write stylesheet: $!\n";
189 body { background-color: white; color: black;}
190 :link { color: rgb(0,137,139); }
191 :visited { color: rgb(0,100,100);
192 background-color: white; /* should be inherit */ }
193 :active { color: rgb(0,200,200);
194 background-color: white; /* should be inherit */ }
196 B.vimtag { color : rgb(250,0,250); }
198 h1, h2 { color: rgb(82,80,82); text-align: center; }
199 h3, h4, h5, h6 { color: rgb(82,80,82); }
200 .headline { color: rgb(0,137,139); }
201 .header { color: rgb(164, 32, 246); }
202 .section { color: rgb(164, 32, 246); }
203 .keystroke { color: rgb(106, 89, 205); }
205 .example { color: rgb(0, 0, 255); }
208 .special { color: rgb(106, 89, 205); }
209 .note { color: blue; background-color: yellow; }
211 .badlink { color: rgb(0,37,39); }
217 usage
() if $#ARGV < 2;
219 print "Processing tags...\n";
220 readTagFile
( $ARGV[ 0 ] );
222 foreach my $file ( 1..$#ARGV ) {
223 print "Processing ".$ARGV[ $file ]."...\n";
224 vim2html
( $ARGV[ $file ] );
226 print "Writing stylesheet...\n";