X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;ds=sidebyside;f=Tex2fb2;h=30988082287d8c4345292a34f511a10b60ca4e66;hb=c5415250d31ea934a22724d095fc0f04429e78c4;hp=12f50da94cbca1d0b11758a5f6f08b85455a621d;hpb=34aa8ee96c682061235ff8355841c2f0c59c123f;p=fiction%2FKate-the-Empress.git diff --git a/Tex2fb2 b/Tex2fb2 index 12f50da..3098808 100755 --- a/Tex2fb2 +++ b/Tex2fb2 @@ -1,5 +1,6 @@ #!/usr/bin/perl -CDS use utf8; +use POSIX qw(strftime); # char-level modes my $poetry = 0; my $verbatim = 0; @@ -19,6 +20,16 @@ xmlns:l=\"http://www.w3.org/1999/xlink\">\n"; my $metadata = shift @ARGV; open F,"<",$metadata; while () { + # Replace empty date with current date + if (// || /\s*<\/date>/) { + $_ = "". + strftime("%d/%m/%Y",localtime())."\n"; + } + # Add current to date as fractional part to version + if (/(\d*)(.\d*)?<\/version>/) { + my $ver = $1+time()/1E10; + $_=tag(sprintf("%g",$ver),"version")."\n"; + } print $_; } close F; @@ -66,6 +77,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 @@ -81,21 +98,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) {