X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=Tex2fb2;h=96279b391b0062e4b4afdb8b8e21ceddb3366ecd;hb=21dea09917423a78e9d8d12a3be622355915947c;hp=22d83434cdcc887bf7382299656a993c4ac007ee;hpb=0387dbe081b6d275160f7109e992e7eca30ce74d;p=fiction%2FKate-the-Empress.git diff --git a/Tex2fb2 b/Tex2fb2 index 22d8343..96279b3 100755 --- a/Tex2fb2 +++ b/Tex2fb2 @@ -1,6 +1,7 @@ #!/usr/bin/perl -CDS use utf8; use POSIX qw(strftime); +use MIME::Base64; # char-level modes my $poetry = 0; my $verbatim = 0; @@ -19,10 +20,11 @@ print "\n"; my $metadata = shift @ARGV; open F,"<",$metadata; +my $pics = ""; while () { # Replace empty date with current date if (// || /\s*<\/date>/) { - $_ = "".strftime("%Y-%m-%d",localtime())."\">". + $_ = "". strftime("%d/%m/%Y",localtime())."\n"; } # Add current to date as fractional part to version @@ -30,6 +32,15 @@ while () { my $ver = $1+time()/1E10; $_=tag(sprintf("%g",$ver),"version")."\n"; } + # Если существует cover.png, добавляем coverpage + if (//) { + $_=""; + if (-f "cover.png") { + my $id = "cover_png"; + $_ = "\n\n\n"; + $pics .= mkbinary("cover.png",$id); + } + } print $_; } close F; @@ -77,6 +88,12 @@ if (/\\vspace{/) { next LINE; } next LINE if /\\pagebreak\b/; +#replace ' and " with entities +s/&/&/g; +s/'/'/g; +s/"/"/g; +s//>/g; #normal mode: if (!$verbatim) { #strip TeX comments @@ -92,21 +109,26 @@ 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/\\dots/\x{2026}/g; +s/\\verb(.)(.*)\1/$2<\/code>/; } -#replace ' and " with entities -s/&/&/g; -s/'/'/g; -s/"/"/g; -s//>/g; if ($poetry) { chomp; + if ($poetic_buffer) { + $_ = $poetic_buffer." ".$_; + $poetic_buffer = undef; + } + if (/{[^}]+$/) { + $poetic_buffer=$_; + next LINE; + } + s/\\footnote{(.*)}/push_footnote($1)/e; s/\s*\\\\$//; $buffer.=tag($_,'v')."\n"; } elsif ($verbatim) { @@ -126,6 +148,7 @@ while (@sections) { print "\n"; ## print footnotes print "\n$footnotes\n" if $footnotes; +print $pics; print ""; sub add_to_section { @@ -196,3 +219,14 @@ sub push_footnote { $footnotes.="
".tag(shift,'p')."
\n"; return "$idseq"; } + +sub mkbinary { + my ($filename,$id) = @_; + my $f; + open $f,"<",$filename; + binmode $f; + local $/; + my $data = encode_base64(<$f>); + return "$data\n"; + close $f; +}