7
|
1 #!/usr/bin/env perl
|
|
2 use strict;
|
|
3 use warnings;
|
10
|
4 use utf8;
|
|
5
|
|
6 my $source_md = shift;
|
|
7 my $target_tex = shift;
|
|
8
|
|
9 open my $texFH, '>', $target_tex;
|
7
|
10
|
|
11 {
|
|
12 open my $fh, '<', 'md2tex/first.tex';
|
|
13 while (my $line = <$fh> ) {
|
10
|
14 print $texFH $line;
|
7
|
15 }
|
|
16 close $fh;
|
|
17 }
|
|
18
|
10
|
19 open my $fh, '<', $source_md;
|
14
|
20
|
|
21 my $in_codeblock = 0;
|
|
22
|
7
|
23 while (my $line = <$fh>) {
|
18
|
24 if ($line =~ /^```/) {
|
14
|
25 $in_codeblock = !$in_codeblock;
|
|
26 if (!$in_codeblock) {
|
|
27 $line = '\end{lstlisting}' ."\n";
|
|
28 }
|
24
|
29 if ($line =~ /``` lab:(.*),\s*cap:(.*)/) {
|
14
|
30 $line = '\b'."egin{lstlisting}[frame=lrbt,label=$1,caption={$2}]\n";
|
|
31 }
|
|
32 }
|
|
33
|
18
|
34 if ($in_codeblock) {
|
|
35 print $texFH $line;
|
|
36 next;
|
|
37 }
|
|
38
|
|
39 if ($line =~/^#/) {
|
|
40 $line =~ s/# (.*)/\\section{$1}/;
|
|
41 }
|
|
42
|
|
43 while ($line =~ /`([\s\w_\-\\]+)`/g) {
|
19
|
44 my $inlineCodeBlock = $1;
|
|
45 $inlineCodeBlock =~ s/_/\\_/g;
|
|
46 $line =~ s/`([\s\w_\-\\]+)`/\\texttt{$inlineCodeBlock}/;
|
18
|
47 }
|
|
48
|
24
|
49 if ($line =~ /!\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) {
|
23
|
50 $line = <<"EOF";
|
|
51 \\begin{figure}[tb]
|
|
52 \\begin{center}
|
|
53 \\includegraphics[width=70mm]{$3}
|
|
54 \\end{center}
|
|
55 \\caption{$2}
|
|
56 \\label{$1}
|
|
57 \\end{figure}
|
|
58 EOF
|
|
59 }
|
|
60
|
24
|
61 if ($line =~ /^\[lab:(.*),\s*cap:(.*)\]\((.*)\)/) {
|
14
|
62 $line = '\l' ."stinputlisting[label=$1, caption={$2}]{$3}\n";
|
|
63 }
|
10
|
64 print $texFH $line;
|
7
|
65 }
|
|
66 close $fh;
|
|
67
|
10
|
68 print $texFH <<'EOF';
|
7
|
69
|
|
70 \nocite{*}
|
|
71 \bibliographystyle{ipsjunsrt}
|
|
72 \bibliography{anatofuz-bib}
|
|
73
|
|
74
|
|
75 \end{document}
|
|
76 EOF
|
10
|
77
|
|
78
|
|
79 close $texFH;
|