Permalink
Browse files

Switched HTML anchor output from name to id attr.

This improves W3C spec compliance and very much improves ePub output.
  • Loading branch information...
1 parent 673d542 commit c46c72acce5015d5dd5433b4225c594b1b374fa5 @chromatic committed Nov 26, 2012
Showing with 31 additions and 9 deletions.
  1. +25 −3 lib/Pod/PseudoPod/DOM/Role/HTML.pm
  2. +4 −4 t/html/tags.t
  3. +2 −2 t/html/translations.t
@@ -428,10 +428,32 @@ sub emit_paragraph
my $self = shift;
my @kids = @{ $self->children };
my $has_visible_text = grep { ! exists $invisibles{ $_->type } } @kids;
- my $content = $self->emit_kids( @_ );
+ return $self->emit_kids( @_ ) unless $has_visible_text;
- return $content unless $has_visible_text;
- return '<p>' . $content . qq|</p>\n\n|;
+ my $attrs = @kids && $kids[0]->type =~ /anchor|index/
+ ? $self->get_anchored_paragraph_attrs( shift @kids )
+ : '';
+
+ # inlined emit_kids() here to reflect any anchor manipulation
+ my $content = join '', map { $_->emit( @_ ) } @kids;
+ return "<p$attrs>" . $content . qq|</p>\n\n|;
+}
+
+sub get_anchored_paragraph_attrs
+{
+ my ($self, $tag) = @_;
+ my $type = $tag->type;
+
+ if ($type eq 'anchor')
+ {
+ my $content = $tag->get_anchor;
+ return qq| id="$content"|;
+ }
+ elsif ($type eq 'index')
+ {
+ my $content = $tag->get_anchor . $tag->id;
+ return qq| id="$content"|;
+ }
}
my %parent_items =
View
@@ -15,15 +15,15 @@ my $file = read_file( catfile( qw( t test_file.pod ) ) );
my $result = parse_with_anchors( $file );
my $link = encode_link( 'startofdocument' );
-like_string $result, qr!<a name="$link"></a>!m,
+like_string $result, qr!<p id="$link">!m,
'Z<> tags should become anchors';
$link = encode_link( 'next_heading' );
-like_string $result, qr!<a name="$link"></a>!m,
+like_string $result, qr!<p id="$link">!m,
'... without normal escaping';
$link = encode_link( 'slightlycomplex?heading' );
-like_string $result, qr!<a name="$link"></a>!,
+like_string $result, qr!<p id="$link">!,
'... and escaping non-alphanumerics';
like_string $result, qr!<a class="url" href="http://www.google.com/">!,
@@ -45,7 +45,7 @@ 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!,
+like_string $result, qr!<p id="${link}1">Special formatting!,
'... paragraphs of index/anchor tags should collapse';
done_testing;
View
@@ -67,10 +67,10 @@ 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!<p><a name="${link}1"></a>!m,
+like_string $result, qr!<p id="${link}1">!m,
'indexed items need even more special escaping';
-like_string $result, qr!<a name="${link}2"></a>!m,
+like_string $result, qr!<p id="${link}2">!m,
'... and de-duplication';
like_string $result, qr!mc<sup>2</sup>!, 'superscript works';

0 comments on commit c46c72a

Please sign in to comment.