manfull.pl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/perl
  2. $failures = 0;
  3. while ($page = shift) {
  4. system "mv $page $page.orig";
  5. open IN,"<$page.orig" or die "Cannot read from $page.orig\n";
  6. open OUT,">$page" or die "Cannot write to $page\n";
  7. $toc = undef;
  8. while (<IN>) {
  9. if (/<meta http-equiv="Content-Style-Type" content="text\/css">/) {
  10. print OUT;
  11. print OUT '<link rel="stylesheet" href="https://orgmode.org/org-manual.css" type="text/css" />';
  12. } elsif (/<div class="contents">/) {
  13. print OUT;
  14. print OUT '<p>This is the official manual for the latest <a href="https://orgmode.org">Org mode</a> release.</p><div id="table-of-contents">';
  15. } elsif (/<h2>Table of Contents<\/h2>|<h2 class="contents-heading">/) {
  16. print OUT;
  17. print OUT '<a href="https://orgmode.org">https://orgmode.org</a><br/><div id="text-table-of-contents">';
  18. $toc = 1;
  19. } elsif (/<\/div>/ and $toc) {
  20. print OUT "</div></div></div>";
  21. $toc = 0;
  22. } else {
  23. print OUT;
  24. }
  25. }
  26. system "rm $page.orig";
  27. if (!defined($toc) || $toc != 0) {
  28. ++$failures;
  29. print STDERR "Patching of $page failed\n";
  30. }
  31. }
  32. $failures == 0 or die "Patching of $failures files failed\n";