2
0

trimmarkdownheader.pl 751 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env perl
  2. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  3. #
  4. # SPDX-License-Identifier: curl
  5. #
  6. # Given: a libcurl curldown man page
  7. # Outputs: the same file, minus the header
  8. #
  9. my $f = $ARGV[0];
  10. open(F, "<$f") or die;
  11. my @out;
  12. my $line = 0;
  13. my $hideheader = 0;
  14. while(<F>) {
  15. if($hideheader) {
  16. if(/^---/) {
  17. # end if hiding
  18. $hideheader = 0;
  19. }
  20. push @out, "\n"; # replace with blank
  21. next;
  22. }
  23. elsif(!$line++ && /^---/) {
  24. # starts with a header, strip off the header
  25. $hideheader = 1;
  26. push @out, "\n"; # replace with blank
  27. next;
  28. }
  29. push @out, $_;
  30. }
  31. close(F);
  32. open(O, ">$f") or die;
  33. for my $l (@out) {
  34. print O $l;
  35. }
  36. close(O);