Permalink
Browse files

allow an URL munging callback

  • Loading branch information...
1 parent c34f2be commit b4bdbafd14d1aa85cb8205c1148ce897dd7d5a67 @moritz moritz committed Jul 15, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/Pod/To/HTML.pm
View
5 lib/Pod/To/HTML.pm
@@ -9,6 +9,7 @@ method render($pod) {
# way to walk a Pod tree and invoke callbacks on each node, that would reduce the multispaghetti at
# the bottom to something much more readable.
+my &url;
my $title;
my @meta;
my @indexes;
@@ -26,8 +27,9 @@ sub escape_html(Str $str) returns Str {
}
#= Converts a Pod tree to a HTML document.
-sub pod2html($pod) is export returns Str {
+sub pod2html($pod, :&url = -> $url { $url }) is export returns Str {
($title, @meta, @indexes, @body, @footnotes) = ();
+ &OUTER::url = &url;
@body.push: node2html($pod);
my $title_html = escape_html($title // 'Pod document');
@@ -346,6 +348,7 @@ multi sub node2inline(Pod::FormattingCode $node) returns Str {
$text = $/.prematch;
$url = $/.postmatch;
}
+ $url = url($url);
# TODO: URI-escape $url
$text = escape_html $text;
return qq{<a href="$url">{$text}</a>}

0 comments on commit b4bdbaf

Please sign in to comment.