Skip to content

Commit

Permalink
Generate URL fragments for index entries according to new schema
Browse files Browse the repository at this point in the history
Prior to this, URI fragments rendered were aligned with the format
Documentable expected to follow, however it was recently changed
to address number of issues such as:

- Absence of special characters escaping in the fragments
- Relying on the formatting code parts that should be flexible
  in long term
  • Loading branch information
Altai-man committed Jul 30, 2022
1 parent 9d99075 commit 813ef63
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/Pod/To/HTML.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,17 @@ monitor Node::To::HTML {
}

when 'X' {
multi sub recurse-until-str(Str:D $s) { $s }
multi sub recurse-until-str(Pod::Block $n) { $n.contents>>.&recurse-until-str().join }

my $index-text = recurse-until-str($node).join;
my @indices = $node.meta;
my $index-name-attr =
qq[index-entry{ @indices ?? '-' !! '' }{ @indices.join('-') }{ $index-text ?? '-' !! '' }$index-text]
.subst('_', '__', :g).subst(' ', '_', :g);
$index-name-attr = $!renderer.url($index-name-attr).subst(/^\//, '');
# meta is by default a list of lists, so take the first element
# and then take `foo` part of `X<Text?|Category,foo>`.
my $index-entry-text = @indices[0][1];
my $fragment = uri-escape("index-entry-$index-entry-text");
$fragment = $!renderer.url($fragment).subst(/^\//, '');
my $text = self.node2inline($node.contents);
$!renderer.crossrefs{$_} = $text for @indices;

return qq[<a name="$index-name-attr"><span class="index-entry">$text\</span></a>] if $text;
return qq[<a name="$index-name-attr"></a>];
return qq[<a id="$fragment"><span class="index-entry">$text\</span></a>] if $text;
return qq[<a id="$fragment"></a>];
}

# Stuff I haven't figured out yet
Expand Down

0 comments on commit 813ef63

Please sign in to comment.