\n);
150 | my $lastletter = "ZZ";
151 |
152 | for my $i ( sort { lc($a) cmp lc($b) } @keywords ) {
153 | my $letter = uc( substr( $i, 0, 1 ) );
154 | if ( $letter ne $lastletter ) {
155 | if ( $lastletter ne "ZZ" ) {
156 | $index .= "\n";
157 | }
158 | $index .= "\n
$letter
\n";
159 | $index .= "\n
\n";
160 | $lastletter = $letter;
161 | }
162 | if ($outputdir) {
163 | $index .= qq(- $i
\n);
164 | }
165 | else {
166 | $index .= qq(- $i
\n);
167 | }
168 |
169 | }
170 | $index .= "
\n\n";
171 | return $index;
172 | }
173 |
174 | # Pipe stuff through markdown for parsing
175 | sub markdown_pipe {
176 | my $in = shift;
177 | my @out = ();
178 |
179 | # Use pipes instead of temp files
180 | # The magic here is what you expect open(HANDLE, "| $markdown_bin |") to do.
181 | my $pid = open2( my $chld_out, my $chld_in, $markdown_bin ) or die $!;
182 | print $chld_in $in;
183 | close $chld_in or die $!;
184 | while (<$chld_out>) {
185 | push( @out, $_ );
186 | }
187 | close $chld_out or die $!;
188 |
189 | # We don't leave a process behind!
190 | waitpid( $pid, 0 );
191 | return join( "", @out );
192 | }
193 |
194 | sub smartypants_pipe {
195 | my $in = shift;
196 | my @out = ();
197 | my $pid = open2( my $chld_out, my $chld_in, "$smartypants_bin" )
198 | or die $!;
199 | print $chld_in $in;
200 | close $chld_in or die $!;
201 | while (<$chld_out>) {
202 | push( @out, $_ );
203 | }
204 | close $chld_out or die $!;
205 |
206 | # We don't leave a process behind!
207 | waitpid( $pid, 0 );
208 | return join( "", @out );
209 | }
210 |
211 | sub tidy_pipe {
212 | my $in = shift;
213 | my @out = ();
214 | my $pid = open2( my $chld_out, my $chld_in, "$tidy_bin" )
215 | or die $!;
216 | print $chld_in $in;
217 | close $chld_in or die $!;
218 | while (<$chld_out>) {
219 | push( @out, $_ );
220 | }
221 | close $chld_out or die $!;
222 |
223 | # We don't leave a process behind!
224 | waitpid( $pid, 0 );
225 | return join( "", @out );
226 | }
227 |
228 | # Find all the h1tags for all files
229 | sub h1finder {
230 | %h1s = ();
231 | %files_to_h1s = ();
232 | for my $file ( keys %processed ) {
233 | my @h1 = $processed{$file} =~ m{\