Skip to content

Commit

Permalink
Merge pull request #46 from finanalyst/master
Browse files Browse the repository at this point in the history
change returns to -->
  • Loading branch information
JJ committed Oct 12, 2018
2 parents 8fbb00b + e80425c commit a07bb78
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/Pod/To/HTML.pm
Expand Up @@ -50,13 +50,13 @@ my $DEBUG := %*ENV<P6DOC_DEBUG>;

sub Debug(Callable $c) { $c() if $DEBUG; }

sub escape_html(Str $str) returns Str {
sub escape_html(Str $str --> Str ) {
return $str unless ( $str ~~ /<[ & < > " ' {   ]>/ ) or ( $str ~~ / ' ' / );
$str.trans( [ q{&}, q{<}, q{>}, q{"}, q{'}, q{ } ] =>
[ q{&amp;}, q{&lt;}, q{&gt;}, q{&quot;}, q{&#39;}, q{&nbsp;}]);
}

sub unescape_html(Str $str) returns Str {
sub unescape_html(Str $str --> Str ) {
$str.trans( [ rx{'&amp;'}, rx{'&lt;'}, rx{'&gt;'}, rx{'&quot;'}, rx{'&#39;'} ] =>
[ q{&}, q{<}, q{>}, q{"}, q{'} ] );
}
Expand Down Expand Up @@ -159,7 +159,7 @@ sub assemble-list-items(:@content, :$node, *% ) {
#| Converts a Pod tree to a HTML document.
sub pod2html($pod, :&url = -> $url { $url }, :$head = '', :$header = '', :$footer = '', :$default-title,
:$css-url = '//design.perl6.org/perl.css', :$lang = 'en',
) is export returns Str {
--> Str ) is export {
($title, $subtitle, @meta, @indexes, @body, @footnotes) = ();
#| Keep count of how many footnotes we've output.
my Int $*done-notes = 0;
Expand Down Expand Up @@ -217,14 +217,14 @@ sub pod2html($pod, :&url = -> $url { $url }, :$head = '', :$header = '', :$foote
}
#| Returns accumulated metadata as a string of C«<meta>» tags
sub do-metadata returns Str {
sub do-metadata ( --> Str ) {
return @meta.map(-> $p {
qq[<meta name="{escape_html($p.key)}" value="{node2text($p.value)}" />]
}).join("\n");
}
#| Turns accumulated headings into a nested-C«<ol>» table of contents
sub do-toc($pod) returns Str {
sub do-toc($pod --> Str ) {
my @levels is default(0) = 0;
my proto sub find-headings($node, :$inside-heading){*}
Expand Down Expand Up @@ -279,7 +279,7 @@ sub do-toc($pod) returns Str {
#| Flushes accumulated footnotes since last call. The idea here is that we can stick calls to this
#| before each C«</section>» tag (once we have those per-header) and have notes that are visually
#| and semantically attached to the section.
sub do-footnotes returns Str {
sub do-footnotes ( --> Str ) {
return '' unless @footnotes;
my Int $current-note = $*done-notes + 1;
Expand All @@ -297,7 +297,7 @@ sub do-footnotes returns Str {
}
#| block level or below
proto sub node2html(|) returns Str is export {*}
proto sub node2html(| --> Str ) is export {*}
multi sub node2html($node) {
Debug { note colored("Generic node2html called for ", "bold") ~ $node.perl };
return node2inline($node);
Expand Down Expand Up @@ -500,16 +500,16 @@ multi sub node2html(Str $node) {
#| inline level or below
multi sub node2inline($node) returns Str {
multi sub node2inline($node --> Str ) {
Debug { note colored("missing a node2inline multi for ", "bold") ~ $node.gist };
return node2text($node);
}
multi sub node2inline(Pod::Block::Para $node) returns Str {
multi sub node2inline(Pod::Block::Para $node --> Str ) {
return node2inline($node.contents);
}
multi sub node2inline(Pod::FormattingCode $node) returns Str {
multi sub node2inline(Pod::FormattingCode $node --> Str ) {
my %basic-html = (
B => 'strong', #= Basis
C => 'code', #= Code
Expand Down Expand Up @@ -594,26 +594,26 @@ multi sub node2inline(Pod::FormattingCode $node) returns Str {
}
}
multi sub node2inline(Positional $node) returns Str {
multi sub node2inline(Positional $node --> Str ) {
return $node.map({ node2inline($_) }).join;
}
multi sub node2inline(Str $node) returns Str {
multi sub node2inline(Str $node --> Str ) {
return escape_html($node);
}
#| HTML-escaped text
multi sub node2text($node) returns Str {
multi sub node2text($node --> Str ) {
Debug { note colored("missing a node2text multi for ", "red") ~ $node.perl };
return escape_html(node2rawtext($node));
}
multi sub node2text(Pod::Block::Para $node) returns Str {
multi sub node2text(Pod::Block::Para $node --> Str ) {
return node2text($node.contents);
}
multi sub node2text(Pod::Raw $node) returns Str {
multi sub node2text(Pod::Raw $node --> Str ) {
my $t = $node.target;
if $t && lc($t) eq 'html' {
$node.contents.join
Expand All @@ -625,31 +625,31 @@ multi sub node2text(Pod::Raw $node) returns Str {
# FIXME: a lot of these multis are identical except the function name used...
# there has to be a better way to write this?
multi sub node2text(Positional $node) returns Str {
multi sub node2text(Positional $node --> Str ) {
return $node.map({ node2text($_) }).join;
}
multi sub node2text(Str $node) returns Str {
multi sub node2text(Str $node --> Str ) {
return escape_html($node);
}
#| plain, unescaped text
multi sub node2rawtext($node) returns Str {
multi sub node2rawtext($node --> Str ) {
Debug { note colored("Generic node2rawtext called with ", "red") ~ $node.perl };
return $node.Str;
}
multi sub node2rawtext(Pod::Block $node) returns Str {
multi sub node2rawtext(Pod::Block $node --> Str ) {
Debug { note colored("node2rawtext called for ", "bold") ~ $node.gist };
return node2rawtext($node.contents);
}
multi sub node2rawtext(Positional $node) returns Str {
multi sub node2rawtext(Positional $node --> Str ) {
return $node.map({ node2rawtext($_) }).join;
}
multi sub node2rawtext(Str $node) returns Str {
multi sub node2rawtext(Str $node --> Str ) {
return $node;
}
Expand Down

0 comments on commit a07bb78

Please sign in to comment.