aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2021-02-18 15:03:19 +0100
committerPatrick Spek <p.spek@tyil.nl>2021-02-18 15:03:59 +0100
commit59105b80fb6131ca87b8d1cd56044560382f2604 (patch)
treeb48868042c334aeaa7706acdedeb87f2b71e6fde
parentd7b7fa9a54ec2a05a9a8b1c6db0768889de7f123 (diff)
downloadPod::To::HTML::Section-master.tar.gz
Pod::To::HTML::Section-master.tar.bz2
Update for use with latest Pod::To::AnythingHEADmaster
-rw-r--r--lib/Pod/To/HTML/Section.pm6113
1 files changed, 54 insertions, 59 deletions
diff --git a/lib/Pod/To/HTML/Section.pm6 b/lib/Pod/To/HTML/Section.pm6
index 8e218c6..8ce2fbd 100644
--- a/lib/Pod/To/HTML/Section.pm6
+++ b/lib/Pod/To/HTML/Section.pm6
@@ -14,15 +14,42 @@ my $title;
my $version;
my @notes;
-multi method render (Pod::Block::Code:D $code --> Str) {
+method init () {
+ # Reset all state, or counters will go wrong. It seems pod rendering classes
+ # are invoked statically, so I can't use standard object fields.
+ $no-para = 0;
+ @authors = ();
+ $title = 'Unnamed Module';
+ $version = '*';
+ @notes = ();
+}
+
+method render-before () {
+ "<section id=\"pod\"><h1>$title <small>{$version}</small></h1>"
+}
+
+method render-after () {
+ return '</section>' unless @notes;
+
+ my $content = '<hr>';
+
+ for @notes.kv -> $index, $note {
+ $content ~= "<p><small>[<a id=\"notes-{$index + 1}\">{$index + 1}</a>]: {$note}</small></p>";
+ }
+
+ # And output it.
+ $content ~ '</section>'
+}
+
+multi method render (Pod::Block::Code:D $code, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<pre>{$code.contents.join('').trim.&escape-html}</pre>"
}
-multi method render (Pod::Block::Declarator:D $declarator --> Str) {
+multi method render (Pod::Block::Declarator:D $declarator, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.traverse($declarator)
}
-multi method render (Pod::Block::Named::Author:D $author --> Str) {
+multi method render (Pod::Block::Named::Author:D $author, Pod::Block :$prev, Pod::Block :$next --> Str) {
ENTER { $no-para++ }
LEAVE { $no-para-- }
@@ -31,7 +58,7 @@ multi method render (Pod::Block::Named::Author:D $author --> Str) {
''
}
-multi method render (Pod::Block::Named::Name:D $t --> Str) {
+multi method render (Pod::Block::Named::Name:D $t, Pod::Block :$prev, Pod::Block :$next --> Str) {
ENTER { $no-para++ }
LEAVE { $no-para-- }
@@ -40,11 +67,11 @@ multi method render (Pod::Block::Named::Name:D $t --> Str) {
''
}
-multi method render (Pod::Block::Named::Subtitle:D $subtitle --> Str) {
+multi method render (Pod::Block::Named::Subtitle:D $subtitle, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.traverse($subtitle)
}
-multi method render (Pod::Block::Named::Title:D $t --> Str) {
+multi method render (Pod::Block::Named::Title:D $t, Pod::Block :$prev, Pod::Block :$next --> Str) {
ENTER { $no-para++ }
LEAVE { $no-para-- }
@@ -53,7 +80,7 @@ multi method render (Pod::Block::Named::Title:D $t --> Str) {
''
}
-multi method render (Pod::Block::Named::Version:D $v --> Str) {
+multi method render (Pod::Block::Named::Version:D $v, Pod::Block :$prev, Pod::Block :$next --> Str) {
ENTER { $no-para++ }
LEAVE { $no-para-- }
@@ -62,115 +89,83 @@ multi method render (Pod::Block::Named::Version:D $v --> Str) {
''
}
-multi method render (Pod::Block::Named::Pod:D $document --> Str) {
- # Reset all state, or counters will go wrong. It seems pod rendering classes
- # are invoked statically, so I can't use standard object fields.
- $no-para = 0;
- @authors = ();
- $title = 'Unnamed Module';
- $version = '*';
- @notes = ();
-
- # Traverse the document, which will walk through all the elements.
- my $body = self.traverse($document);
-
- # Create the HTML section to output
- my $section = '<section id="pod">'
- ~ "<h1>$title <small>{$version}</small></h1>"
- ~ $body
- ~ '<h2>Authors</h2>'
- ~ "<ul>{@authors.map({ "<li>{$_}</li>" })}</ul>"
- ;
-
- if (@notes) {
- $section ~= '<hr>';
-
- for @notes.kv -> $index, $note {
- $section ~= "<p><small>[<a id=\"notes-{$index + 1}\">{$index + 1}</a>]: {$note}</small></p>";
- }
- }
-
- # And output it.
- $section ~ '</section>'
-}
-
-multi method render (Pod::Block::Para:D $paragraph --> Str) {
+multi method render (Pod::Block::Para:D $paragraph, Pod::Block :$prev, Pod::Block :$next --> Str) {
return self.traverse($paragraph) if $no-para;
"<p>{self.traverse($paragraph)}</p>"
}
-multi method render (Pod::Block::Table:D $table --> Str) {
+multi method render (Pod::Block::Table:D $table, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.traverse($table)
}
-multi method render (Pod::FormattingCode::B:D $prose --> Str) {
+multi method render (Pod::FormattingCode::B:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<strong>{self.traverse($prose)}</strong>"
}
-multi method render (Pod::FormattingCode::C:D $code --> Str) {
+multi method render (Pod::FormattingCode::C:D $code, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<code>{self.traverse($code)}</code>"
}
-multi method render (Pod::FormattingCode::E:D $prose --> Str) {
+multi method render (Pod::FormattingCode::E:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"&{self.traverse($prose)};"
}
-multi method render (Pod::FormattingCode::I:D $prose --> Str) {
+multi method render (Pod::FormattingCode::I:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<em>{self.traverse($prose)}</em>"
}
-multi method render (Pod::FormattingCode::K:D $prose --> Str) {
+multi method render (Pod::FormattingCode::K:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<code>{self.traverse($prose)}</code>"
}
-multi method render (Pod::FormattingCode::L:D $link --> Str) {
+multi method render (Pod::FormattingCode::L:D $link, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<a href=\"{$link.meta.first}\">{self.traverse($link)}</a>"
}
-multi method render (Pod::FormattingCode::N:D $prose --> Str) {
- @notes.append: self.traverse($prose);
+multi method render (Pod::FormattingCode::N:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
+ @notes.append(self.traverse($prose));
my $index = @notes.elems;
"<sup>[<a href=\"#notes-{$index}\">{$index}</a>]</sup>"
}
-multi method render (Pod::FormattingCode::P:D $prose --> Str) {
+multi method render (Pod::FormattingCode::P:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.traverse($prose)
}
-multi method render (Pod::FormattingCode::R:D $prose --> Str) {
+multi method render (Pod::FormattingCode::R:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<em>{self.traverse($prose)}</em>"
}
-multi method render (Pod::FormattingCode::T:D $prose --> Str) {
+multi method render (Pod::FormattingCode::T:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<code>{self.traverse($prose)}</code>"
}
-multi method render (Pod::FormattingCode::U:D $prose --> Str) {
+multi method render (Pod::FormattingCode::U:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
"<u>{self.traverse($prose)}</u>"
}
-multi method render (Pod::FormattingCode::V:D $prose --> Str) {
+multi method render (Pod::FormattingCode::V:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.unpod($prose)
}
-multi method render (Pod::FormattingCode::X:D $prose --> Str) {
+multi method render (Pod::FormattingCode::X:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
self.traverse($prose)
}
-multi method render (Pod::Heading:D $heading --> Str) {
+multi method render (Pod::Heading:D $heading, Pod::Block :$prev, Pod::Block :$next --> Str) {
ENTER { $no-para++ }
LEAVE { $no-para-- }
"<h{$heading.level + 1}>{self.traverse($heading)}</h{$heading.level + 1}>"
}
-multi method render (Pod::Item:D $item --> Str) {
- "<ul><li>{self.traverse($item)}</li></ul>"
+multi method render (Pod::Item:D $item, Pod::Block :$prev, Pod::Block :$next --> Str) {
+ ('<ul>' unless $prev ~~ Pod::Item) ~ "<li>{self.traverse($item)}</li>" ~ ('</ul>' unless $next ~~ Pod::Item)
}
-multi method render (Str:D $prose --> Str) {
+multi method render (Str:D $prose, Pod::Block :$prev, Pod::Block :$next --> Str) {
$prose.&escape-html
}