From: Victor Wagner Date: Mon, 17 Jul 2017 18:27:48 +0000 (+0300) Subject: Sync Tex2fb2 with spacians version X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=c5aed59d228a68df12f4ca532f4ffabbae2020f0;p=fiction%2FKate-the-Empress.git Sync Tex2fb2 with spacians version --- diff --git a/Tex2fb2 b/Tex2fb2 index 9ed9dd9..abc38bb 100755 --- a/Tex2fb2 +++ b/Tex2fb2 @@ -1,4 +1,5 @@ #!/usr/bin/perl -CDS + use utf8; use POSIX qw(strftime); use MIME::Base64; @@ -35,11 +36,16 @@ while () { # Если существует cover.png, добавляем coverpage if (//) { $_=""; - if (-f "cover.png") { - my $id = "cover_png"; - $_ = "\n\n\n"; - $pics .= mkbinary("cover.png",$id); - } + COVER: + for $file ("cover.jpg","cover.png") { + if (-f $file) { + my $id = $file; + $id=~tr/./_/; + $_ = "\n\n\n"; + $pics .= mkbinary($file,$id); + last COVER; + } + } } print $_; } @@ -100,6 +106,7 @@ if (!$verbatim) { s/([^\\])%.*$/$1/; s/^%.*$//; # strip \sloppy +s/\\(\w+)\\sloppy/\\$1/g; s/\\sloppy\s+//g; s/\\sloppy\{\}//g; s/\\sloppy([^\w])/$1/g; @@ -108,14 +115,7 @@ s/^\s+//; 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>/; +$_ = fix_ligatures($_); } if ($poetry) { @@ -128,9 +128,8 @@ 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 { @@ -194,9 +193,21 @@ sub pushsection { 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/\\dots/\x{2026}/g; + s/\\verb(.)(.*)\1/$2<\/code>/; + return $_; +} sub tag { my ($content,$name) = @_; $content =~s/^\s+//s; @@ -206,9 +217,12 @@ sub tag { sub flushbuffer { local $_ = shift; - s/\{\\(em|it|bf)(?:\s+|\{\})([^{}]+)\}/$2<\/emphasis>/g; - s/\\(emph|textit|textbf)\{([^{}]+)\}/$2<\/emphasis>/g; + s/\\footnote\{(.*)\}/push_footnote($1)/e; + $_.="}" if (/^\s*\{.*?[^}]$/) ; + s/\{\\(em|it|bf)(?:\s+| \{\})([^{}]+)}/$2<\/emphasis>/g; + s/\{\\(tt)(?:\s+|\{\})([^{}]+)}/$2<\/code>/g; + s/\\(emph|textit|textbf)\{([^{}]+)\}/$2<\/emphasis>/g; s/[{}]//g; return $_; } @@ -216,7 +230,7 @@ sub flushbuffer { sub push_footnote { my $id = "note_".(++$idseq); - $footnotes.="
".tag(shift,'p')."
\n"; + $footnotes.="
".tag(flushbuffer(shift),'p')."
\n"; return "$idseq"; }