Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change returns to --> #46

Merged
merged 1 commit into from
Oct 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/Pod/To/HTML.pm
Original file line number Diff line number Diff line change
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