Skip to content

Commit e8bef89

Browse files
Fletcher T. PenneyFletcher T. Penney
authored andcommitted
update mmd_merge
1 parent 8606a13 commit e8bef89

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Utilities/mmd_merge.pl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,32 @@
1616
my $data = "";
1717
my $line = "";
1818

19-
foreach(@ARGV) {
20-
open(INPUT, "<$_");
19+
my $count = @ARGV;
20+
21+
if ($count == 0) {
22+
# We're in "stdin mode"
23+
24+
# process stdin
25+
undef $/;
26+
my $data .= <>;
27+
28+
mergeLines($data);
29+
} else {
30+
foreach(@ARGV) {
31+
open(INPUT, "<$_");
32+
local $/;
33+
my $data = <INPUT>;
34+
close(INPUT);
35+
mergeLines($data);
36+
}
37+
}
38+
2139

22-
while ($line = <INPUT>) {
40+
sub mergeLines {
41+
my $file = shift;
42+
43+
while ($file =~ /^(.*?)$/mg) {
44+
$line = $1;
2345
if (($line !~ /^\s*$/) && ($line !~ /^\#/)) {
2446
$line =~ s/ {4}/\t/g;
2547
$line =~ s/\s*$//;
@@ -39,12 +61,9 @@
3961
}
4062
}
4163

42-
close INPUT;
64+
print $data;
4365
}
4466

45-
print $data;
46-
47-
4867
=head1 NAME
4968
5069
mmd_merge.pl - Combine text documents to create a MultiMarkdown structured

0 commit comments

Comments
 (0)