Skip to content

Commit

Permalink
fixed bug that prevented multiple anchors with the same name in Mojol…
Browse files Browse the repository at this point in the history
…icious::Plugin::PODRenderer
  • Loading branch information
kraih committed Aug 2, 2012
1 parent 9f795ac commit 9c89a67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
3.19 2012-08-03
- Improved documentation.
- Improved tests.
- Fixed bug that prevented multiple anchors with the same name in
Mojolicious::Plugin::PODRenderer.

3.18 2012-08-02
- Improved documentation.
Expand Down
15 changes: 10 additions & 5 deletions lib/Mojolicious/Plugin/PODRenderer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ sub _perldoc {

# Rewrite headers
my $url = $self->req->url->clone;
my @parts;
my (%anchors, @parts);
$dom->find('h1, h2, h3')->each(
sub {
my $e = shift;
my $anchor = my $text = $e->all_text;
$anchor =~ s/\s+/_/g;
$anchor = url_escape $anchor, '^A-Za-z0-9_';
$anchor =~ s/\%//g;

# Anchor and text
my $name = my $text = $e->all_text;
$name =~ s/\s+/_/g;
my $anchor = $name = url_escape $name, '^A-Za-z0-9\-._~!()*';
my $i = 1;
$anchor = $name . $i++ while $anchors{$anchor}++;

# Rewrite
push @parts, [] if $e->type eq 'h1' || !@parts;
push @{$parts[-1]}, $text, $url->fragment($anchor)->to_abs;
$e->replace_content(
Expand Down

0 comments on commit 9c89a67

Please sign in to comment.