aboutsummaryrefslogtreecommitdiff
path: root/spec2md.pl
blob: 313f86f42bbb3c0393654bdc9ccb43415f43ead5 (plain)
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. my $stage = 0;
  5. my $example = 0;
  6. my @match;
  7. my $section = "";
  8. while (<STDIN>) {
  9. if (/^\.$/) {
  10. if ($stage == 0) {
  11. $example++;
  12. print "\n<div class=\"example\" id=\"example-$example\" data-section=\"$section\">\n";
  13. print "<div class=\"examplenum\"><a href=\"#example-$example\">Example $example</a>&nbsp;&nbsp;<a class=\"dingus\" title=\"open in interactive dingus\">(interact)</a></div>\n\n";
  14. print "````````````````````````````````````````````````````````` markdown\n";
  15. } elsif ($stage == 1) {
  16. print "`````````````````````````````````````````````````````````\n\n";
  17. print "````````````````````````````````````````````````````````` html\n";
  18. } elsif ($stage == 2) {
  19. print "`````````````````````````````````````````````````````````\n\n";
  20. print "</div>\n\n";
  21. } else {
  22. die "Encountered unknown stage $stage";
  23. }
  24. $stage = ($stage + 1) % 3;
  25. } else {
  26. if ($stage == 0 && (@match = ($_ =~ /^#{1,6} *(.*)/))) {
  27. $section = $match[0];
  28. }
  29. if ($stage != 0) {
  30. $_ =~ s/ /␣/g;
  31. }
  32. print $_;
  33. }
  34. }