Mercurial > vim
annotate runtime/doc/vim2html.pl @ 34674:bfd2c0032686 v9.1.0218
patch 9.1.0218: Unnecessary multiplications in backspace code
Commit: https://github.com/vim/vim/commit/8ede7a069419e0e01368c65a2d0c79d6332aa6cd
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu Mar 28 10:30:08 2024 +0100
patch 9.1.0218: Unnecessary multiplications in backspace code
Problem: Unnecessary multiplications in backspace code, as
"col / ts * ts" is the same as "col - col % ts".
Solution: Change "col / ts * ts" to "col - col % ts". Adjust the loop
and the comments ins_bs() to be easier to understand. Update
tests to reset 'smarttab' properly.
(zeertzjq)
closes: #14308
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Mar 2024 10:45:04 +0100 |
parents | e09acb1daea7 |
children |
rev | line source |
---|---|
7 | 1 #!/usr/bin/env perl |
2 | |
3 # converts vim documentation to simple html | |
4 # Sirtaj Singh Kang (taj@kde.org) | |
5 | |
6 # Sun Feb 24 14:49:17 CET 2002 | |
7 | |
8 use strict; | |
33712
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
9 use warnings; |
7 | 10 use vars qw/%url $date/; |
11 | |
12 %url = (); | |
33712
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
13 # 30.11.23, Restorer: |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
14 # This command does not work in OS Windows. |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
15 # The "date" command in Windows is different from its counterpart in UNIX-like systems. |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
16 # The closest analog is the "date /t" command, but how it would work in UNIX, |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
17 # I don't know. I've corrected it as best I can. I don't know Perl. |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
18 #$date = `date`; |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
19 #chop $date; |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
20 my ($year) = 1900 + (localtime())[5]; |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
21 my ($month) = 1 + (localtime())[4]; |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
22 my ($day) = (localtime())[3]; |
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
23 #$date = localtime(); # outputs like this Fri Nov 3 00:56:59 2023 |
7 | 24 |
25 sub maplink | |
26 { | |
27 my $tag = shift; | |
28 if( exists $url{ $tag } ){ | |
29 return $url{ $tag }; | |
30 } else { | |
31 #warn "Unknown hyperlink target: $tag\n"; | |
32 $tag =~ s/\.txt//; | |
33 $tag =~ s/</</g; | |
34 $tag =~ s/>/>/g; | |
35 return "<code class=\"badlink\">$tag</code>"; | |
36 } | |
37 } | |
38 | |
39 sub readTagFile | |
40 { | |
41 my($tagfile) = @_; | |
42 my( $tag, $file, $name ); | |
43 | |
44 open(TAGS,"$tagfile") || die "can't read tags\n"; | |
45 | |
46 while( <TAGS> ) { | |
47 next unless /^(\S+)\s+(\S+)\s+/; | |
48 | |
49 $tag = $1; | |
50 my $label = $tag; | |
51 ($file= $2) =~ s/.txt$/.html/g; | |
52 $label =~ s/\.txt//; | |
53 | |
54 $url{ $tag } = "<a href=\"$file#".escurl($tag)."\">".esctext($label)."</a>"; | |
55 } | |
56 close( TAGS ); | |
57 } | |
58 | |
59 sub esctext | |
60 { | |
61 my $text = shift; | |
62 $text =~ s/&/&/g; | |
63 $text =~ s/</</g; | |
64 $text =~ s/>/>/g; | |
65 return $text; | |
66 } | |
67 | |
68 sub escurl | |
69 { | |
70 my $url = shift; | |
71 $url =~ s/"/%22/g; | |
72 $url =~ s/~/%7E/g; | |
73 $url =~ s/</%3C/g; | |
74 $url =~ s/>/%3E/g; | |
75 $url =~ s/=/%20/g; | |
76 $url =~ s/#/%23/g; | |
77 $url =~ s/\//%2F/g; | |
78 | |
79 return $url; | |
80 } | |
81 | |
82 sub vim2html | |
83 { | |
84 my( $infile ) = @_; | |
85 my( $outfile ); | |
86 | |
87 open(IN, "$infile" ) || die "Couldn't read from $infile: $!.\n"; | |
88 | |
89 ($outfile = $infile) =~ s:.*/::g; | |
90 $outfile =~ s/\.txt$//g; | |
91 | |
92 open( OUT, ">$outfile.html" ) | |
93 || die "Couldn't write to $outfile.html: $!.\n"; | |
94 my $head = uc( $outfile ); | |
95 | |
96 print OUT<<EOF; | |
97 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
98 <html> | |
99 <head> | |
100 <title>VIM: $outfile</title> | |
101 <link rel="stylesheet" href="vim-stylesheet.css" type="text/css"> | |
102 </head> | |
103 <body> | |
104 <h2>$head</h2> | |
105 <pre> | |
106 EOF | |
107 | |
108 my $inexample = 0; | |
109 while( <IN> ) { | |
110 chop; | |
111 if ( /^\s*[-=]+\s*$/ ) { | |
112 print OUT "</pre><hr><pre>"; | |
113 next; | |
114 } | |
115 | |
116 # examples | |
117 elsif( /^>$/ || /\s>$/ ) { | |
118 $inexample = 1; | |
119 chop; | |
120 } | |
121 elsif ( $inexample && /^([<\S])/ ) { | |
122 $inexample = 0; | |
123 $_ = $' if $1 eq "<"; | |
124 } | |
125 | |
126 s/\s+$//g; | |
127 | |
128 # Various vim highlights. note that < and > have already been escaped | |
129 # so that HTML doesn't get screwed up. | |
130 | |
131 my @out = (); | |
132 # print "Text: $_\n"; | |
133 LOOP: | |
134 foreach my $token ( split /((?:\|[^\|]+\|)|(?:\*[^\*]+\*))/ ) { | |
135 if ( $token =~ /^\|([^\|]+)\|/ ) { | |
136 # link | |
137 push( @out, "|".maplink( $1 )."|" ); | |
138 next LOOP; | |
139 } | |
140 elsif ( $token =~ /^\*([^\*]+)\*/ ) { | |
141 # target | |
142 push( @out, | |
143 "<b class=\"vimtag\">\*<a name=\"".escurl($1)."\">".esctext($1)."<\/a>\*<\/b>"); | |
144 next LOOP; | |
145 } | |
146 | |
147 $_ = esctext($token); | |
148 s/CTRL-(\w+)/<code class="keystroke">CTRL-$1<\/code>/g; | |
149 # parameter <...> | |
150 s/<(.*?)>/<code class="special"><$1><\/code>/g; | |
151 | |
152 # parameter {...} | |
153 s/\{([^}]*)\}/<code class="special">{$1}<\/code>/g; | |
154 | |
155 # parameter [...] | |
156 s/\[(range|line|count|offset|cmd|[-+]?num)\]/<code class="special">\[$1\]<\/code>/g; | |
157 # note | |
158 s/(Note:?)/<code class="note">$1<\/code>/gi; | |
159 | |
160 # local heading | |
161 s/^(.*)\~$/<code class="section">$1<\/code>/g; | |
162 push( @out, $_ ); | |
163 } | |
164 | |
165 $_ = join( "", @out ); | |
166 | |
167 if( $inexample == 2 ) { | |
168 print OUT "<code class=\"example\">$_</code>\n"; | |
169 } else { | |
170 print OUT $_,"\n"; | |
171 } | |
172 | |
173 $inexample = 2 if $inexample == 1; | |
174 } | |
175 print OUT<<EOF; | |
176 </pre> | |
33712
e09acb1daea7
runtime(doc): Add Makefile for the Vim documentation on Windows (#13467)
Christian Brabandt <cb@256bit.org>
parents:
2642
diff
changeset
|
177 <p><i>Generated by vim2html on $day.$month.$year</i></p> |
7 | 178 </body> |
179 </html> | |
180 EOF | |
181 | |
182 } | |
183 | |
184 sub usage | |
185 { | |
186 die<<EOF; | |
187 vim2html.pl: converts vim documentation to HTML. | |
188 usage: | |
189 | |
190 vim2html.pl <tag file> <text files> | |
191 EOF | |
192 } | |
193 | |
194 | |
195 sub writeCSS | |
196 { | |
197 open( CSS, ">vim-stylesheet.css" ) || die "Couldn't write stylesheet: $!\n"; | |
198 print CSS<<EOF; | |
199 body { background-color: white; color: black;} | |
200 :link { color: rgb(0,137,139); } | |
201 :visited { color: rgb(0,100,100); | |
202 background-color: white; /* should be inherit */ } | |
203 :active { color: rgb(0,200,200); | |
204 background-color: white; /* should be inherit */ } | |
205 | |
206 B.vimtag { color : rgb(250,0,250); } | |
207 | |
208 h1, h2 { color: rgb(82,80,82); text-align: center; } | |
209 h3, h4, h5, h6 { color: rgb(82,80,82); } | |
210 .headline { color: rgb(0,137,139); } | |
211 .header { color: rgb(164, 32, 246); } | |
212 .section { color: rgb(164, 32, 246); } | |
213 .keystroke { color: rgb(106, 89, 205); } | |
214 .vim { } | |
215 .example { color: rgb(0, 0, 255); } | |
216 .option { } | |
217 .notvi { } | |
218 .special { color: rgb(106, 89, 205); } | |
219 .note { color: blue; background-color: yellow; } | |
220 .sub {} | |
221 .badlink { color: rgb(0,37,39); } | |
222 EOF | |
223 | |
224 } | |
225 | |
226 # main | |
2642 | 227 usage() if $#ARGV < 1; |
7 | 228 |
229 print "Processing tags...\n"; | |
230 readTagFile( $ARGV[ 0 ] ); | |
231 | |
232 foreach my $file ( 1..$#ARGV ) { | |
233 print "Processing ".$ARGV[ $file ]."...\n"; | |
234 vim2html( $ARGV[ $file ] ); | |
235 } | |
236 print "Writing stylesheet...\n"; | |
237 writeCSS(); | |
238 print "done.\n" |