8 # TODO italic paragaphs
12 # print fictionbook header
13 print "<?xml version=\"1.0\" encoding=\"UTF-8\">\n";
14 print "<FictionBook xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\"
15 xmlns:l=\"http://www.w3.org/1999/xlink\">\n";
16 my $metadata = shift @ARGV;
26 if (/\\(begin|end){(\w+)}/) {
29 if ($environ eq 'verbatim') {
31 } elsif ($environ eq 'verse') {
33 pushsection("poem",undef);
38 } elsif($environ = 'document' && $begin) {
43 if (/^$/ && $environ && $buffer) {
44 #output on empty line (p or stanza) depending on poetry mode
45 add_to_section(tag($buffer,$poetry?"stanza":"p"));
48 next LINE if $environ;
50 if (/\\(part|chapter|section|subsection|subsubsection){(.*)}/) {
57 #replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
63 #replace ' and " with entities
74 add_to_section(tag(tag($_,"code"),"p"));
80 add_to_section(tag($buffer,"p"));
87 ## FIXME print footnotes
88 print "</FictionBook>";
92 return if ($#sections<0) ;
93 $sections[$#sections]->{data}.=$data;
97 my $tag= shift || 'section';
98 my $str = pop @sections;
101 $content = tag($str->{title},"title");
103 $content .= $str->{data};
104 if ($#sections >=0) {
105 add_to_section(tag($content,$tag));
107 print tag($content,$tag);
112 my ($level,$title)=@_;
113 # Find section of $level in the current stack
114 my $found=scalar(@sections);
116 for (my $i=0;$i<=$#sections;$i++) {
117 if ($sections[$i]->{level} eq $level) {
122 # if found, flush everything below
123 while (scalar(@sections) > $found) {
126 push @sections,{level=>$level,title=>$title,data=>""};
130 my ($content,$name) = @_;
131 return "<$name>$content</$name>";