From a98a6996c291b3e300d27b791eded9eed333d677 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 11 Jul 2014 04:05:51 +0000 Subject: re-integrate runtime/ vim-patch:0 #938 Vim runtime files based on 7.4.384 / hg changeset 7090d7f160f7 Excluding: Amiga icons (*.info, icons/) doc/hangulin.txt tutor/ spell/ lang/ (only used for menu translations) macros/maze/, macros/hanoi/, macros/life/, macros/urm/ These were used to test vi compatibility. termcap "Demonstration of a termcap file (for the Amiga and Archimedes)" Helped-by: Rich Wareham Helped-by: John Helped-by: Yann Helped-by: Christophe Badoit Helped-by: drasill Helped-by: Tae Sandoval Murgan Helped-by: Lowe Thiderman --- runtime/doc/vim2html.pl | 228 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 228 insertions(+) create mode 100644 runtime/doc/vim2html.pl (limited to 'runtime/doc/vim2html.pl') diff --git a/runtime/doc/vim2html.pl b/runtime/doc/vim2html.pl new file mode 100644 index 0000000000..9066b03b16 --- /dev/null +++ b/runtime/doc/vim2html.pl @@ -0,0 +1,228 @@ +#!/usr/bin/env perl + +# converts vim documentation to simple html +# Sirtaj Singh Kang (taj@kde.org) + +# Sun Feb 24 14:49:17 CET 2002 + +use strict; +use vars qw/%url $date/; + +%url = (); +$date = `date`; +chop $date; + +sub maplink +{ + my $tag = shift; + if( exists $url{ $tag } ){ + return $url{ $tag }; + } else { + #warn "Unknown hyperlink target: $tag\n"; + $tag =~ s/\.txt//; + $tag =~ s//>/g; + return "$tag"; + } +} + +sub readTagFile +{ + my($tagfile) = @_; + my( $tag, $file, $name ); + + open(TAGS,"$tagfile") || die "can't read tags\n"; + + while( ) { + next unless /^(\S+)\s+(\S+)\s+/; + + $tag = $1; + my $label = $tag; + ($file= $2) =~ s/.txt$/.html/g; + $label =~ s/\.txt//; + + $url{ $tag } = "".esctext($label).""; + } + close( TAGS ); +} + +sub esctext +{ + my $text = shift; + $text =~ s/&/&/g; + $text =~ s//>/g; + return $text; +} + +sub escurl +{ + my $url = shift; + $url =~ s/"/%22/g; + $url =~ s/~/%7E/g; + $url =~ s//%3E/g; + $url =~ s/=/%20/g; + $url =~ s/#/%23/g; + $url =~ s/\//%2F/g; + + return $url; +} + +sub vim2html +{ + my( $infile ) = @_; + my( $outfile ); + + open(IN, "$infile" ) || die "Couldn't read from $infile: $!.\n"; + + ($outfile = $infile) =~ s:.*/::g; + $outfile =~ s/\.txt$//g; + + open( OUT, ">$outfile.html" ) + || die "Couldn't write to $outfile.html: $!.\n"; + my $head = uc( $outfile ); + + print OUT< + + +VIM: $outfile + + + +

$head

+
+EOF
+
+	my $inexample = 0;
+	while(  ) {
+		chop;
+		if ( /^\s*[-=]+\s*$/ ) {
+			print OUT "

";
+			next;
+		}
+
+		# examples
+		elsif( /^>$/ || /\s>$/ ) {
+			$inexample = 1;
+			chop;
+		}
+		elsif ( $inexample && /^([<\S])/ ) {
+			$inexample = 0;
+			$_ = $' if $1 eq "<";
+		}
+
+		s/\s+$//g;
+
+		# Various vim highlights. note that < and > have already been escaped
+		# so that HTML doesn't get screwed up.
+
+		my @out = ();
+		#		print "Text: $_\n";
+		LOOP:
+		foreach my $token ( split /((?:\|[^\|]+\|)|(?:\*[^\*]+\*))/ ) {
+			if ( $token =~ /^\|([^\|]+)\|/ ) {
+				# link
+				push( @out, "|".maplink( $1 )."|" );
+				next LOOP;
+			}
+			elsif ( $token =~ /^\*([^\*]+)\*/ ) {
+				# target
+				push( @out,
+					"\*".esctext($1)."<\/a>\*<\/b>");
+				next LOOP;
+			}
+
+			$_ = esctext($token);
+			s/CTRL-(\w+)/CTRL-$1<\/code>/g;
+			# parameter <...>
+			s/<(.*?)>/<$1><\/code>/g;
+
+			# parameter {...}
+			s/\{([^}]*)\}/{$1}<\/code>/g;
+
+			# parameter [...]
+			s/\[(range|line|count|offset|cmd|[-+]?num)\]/\[$1\]<\/code>/g;
+			# note
+			s/(Note:?)/$1<\/code>/gi;
+
+			# local heading
+			s/^(.*)\~$/$1<\/code>/g;
+			push( @out, $_ );
+		}
+
+		$_ = join( "", @out );
+
+		if( $inexample == 2 ) {
+			print OUT "$_\n";
+		} else {
+			print OUT $_,"\n";
+		}
+
+		$inexample = 2 if $inexample == 1;
+	}
+	print OUT<
+

Generated by vim2html on $date

+ + +EOF + +} + +sub usage +{ +die< +EOF +} + + +sub writeCSS +{ + open( CSS, ">vim-stylesheet.css" ) || die "Couldn't write stylesheet: $!\n"; + print CSS<