leas => Lingua::EN::Alphabet::Shaw->new(),
quotedepth => 0,
magicword => undef,
- magiccontent => undef,
+ textcontent => undef,
unknownWords => {},
};
}
}
+sub addTextContentToPara {
+
+ my ($self, $lineNumber) = @_;
+
+ return unless defined $self->{'textcontent'};
+
+ my @lines = split(/\n/, $self->{'textcontent'});
+ for my $line (@lines) {
+ my @words = split(/\s+/, $line);
+
+ my @result;
+
+ for my $word (@words) {
+ next unless $word;
+ my $shaw = $word;
+
+ $shaw = $self->shavianise_phrase($shaw, $lineNumber) unless $self->{'literal'};
+
+ $word =~ s/_[a-z]*//g;
+
+ my $args = 0;
+ if ($self->{'poetry'}) {
+ $args = 1;
+ } else {
+ $args += 1 if $self->{'italics'};
+ $args += 2 if $self->{'literal'};
+ }
+
+ push @result, [$word, $shaw,
+ $args];
+ }
+
+ push @{$self->{'para'}}, @result;
+
+ if ($self->{'poetry'}) {
+ push @{$self->{'para'}}, ['LINE', 'LINE', 4];
+ }
+
+ }
+
+ $self->{'textcontent'} = undef;
+}
+
sub parse {
my ($self, $filename, $callback) = @_;
my ($parser, $tag, %attrs) = @_;
if ($tag eq 'i') {
+ $self->addTextContentToPara($parser->current_line());
$self->{'italics'} = 1;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'literal') {
+ $self->addTextContentToPara($parser->current_line());
$self->{'literal'} = 1;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'p') {
$self->{'para'} = [];
$self->{'poetry'} = 0;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'poetry') {
$self->{'para'} = [];
$self->{'poetry'} = 1;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'pagebreak') {
$callback->('PGBK');
} elsif ($tag eq 'dab') {
$attrs{'short'});
} elsif ($tag eq 'magic') {
$self->{'magicword'} = $attrs{'word'};
- $self->{'magiccontent'} = '';
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'quote') {
$self->{'quotedepth'} = $attrs{'depth'};
}
my ($parser, $tag) = @_;
if ($tag eq 'i') {
+ $self->addTextContentToPara($parser->current_line());
$self->{'italics'} = 0;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'literal') {
+ $self->addTextContentToPara($parser->current_line());
$self->{'literal'} = 0;
+ $self->{'textcontent'} = '';
} elsif ($tag eq 'p') {
+ $self->addTextContentToPara($parser->current_line());
$skipping = !$callback->('PARA',
$self->{'para'});
$self->checkQuoteDepth($parser->current_line());
} elsif ($tag eq 'poetry') {
my @temp;
$self->checkQuoteDepth($parser->current_line());
+ $self->addTextContentToPara($parser->current_line());
for my $word (@{$self->{'para'}}) {
if ($word->[2] == 8) {
# Stanza break
push @{$self->{'para'}}, ['STANZA', 'STANZA', 8];
$self->{'quotedepth'} = 0;
} elsif ($tag eq 'magic') {
- my $shavian_content = $self->{'magiccontent'};
+ my $shavian_content = $self->{'textcontent'};
$shavian_content = $self->shavianise_phrase($shavian_content, $parser->current_line);
$callback->('MAGI',
$self->{'magicword'},
- $self->{'magiccontent'},
+ $self->{'textcontent'},
$shavian_content);
$self->{'magicword'} = undef;
- $self->{'magiccontent'} = undef;
+ $self->{'textcontent'} = undef;
}
},
Char => sub {
$parser->current_line()."\n";
}
- if (defined $self->{'magiccontent'}) {
- # <magic/> captures all text
- $self->{'magiccontent'} .= $text;
+ if (defined $self->{'textcontent'}) {
+ $self->{'textcontent'} .= $text;
return;
}
-
- my @lines = split(/\n/, $text);
- for my $line (@lines) {
- my @words = split(/\s+/, $line);
-
- my @result;
-
- for my $word (@words) {
- next unless $word;
- my $shaw = $word;
-
- $shaw = $self->shavianise_phrase($shaw, $parser->current_line) unless $self->{'literal'};
-
- $word =~ s/_[a-z]*//g;
-
- my $args = 0;
- if ($self->{'poetry'}) {
- $args = 1;
- } else {
- $args += 1 if $self->{'italics'};
- $args += 2 if $self->{'literal'};
- }
-
- push @result, [$word, $shaw,
- $args];
- }
-
- push @{$self->{'para'}}, @result;
-
- if ($self->{'poetry'}) {
- push @{$self->{'para'}}, ['LINE', 'LINE', 4];
- }
-
- }
},
});
<p>[Not like cats!] cried the Mouse, in a shrill, passionate voice. [Would <i>you</i> like cats if you were me?]</p>
-<p>[Well, perhaps not,] said Alice in a soothing tone: [don't be angry about it. And yet I wish I could show you our cat Dinah: I think you'd take a fancy to cats if you could only see her. She is such a dear quiet thing,] Alice went on, half to herself, as she swam lazily about in the pool, [and she sits purring so nicely by the fire, licking her paws and washing her face—and she is such a nice soft thing to nurse—and she's such a capital one for catching mice—oh, I beg your pardon!] cried Alice again, for this time the Mouse was bristling all over, and she felt certain it must be <fixme/>really offended. [We won't talk about her any more if you'd rather not.]</p>
+<p>[Well, perhaps not,] said Alice in a soothing tone: [don't be angry about it. And yet I wish I could show you our cat Dinah: I think you'd take a fancy to cats if you could only see her. She is such a dear quiet thing,] Alice went on, half to herself, as she swam lazily about in the pool, [and she sits purring so nicely by the fire, licking her paws and washing her face—and she is such a nice soft thing to nurse—and she's such a capital one for catching mice—oh, I beg your pardon!] cried Alice again, for this time the Mouse was bristling all over, and she felt certain it must be really offended. [We won't talk about her any more if you'd rather not.]</p>
<p>[We indeed!] cried the Mouse, who was trembling down to the end of his tail. [As if I would talk on such a subject_n! Our family always <i>hated</i> cats: nasty, low, vulgar things! Don't let me hear the name again!]</p>
<p>[I had <i>not!]</i> cried the Mouse, sharply and very angrily.</p>
-<p>[A knot!] said Alice, <fixme/>always ready to make herself useful, and looking anxiously about her. [Oh, do let me help to undo it!]</p>
+<p>[A knot!] said Alice, always ready to make herself useful, and looking anxiously about her. [Oh, do let me help to undo it!]</p>
<p>[I shall do nothing of the sort,] said the Mouse, getting up and walking away. [You insult me by talking such nonsense!]</p>
-<p>[I didn't mean it!] pleaded poor Alice. <fixme/>[But you're so easily offended, you know!]</p>
+<p>[I didn't mean it!] pleaded poor Alice. [But you're so easily offended, you know!]</p>
<p>The Mouse only growled in reply.</p>