File: convert.pl

package info (click to toggle)
libtext-multimarkdown-perl 1.000035-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 1,772 kB
  • ctags: 148
  • sloc: perl: 2,186; makefile: 8
file content (47 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use strict;
use warnings;
open(LS, "ls -1 *.md|") or die;
my @list = <LS>;
close(LS);

foreach (@list) {
    chomp;
    s/\.md$//;
    my ($markdown, $html) = convert_to_perl_test("$_.md");
    open(MD, ">$_.text") or die;
    print MD $markdown;
    close(MD);
    open(MD, ">$_.html") or die;
    print MD $html;
    close(MD);
}

sub convert_to_perl_test {
    my ($file) = @_;
    my $FH;
    open($FH, '<', $file) or die("Cannot open $file");
    my ($markdown, $html);
    my @lines = <$FH>;
    close($FH);
    my $mode = 0;
    foreach my $l (@lines) {
        if ($l =~ /^\*\*\*/) {
            $mode = 0;
            if ($l =~ /Markdown input/i) {
                $mode = 1;
            }
            if ($l =~ /Output of to_html/) {
                $mode = 2;
            }
        }
        elsif ($mode > 0) {
            if (1 == $mode) {
                $markdown .= $l;
            }
            else {
                $html .= $l;
            }
        }
    }
    return ($markdown, $html);
}