X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=Tex2fb2;fp=Tex2fb2;h=693149fcdc401644ad80bda7cf08af16a61a47eb;hb=90f2749e4d60b2700566294a2dc75370dcf356d2;hp=2d644dfdac9b0cc512d5ba3229ee4a0a05bc7c12;hpb=416f4f9bd47860f06c2dfe92269dbc8a49f5887d;p=fiction%2FKate-the-Empress.git diff --git a/Tex2fb2 b/Tex2fb2 index 2d644df..693149f 100755 --- a/Tex2fb2 +++ b/Tex2fb2 @@ -26,7 +26,7 @@ LINE: while (<>) { $environ = undef; if (/\\(begin|end){(\w+)}/) { - $environ = $2; + $environ=$2; $begin=$1 eq "begin"; if ($environ eq 'verbatim') { $verbatim=$begin; @@ -34,17 +34,19 @@ if (/\\(begin|end){(\w+)}/) { if ($begin) { pushsection("poem",undef); } else { - flushsection('poem'); + add_to_section(tag($buffer,'stanza')."\n") if $buffer; + $buffer=""; + flushsection('poem'); } $poetry = $begin; - } elsif($environ = 'document' && $begin) { + } elsif($environ eq 'document' && $begin) { $header=0; } } next LINE if $header; if ((/^$/ || $environ) && $buffer) { #output on empty line (p or stanza) depending on poetry mode - add_to_section(tag($buffer,$poetry?"stanza":"p")); + add_to_section(tag($buffer,$poetry?"stanza":"p")."\n"); $buffer=""; } next LINE if $environ; @@ -61,6 +63,7 @@ if (/\\vspace{/) { add_to_section(""); next LINE; } +next LINE if /\\pagebreak\b/; #normal mode: if (!$verbatim) { #strip TeX comments @@ -70,6 +73,10 @@ s/^%.*$//; s/\\sloppy\s+//g; s/\\sloppy{}//g; s/\\sloppy([^\w])/$1/g; +# strip extra space +s/^\s+//; +s/\s+$//; +s/(\s)\s+/$1/g; #replace TeX ligatures ~ --- << >> \% with appropriate unicode symbols s/~/\xA0/g; s/---/-/g; @@ -87,11 +94,12 @@ s/>/>/g; if ($poetry) { chomp; - $buffer.=tag($_,'v'); + s/\s*\\\\$//; + $buffer.=tag($_,'v')."\n"; } elsif ($verbatim) { add_to_section(tag(tag($_,"code"),"p")); } else { - $buffer.=$_; + $buffer.=" ".$_; } } if ($buffer) { @@ -121,7 +129,7 @@ sub flushsection { } $content .= $str->{data}; if ($#sections >=0) { - add_to_section(tag($content,$tag)); + add_to_section(tag($content,$tag)."\n"); } else { print tag($content,$tag); } @@ -147,6 +155,6 @@ sub pushsection { sub tag { my ($content,$name) = @_; - return "" if ($content eq "\n"); + return "" if $content =~ /^\s*$/s; return "<$name>$content"; }