Permalink
Browse files

Added fixup for index entries in their own paras.

Now they merge into the next paragraph with visible text.
  • Loading branch information...
1 parent 3d5c1e7 commit 563917664f50636fadb0ee5469142306dafa5055 @chromatic committed Mar 27, 2012
Showing with 52 additions and 3 deletions.
  1. +34 −0 lib/Pod/PseudoPod/DOM.pm
  2. +13 −2 lib/Pod/PseudoPod/DOM/Elements.pm
  3. +4 −0 t/html/tags.t
  4. +1 −1 t/html/translations.t
View
34 lib/Pod/PseudoPod/DOM.pm
@@ -100,6 +100,40 @@ sub end_Document
{
my $self = shift;
$self->{active_elements} = [];
+ $self->finish_document;
+}
+
+sub finish_document
+{
+ my $self = shift;
+ $self->collapse_index_entries;
+}
+
+sub collapse_index_entries
+{
+ my $self = shift;
+ my $document = $self->get_document;
+ my $kids = $document->children;
+ my @saved_kids;
+ my @splice_kids;
+
+ # merge index entries into the next paragraph with visible text
+ for my $kid (@$kids)
+ {
+ if ($kid->type eq 'paragraph')
+ {
+ unless ($kid->has_visible_kids)
+ {
+ push @splice_kids, @{ $kid->children };
+ next;
+ }
+ unshift @{ $kid->children }, splice @splice_kids;
+ }
+
+ push @saved_kids, $kid;
+ }
+
+ @$kids = @saved_kids;
}
sub start_Verbatim
View
15 lib/Pod/PseudoPod/DOM/Elements.pm
@@ -13,7 +13,8 @@ use Moose;
with 'MooseX::Traits';
has 'type', is => 'ro', required => 1;
- sub is_empty { 1 }
+ sub is_empty { 1 }
+ sub is_visible { 1 }
}
{
@@ -45,6 +46,12 @@ use Moose;
use Moose;
extends 'Pod::PseudoPod::DOM::ParentElement';
+
+ sub has_visible_kids
+ {
+ my $self = shift;
+ return grep { $_->is_visible } @{ $self->children };
+ }
}
{
@@ -61,7 +68,8 @@ use Moose;
$self->content( shift );
}
- sub is_empty { length( shift->content ) == 0 }
+ sub is_visible { shift->content =~ /\S/ }
+ sub is_empty { length( shift->content ) == 0 }
}
{
@@ -82,6 +90,7 @@ use Moose;
extends 'Pod::PseudoPod::DOM::Element::Linkable';
+ sub is_visible { 0 }
sub get_anchor { shift->emit_kids( encode => 'index_anchor' ) }
sub get_link_text { shift->heading->emit_kids }
}
@@ -94,6 +103,8 @@ use Moose;
extends 'Pod::PseudoPod::DOM::Element::Linkable';
+ sub is_visible { 0 }
+
sub get_key
{
my $self = shift;
View
4 t/html/tags.t
@@ -44,4 +44,8 @@ $link = encode_link( 'next_heading' );
like_string $result, qr!<a href="tags.t.pod#$link">!,
'... and non-quoting when appropriate';
+$link = encode_link( 'Specialformatting' );
+like_string $result, qr!<p><a name="${link}1"></a>Special formatting!,
+ '... paragraphs of index/anchor tags should collapse';
+
done_testing;
View
2 t/html/translations.t
@@ -67,7 +67,7 @@ like_string $result, qr|<span class="footnote">but beware of footnotes!</span>|,
'footnotes need special escaping too';
my $link = encode_link( 'Specialformatting' );
-like_string $result, qr!^<a name="${link}1"></a><p>!m,
+like_string $result, qr!<p><a name="${link}1"></a>!m,
'indexed items need even more special escaping';
like_string $result, qr!<a name="${link}2"></a>!m,

0 comments on commit 5639176

Please sign in to comment.