3 #=======================================================================
5 # File ID: b9e646d2-ae65-11e5-837d-fefdb24f8e10
7 # Add Vim fold markers to headers in Commonmark/Markdown
10 # ©opyleft 2015– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
32 $progname =~ s/^.*\/(.*?)$/$1/;
33 our $VERSION = '0.2.1';
35 Getopt
::Long
::Configure
('bundling');
38 'help|h' => \
$Opt{'help'},
39 'quiet|q+' => \
$Opt{'quiet'},
40 'remove|r' => \
$Opt{'remove'},
41 'verbose|v+' => \
$Opt{'verbose'},
42 'version' => \
$Opt{'version'},
44 ) || die("$progname: Option error. Use -h for help.\n");
46 $Opt{'verbose'} -= $Opt{'quiet'};
47 $Opt{'help'} && usage
(0);
48 if ($Opt{'version'}) {
58 my $FB = "\x7b\x7b\x7b";
59 my $FB_regex = "\\\x7b\\\x7b\\\x7b";
61 while (my $Line = <>) {
63 if ($Line =~ /^(#+)/) {
65 $Line =~ s/ ?<!-- $FB_regex\d? -->//;
68 my $level = length($marks);
69 if ($Line =~ /<!-- $FB_regex\d? -->/) {
70 $Line =~ s/ ?<!-- $FB_regex\d? -->/ <!-- ${FB}$level -->/;
72 $Line .= " <!-- ${FB}$level -->";
84 # Print program version {{{
85 print("$progname $VERSION\n");
91 # Send the help message to stdout {{{
94 if ($Opt{'verbose'}) {
100 Add Vim folds to '#*' headers in Commonmark/Markdown.
102 Usage: $progname [options] [file [files [...]]]
109 Be more quiet. Can be repeated to increase silence.
111 Remove folds from header lines instead of adding them.
113 Increase level of verbosity. Can be repeated.
115 Print version information.
123 # Print a status message to stderr based on verbosity level {{{
124 my ($verbose_level, $Txt) = @_;
126 if ($Opt{'verbose'} >= $verbose_level) {
127 print(STDERR
"$progname: $Txt\n");
135 # This program is free software; you can redistribute it and/or modify
136 # it under the terms of the GNU General Public License as published by
137 # the Free Software Foundation; either version 2 of the License, or (at
138 # your option) any later version.
140 # This program is distributed in the hope that it will be useful, but
141 # WITHOUT ANY WARRANTY; without even the implied warranty of
142 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
143 # See the GNU General Public License for more details.
145 # You should have received a copy of the GNU General Public License
146 # along with this program.
147 # If not, see L<http://www.gnu.org/licenses/>.
149 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :