X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=Tex2fb2;fp=Tex2fb2;h=929e9576444bef247c3bd5b14ef17ab39410c098;hb=c94e9f2cf72a205d6081ae2e706d854b35faf5f0;hp=693149fcdc401644ad80bda7cf08af16a61a47eb;hpb=90f2749e4d60b2700566294a2dc75370dcf356d2;p=fiction%2FKate-the-Empress.git diff --git a/Tex2fb2 b/Tex2fb2 index 693149f..929e957 100755 --- a/Tex2fb2 +++ b/Tex2fb2 @@ -5,13 +5,15 @@ my $poetry = 0; my $verbatim = 0; my @sections; my $buffer; +my $idseq = 0; # sequentual number of footnotes +my $footnotes=""; # # TODO italic paragaphs # footnotes # epigraphs # # print fictionbook header -print "\n"; +print "\n"; print "\n"; my $metadata = shift @ARGV; @@ -20,7 +22,7 @@ while () { print $_; } close F; - +print "\n"; my $header =1; LINE: while (<>) { @@ -46,17 +48,17 @@ if (/\\(begin|end){(\w+)}/) { 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")."\n"); + add_to_section(tag(flushbuffer($buffer),$poetry?"stanza":"p")."\n"); $buffer=""; } next LINE if $environ; # Section headings if (/\\(part|chapter|section|subsection|subsubsection)\*?{(.*)}/) { if ($buffer) { - add_to_section(tag($buffer,$poetry?"stanza":"p")); + add_to_section(tag(flushbuffer($buffer),$poetry?"stanza":"p")); $buffer=""; } - pushsection($1,$2); + pushsection($1,tag($2,"p")); next LINE; } if (/\\vspace{/) { @@ -103,7 +105,7 @@ if ($poetry) { } } if ($buffer) { - add_to_section(tag($buffer,"p")); + add_to_section(tag(flushbuffer($buffer),"p")); $buffer=""; } @@ -111,7 +113,8 @@ while (@sections) { flushsection(); } print "\n"; -## FIXME print footnotes +## print footnotes +print "\n$footnotes\n" if $footnotes; print ""; sub add_to_section { @@ -158,3 +161,19 @@ sub tag { return "" if $content =~ /^\s*$/s; return "<$name>$content"; } + +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; + s/[{}]//g; + return $_; +} + + +sub push_footnote { + my $id = "note_".(++$idseq); + $footnotes.="
".tag(shift,'p')."
\n"; + return "$idseq"; +}