Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle definition lists more like =item
This is further to discussion on #20
  • Loading branch information
jonathanstowe committed Aug 13, 2018
1 parent 326838c commit b4684ff
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
29 changes: 22 additions & 7 deletions lib/Pod/To/HTML.pm
Expand Up @@ -47,6 +47,7 @@ my %crossrefs;

# see <https://docs.perl6.org/language/traps#Constants_are_Compile_Time>
my $DEBUG := %*ENV<P6DOC_DEBUG>;

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

sub escape_html(Str $str) returns Str {
Expand Down Expand Up @@ -82,6 +83,9 @@ multi visit($root, :&pre, :&post, :&assemble = -> *% { Nil }) {
}

class Pod::List is Pod::Block { };
class Pod::DefnList is Pod::Block { };



sub assemble-list-items(:@content, :$node, *% ) {
my @newcont;
Expand Down Expand Up @@ -132,6 +136,15 @@ sub assemble-list-items(:@content, :$node, *% ) {

@pushalias.push($_);
}
# This is simpler than lists because we don't need to
# list
when Pod::Defn {
$foundone = True;
unless +@newcont && @newcont[*-1] ~~ Pod::DefnList {
@newcont.push(Pod::DefnList.new());
}
@newcont[*-1].contents.push($_);
}

default {
@newcont.push($_);
Expand Down Expand Up @@ -302,7 +315,7 @@ multi sub node2html(Pod::Block::Declarator $node) {
}
default {
Debug { note "I don't know what {$node.WHEREFORE.WHAT.perl} is. Assuming class..." };
"<h1>"~ node2html([$node.WHEREFORE.perl, q{: }, $node.contents])~ "</h1>";
"<h1>"~ node2html([$node.WHEREFORE.perl, q{: }, $node.contents])~ "</h1>";
}
}
}
Expand Down Expand Up @@ -431,12 +444,14 @@ multi sub node2html(Pod::Config $node) {
return '';
}
multi sub node2html(Pod::DefnList $node ) {
return "<dl>\n" ~ node2html($node.contents) ~ "\n</dl>\n";
}
multi sub node2html(Pod::Defn $node) {
return "<dl>" ~
"<dt>" ~ node2html($node.term) ~ "</dt>" ~
"<dd>" ~ node2html($node.contents) ~ "</dd>" ~
"</dl>\n";
"<dt>" ~ node2html($node.term) ~ "</dt>\n" ~
"<dd>" ~ node2html($node.contents) ~ "</dd>\n";
}
# TODO: would like some way to wrap these and the following content in a <section>; this might be
Expand All @@ -458,8 +473,8 @@ multi sub node2html(Pod::Heading $node) {
$content = %escaped<html>;
} else {
$content = qq[<a class="u" href="#___top" title="go to top of document">]
~ %escaped<html>
~ qq[</a>];
~ %escaped<html>
~ qq[</a>];
}
return sprintf('<h%d id="%s">', $lvl, %escaped<id>)
Expand Down
23 changes: 13 additions & 10 deletions t/075-defn.t
@@ -1,6 +1,6 @@
#!perl6

use Test;
use Test;
use Pod::To::HTML;

plan 1;
Expand All @@ -23,13 +23,16 @@ Having the quality of general expediency.
my $html = pod2html($=pod[0]);

ok $html ~~ ms[[
'<dl><dt>MAD</dt><dd>'
'<p>Affected with a high degree of intellectual independence.</p>'
'</dd></dl>'
'<dl><dt>MEEKNESS</dt><dd>'
'<p>Uncommon patience in planning a revenge that is worth while.</p>'
'</dd></dl>'
'<dl><dt>MORAL</dt><dd>'
'<p>Conforming to a local and mutable standard of right. Having the quality of general expediency.</p>'
'</dd></dl>'
'<dl>'
'<dt>MAD</dt>'
'<dd><p>Affected with a high degree of intellectual independence.</p>'
'</dd>'
'<dt>MEEKNESS</dt>'
'<dd><p>Uncommon patience in planning a revenge that is worth while.</p>'
'</dd>'
'<dt>MORAL</dt>'
'<dd><p>Conforming to a local and mutable standard of right. Having the quality of general expediency.</p>'
'</dd>'

'</dl>'
]], 'generated html for =defn';

0 comments on commit b4684ff

Please sign in to comment.