Last active
May 24, 2018 12:27
-
-
Save vifon/c8cdfc0e603bf9ec342612df94c4467f to your computer and use it in GitHub Desktop.
Make the heavily nested Perl docs more readable (though invalid POD)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use 5.010; | |
use constant INDENT_WIDTH => 2; | |
my $indent_level = 0; | |
sub indentation { | |
return " " x ($indent_level * INDENT_WIDTH); | |
} | |
sub reprint { | |
print indentation, shift // $_; | |
} | |
while (<>) { | |
if (/=over\b/) { | |
reprint; | |
reprint "{\n"; | |
++$indent_level; | |
} elsif (/=back\b/) { | |
--$indent_level; | |
reprint "}\n"; | |
reprint; | |
} else { | |
if (/\S/) { | |
reprint; | |
} else { | |
print; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment