#!/usr/bin/perl -w use strict; use warnings; use utf8; use open qw(:std :utf8); use integer; $| = 1; # Filter_4_02_move_floats.pl # 2010-06-30 # Wolfgang Schmidle my $filtername = "Filter_4_02_move_floats.pl"; # text input my @text; while(<>) { push @text, $_; } # go through the text my $notes = "mgl|mgr|fn"; my %position = ( mgl => "left", mgr => "right", fn => "foot" ); my @newText; my $pb = ""; my $figure = 0; my $note = 0; my $position = ""; my $handwritten = 0; my $nummer; my $anchor; my $float; my @floats = (); my $inP = 0; my $inPandNote = 0; my $noteText = ""; my $inPandFigure = 0; my $figureText = ""; my $i = 0; foreach (@text) { $i++; if (m!]!) { $inP = 1; } if (m!

!) { $inP = 0; } if (/]*file="([^"]+)"/) { $pb = $1; $figure = 1; $note = 1; push @newText, $_; next; } # wird noch nicht korrekt verarbeitet. Vorläufig eine Schummellösung: s!]+)>!!g; if ($inP) { if (m!
!) { $nummer = ( $figure < 10 ? "$pb-0$figure" : "$pb-$figure"); s!'."\n"; $float .= ' '."\n"; $float .= '
'."\n"; push @floats, $float; $figure++; push @newText, $_; next; } if (m!]!) { $inPandFigure = 1; $nummer = ( $figure < 10 ? "$pb-0$figure" : "$pb-$figure"); $anchor = "\n"; s!!) { # $inPandFigure = 0; # push @floats, $figureText; # } $figure++; next; } if (m!!) { $inPandFigure = 0; $figureText .= $_; push @floats, $figureText; next; } if ($inPandFigure) { $figureText .= $_; next; } if (m!<($notes)!) { $inPandNote = 1; $position = $position{$1}; $nummer = ( $note < 10 ? "$pb-0$note" : "$pb-$note"); $anchor = "\n"; s!<($notes)([^>]*)>!!; push @newText, $anchor; $noteText = $_; if ($noteText =~ s!!!) { $inPandNote = 0; push @floats, $noteText; } $note++; next; } if (s!!!) { $inPandNote = 0; $noteText .= $_; push @floats, $noteText; next; } if ($inPandNote) { $noteText .= $_; next; } if (m!!) { $nummer = ( $handwritten < 10 ? "$pb-0$figure" : "$pb-$figure"); s!!!; $float = ' '."\n"; push @floats, $float; $handwritten++; push @newText, $_; next; } } if (! $inP) { if (m!(!) { $nummer = ( $figure < 10 ? "$pb-0$figure" : "$pb-$figure"); $_ = " $1>\n"; $_ .= ' '."\n"; $_ .= ' '."\n"; $figure++; push @newText, $_; next; } if (m!]!) { $nummer = ( $figure < 10 ? "$pb-0$figure" : "$pb-$figure"); chomp; $_ .= "\n"; push @newText, $_; $figure++; next; } if (m!!) { push @newText, $_; next; } if (m!<($notes)!) { $position = $position{$1}; s!<($notes)([^>]*)>!!; s!!!; push @newText, $_; $note++; next; } if (m!!) { s!!!; push @newText, $_; next; } if (m!!) { push @newText, $_; $handwritten++; next; } } if (m!

!) { push @newText, $_; if (/type="float"/) { die "$filtername: Line $i: Es gibt schon ein
!\n"; } if ($pb eq "") { die "$filtername: Line $i:
ohne vorhergehendes !\n"; } if (@floats) { push @newText, '
'."\n"; foreach (@floats) { push @newText, $_; } push @newText, '
'. "\n"; @floats = (); } next; } push @newText, $_; next; } if (@floats) { die "$filtername: Es gibt am Ende noch mindestens ein ohne zugehöriges
!\n"; } # print @newText; printInOutputTextFile(@newText); # TO DO: #
und , die nicht nur eine Zeile lang sind # tables etc. # anchored marginal notes # getrennt? prüfe, ob labels doppelt vergeben wurden # --> braucht man das? Das kann doch nur passieren, wenn labels zum Teil per Hand vergeben wurden? # Marginalien: wenn sie nach der ersten Zeile des Absatzes kommen, ziehe sie vor den Absatz # (erst ein Durchlauf, wo das korrigiert wird, bevor das eigentliche Herausziehen der Floats kommt?) # Fußnoten in Boskovic # Boskovic 1763, p.0329: , und sie haben recht. Wie vermerke ich das? # note mit xml:space nur, wenn kein

oder . Oder: das Skript nimmt es wieder raus, falls nicht anwendbar? # Floats stillschweigend herausziehen, wenn nur eine Absatz-Zeile davor oder danach ist. # sortiere die Elemente in

, nämlich erst , dann , dann # dieses Skript wäre ein Kandidat, um in XSLT geschrieben zu werden! # sollte korrekt funktionieren, wenn es schon IDs gibt