dru.pl 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!perl
  2. ###########################################################
  3. # dru.pl #
  4. # usage: run in directory of html files for drupal #
  5. ###########################################################
  6. # GP 2011
  7. # This program cleans html files bound for drupal #
  8. # of codes that will cause drupal errors #
  9. # This program loops through all html files in a dir #
  10. # then will substitute the strings on line 37&38 s//; #
  11. # added logic to further drupalize the LINK tags s//; #
  12. # finally it will write out the modified file 1 pass #
  13. ###########################################################
  14. # Copyright LN 2011 : all rights reserved #
  15. ###########################################################
  16. use File::Find;
  17. use strict;
  18. my $directory = ".";
  19. find (\&process, $directory);
  20. sub process
  21. {
  22. my @outLines; #Data we are going to output
  23. my $line; #Data we are reading line by line
  24. # print "processing $_ / $File::Find::name\n";
  25. # Only parse files that end in .html
  26. if ( $File::Find::name =~ /\.html$/ ) {
  27. open (FILE, $File::Find::name ) or
  28. die "Cannot open file: $!";
  29. print "\n" . $File::Find::name . "\n";
  30. while ( $line = <FILE> ) {
  31. $line =~ s~<a name\="([^"]*)"><\/a>~~gi;
  32. $line =~ s~<a class\="indexterm" name\="d0e.[^"]*"><\/a>~~gi;
  33. #following line added for see also links for ECLR
  34. $line =~ s/<a class\="link" href\="(.[^\.]*)\.html"/<a class\="link" href\="$1"/g;
  35. ##following lines colorize text
  36. $line =~ s~<span class\="bluebold">~<span class\="bluebold" style\="color:blue\;font-weight:bold">~gi;
  37. $line =~ s~<span class\="blueital">~<span class\="blueital" style\="color:blue\;font-style:italic">~gi;
  38. $line =~ s~<span class\="blue">~<span class\="blue" style\="color:blue">~gi;
  39. $line =~ s~<span class\="redbold">~<span class\="redbold" style\="color:red\;font-weight:bold">~gi;
  40. $line =~ s~<span class\="redital">~<span class\="redital" style\="color:red\;font-style:italic">~gi;
  41. $line =~ s~<span class\="red">~<span class\="red" style\="color:red">~gi;
  42. $line =~ s~<span class\="greenbold">~<span class\="greenbold" style\="color:green\;font-weight:bold">~gi;
  43. $line =~ s~<span class\="greenital">~<span class\="greenital" style\="color:green\;font-style:italic">~gi;
  44. $line =~ s~<span class\="green">~<span class\="green" style\="color:green">~gi;
  45. $line =~ s~<span class\="whitebold">~<span class\="whitebold" style\="color:white\;font-weight:bold">~gi;
  46. $line =~ s~<span class\="whiteital">~<span class\="whiteital" style\="color:white\;font-style:italic">~gi;
  47. $line =~ s~<span class\="white">~<span class\="white" style\="color:white">~gi;
  48. print $line;
  49. push(@outLines, $line);
  50. }
  51. close FILE;
  52. open ( OUTFILE, ">$File::Find::name" ) or
  53. die "Cannot open file: $!";
  54. print ( OUTFILE @outLines );
  55. close ( OUTFILE );
  56. undef( @outLines );
  57. }
  58. }