s/(\s)\s+/$1/g;
#replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
s/~/\xA0/g;
-s/---/-/g;
+s/---/—/g;
s/<</«/g;
s/>>/»/g;
s/\\%/%/g;
}
print "</body>\n";
## print footnotes
-print "<body id=\"notes\">\n$footnotes\n</body>" if $footnotes;
+print "<body>\n$footnotes\n</body>" if $footnotes;
print "</FictionBook>";
sub add_to_section {
my $data = shift;
return if ($#sections<0) ;
+ if ($data =~ /^\s*<section>/ && $sections[$#sections]->{data} !~ /^\s*<section>/) {
+ $sections[$#sections]->{data} = tag($sections[$#sections]->{data},"section")."\n";
+ }
$sections[$#sections]->{data}.=$data;
}
if ($str->{title}) {
$content = tag($str->{title},"title");
}
- $content .= $str->{data};
+ if ($str->{data} =~ /^\s*$/s) {
+ $content .= "<p>\n</p>";
+ } else {
+ $content .= $str->{data};
+ }
if ($#sections >=0) {
add_to_section(tag($content,$tag)."\n");
} else {
sub tag {
my ($content,$name) = @_;
- return "" if $content =~ /^\s*$/s;
+ $content =~s/^\s+//s;
+ return "" unless $content;
return "<$name>$content</$name>";
}