- Timestamp:
- 11/04/08 19:05:26 (2 months ago)
- Files:
-
- 1 modified
-
src/perl6/STD_syntax_highlight (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/perl6/STD_syntax_highlight
r22876 r22877 34 34 STD_syntax_highlight --simple-html=foo.pl.html foo.pl 35 35 36 # write simple snippet html output to foo.pl.html 37 STD_syntax_highlight --snippet-html=foo.pl.html foo.pl 38 36 39 # write simple ansi-colored output to STDOUT 37 40 STD_syntax_highlight --ansi-text=- foo.pl … … 44 47 45 48 my ($clean_html,$help) = (0,0); 46 my ($full_html,$simple_html,$ ansi_text) = (0,0,0);49 my ($full_html,$simple_html,$snippet_html,$ansi_text) = (0,0,0,0); 47 50 my ($file, $parser, $src_text); 48 51 … … 61 64 "full-html=s"=>\$full_html, 62 65 "simple-html=s"=>\$simple_html, 66 "snippet-html=s"=>\$snippet_html, 63 67 "ansi-text=s"=>\$ansi_text, 64 68 "help"=>\$help … … 82 86 option is selected, - for STDOUT) 83 87 88 --snippet-html=filename 89 same as --simple-html but with only the body section. 90 This is typically ideal for inline html code. 91 84 92 --ansi-text=filename 85 93 write simple-mode ansi color text to filename (- for STDOUT) … … 89 97 90 98 #default is --simple-html=- if no option is selected 91 if(!($ansi_text || $full_html ) && !$simple_html) {99 if(!($ansi_text || $full_html || $snippet_html) && !$simple_html) { 92 100 $simple_html = '-'; 93 101 } … … 142 150 my $html = highlight_perl6_simple(); 143 151 write_output $simple_html, $html; 152 } 153 if($snippet_html) { 154 my $html = highlight_perl6_snippet_html(); 155 write_output $snippet_html, $html; 144 156 } 145 157 if($ansi_text) { … … 296 308 } 297 309 310 =item highlight_perl6_snippet_html 311 312 This is same as C<highlight_perl6_full> when --snippet-html is used. 313 No more javascript tree viewer or anything fancy. 314 Only nodes that have a color are printed. Not optimal but works ;-) 315 =cut 316 sub highlight_perl6_snippet_html { 317 my $str = ""; 318 my %colors = (); 319 320 my $CSS = "STD_syntax_highlight.css"; 321 open CSS_FILE, $CSS 322 or die "Could not open $CSS: $OS_ERROR\n"; 323 my $line; 324 while($line = <CSS_FILE>) { 325 if($line =~ /^\s*\.(\w+)\s*{\s*(.+?)\s*}/) { 326 $colors{$1} = $2; 327 } 328 } 329 close CSS_FILE; 330 331 $str .= "<pre>"; 332 333 local *spit_snippet_html = sub { 334 my ($i, $buffer, $rule, $tree) = @ARG; 335 $buffer = escape_html($buffer); 336 my $style = $colors{$rule}; 337 if($rule) { 338 $str .= qq{<span style="$style">$buffer</span>}; 339 } else { 340 $str .= $buffer; 341 } 342 }; 343 344 redspans_traverse(\&spit_snippet_html,%colors); 345 346 $str .= "</pre>"; 347 348 $str; 349 } 350 298 351 299 352 =item highlight_perl6_ansi … … 329 382 330 383 redspans_traverse(\&spit_ansi_text,%colors); 331 384 332 385 $str; 333 386 }
