#!/usr/bin/perl -CDS
+
use utf8;
use POSIX qw(strftime);
use MIME::Base64;
# Если существует cover.png, добавляем coverpage
if (/<coverpage \/>/) {
$_="";
- if (-f "cover.png") {
- my $id = "cover_png";
- $_ = "<coverpage>\n<image l:href=\"#$id\" />\n</coverpage>\n";
- $pics .= mkbinary("cover.png",$id);
- }
+ COVER:
+ for $file ("cover.jpg","cover.png") {
+ if (-f $file) {
+ my $id = $file;
+ $id=~tr/./_/;
+ $_ = "<coverpage>\n<image l:href=\"#$id\" />\n</coverpage>\n";
+ $pics .= mkbinary($file,$id);
+ last COVER;
+ }
+ }
}
print $_;
}
s/([^\\])%.*$/$1/;
s/^%.*$//;
# strip \sloppy
+s/\\(\w+)\\sloppy/\\$1/g;
s/\\sloppy\s+//g;
s/\\sloppy\{\}//g;
s/\\sloppy([^\w])/$1/g;
s/\s+$//;
s/(\s)\s+/$1/g;
#replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols
-s/~/\xA0/g;
-s/\\-/\xAD/g;
-s/---/—/g;
-s/<</«/g;
-s/>>/»/g;
-s/\\%/%/g;
-s/\\dots/\x{2026}/g;
-s/\\verb(.)(.*)\1/<code>$2<\/code>/;
+$_ = fix_ligatures($_);
}
if ($poetry) {
$poetic_buffer=$_;
next LINE;
}
- s/\\footnote\{(.*)\}/push_footnote($1)/e;
s/\s*\\\\$//;
- $buffer.=tag($_,'v')."\n";
+ $buffer.=tag(flushbuffer($_),'v')."\n";
} elsif ($verbatim) {
add_to_section(tag(tag($_,"code"),"p"));
} else {
while (scalar(@sections) > $found) {
flushsection;
}
- push @sections,{level=>$level,title=>$title,data=>""};
+ push @sections,{level=>$level,title=>fix_ligatures($title),data=>""};
}
+sub fix_ligatures {
+ local $_=shift;
+ s/~/\xA0/g;
+ s/\\-/\xAD/g;
+ s/---/—/g;
+ s/<</«/g;
+ s/>>/»/g;
+ s/\\%/%/g;
+ s/\\dots/\x{2026}/g;
+ s/\\verb(.)(.*)\1/<code>$2<\/code>/;
+ return $_;
+}
sub tag {
my ($content,$name) = @_;
$content =~s/^\s+//s;
sub flushbuffer {
local $_ = shift;
- s/\{\\(em|it|bf)(?:\s+|\{\})([^{}]+)\}/<emphasis>$2<\/emphasis>/g;
- s/\\(emph|textit|textbf)\{([^{}]+)\}/<emphasis>$2<\/emphasis>/g;
+
s/\\footnote\{(.*)\}/push_footnote($1)/e;
+ $_.="}" if (/^\s*\{.*?[^}]$/) ;
+ s/\{\\(em|it|bf)(?:\s+| \{\})([^{}]+)}/<emphasis>$2<\/emphasis>/g;
+ s/\{\\(tt)(?:\s+|\{\})([^{}]+)}/<code>$2<\/code>/g;
+ s/\\(emph|textit|textbf)\{([^{}]+)\}/<emphasis>$2<\/emphasis>/g;
s/[{}]//g;
return $_;
}
sub push_footnote {
my $id = "note_".(++$idseq);
- $footnotes.="<section id=\"$id\">".tag(shift,'p')."</section>\n";
+ $footnotes.="<section id=\"$id\">".tag(flushbuffer(shift),'p')."</section>\n";
return "<a l:href=\"#$id\" type=\"note\">$idseq</a>";
}