Skip to content

Commit

Permalink
Merge pull request #22 from JJ/master
Browse files Browse the repository at this point in the history
Eliminates anchors for indexed terms
  • Loading branch information
JJ committed Apr 26, 2018
2 parents 165791c + 2fa627d commit 2a65374
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
18 changes: 14 additions & 4 deletions lib/Pod/To/BigPage.pm6
Expand Up @@ -448,13 +448,14 @@ multi sub handle (Pod::FormattingCode $node where .type eq 'X', $context = None,
my $index-display = $node.contents>>.&handle($context).Str;
my @name = $node.meta».&escape-markup;
my $anchor = register-index-entry(@name, $node.contents, :$pod-name);
Q:c (<span class="indexed{$additional-class}"><a id="{$anchor}" name="{@name}">{$index-display}</a></span>);
Q:c (<span class="indexed{$additional-class}" id="{$anchor}" name="{@name}">{$index-display}</span>);
}

multi sub handle (Pod::FormattingCode $node where .type eq 'X', $context where * == Heading, :$pod-name?, :$part-number?, :$toc-counter?) is export {
my $index-display = $node.contents>>.&handle($context).Str;
my $anchor = register-index-entry($node.meta, $node.contents, :$pod-name);
q:c (<a name="{$anchor}"></a>{$index-display})
# q:c (<a name="{$anchor}"></a>{$index-display})
$index-display;
}

multi sub handle (Pod::Heading $node, :$pod-name?, :$part-number?, :$toc-counter, :%part-config) is export {
Expand All @@ -466,12 +467,21 @@ multi sub handle (Pod::Heading $node, :$pod-name?, :$part-number?, :$toc-counter
my $id = $pod-name.subst('.pod6', '') ~ '#' ~ $raw-text.subst(' ', '_', :g).subst('"','&quot;', :g);
$id = rewrite-link($id, :$part-number).substr(1);
if $node.config<numbered> || %part-config{'head' ~ $node.level}<numbered>.?Int {
my $output ='';
my $anchor = register-toc-entry($l, $text, $toc-counter);
return Q:c (<a name="t{$anchor}"{$class}></a><h{$l} id="{$id}">{$anchor} {$text}</h{$l}>) ~ NL
if %part-config<anchored> {
$output = Q:c ( <a name="t{$anchor}"{$class}></a> );
}
return Q:c ({$output} <h{$l} id="{$id}">{$text}</h{$l}>) ~ NL
} else {
my $output='';
my $anchor = register-toc-entry($l, $text, $toc-counter, :hide);
return Q:c (<a name="t{$anchor}"{$class}></a><h{$l} id="{$id}">{$text}</h{$l}>) ~ NL
if %part-config<anchored> {
$output = Q:c ( <a name="t{$anchor}"{$class}></a> );
}
return Q:c ({$output} <h{$l} id="{$id}">{$text}</h{$l}>) ~ NL
}

}

multi sub handle (Pod::Item $node, :$pod-name?, :$part-number?, :$toc-counter?, :%part-config?) is export {
Expand Down
16 changes: 13 additions & 3 deletions t/render.t
Expand Up @@ -7,19 +7,19 @@ use Test::When <online>;
use Pod::To::BigPage;

# Test the rendering of a full page
plan 3;
plan 7;

=begin pod
=head1 This is the head
=head1 This is the head X<|indexed head>
=head2 More stuff here
And just your average text.
=end pod

setup();

say $=pod;
# Tests start here
like compose-before-content($=pod), /This\s+is\s+the\s+head/, "Head inserted";
like compose-before-content($=pod, 'x'), /xml \s+ version/, "Head with xml inserted";
Expand All @@ -29,6 +29,16 @@ for $=pod[0].contents -> $pod-part {
part-number => 1,
toc-counter => TOC-Counter.new.set-part-number(0),
part-config => {:head1(:numbered(True)),:head2(:numbered(True))} );
say $html;
like $html, /{$pod-part.contents}/, "Inserts text with parts";
}

like handle( $=pod[0].contents[0],
pod-name => "/language/test",
part-number => 1,
toc-counter => TOC-Counter.new.set-part-number(0),
part-config => {:head1(:numbered(True)),
:anchored(True)
}
),
/a \s+ name/, "Anchors inserted when you want them";

0 comments on commit 2a65374

Please sign in to comment.