Hello Ron,
thanks for the information.
Here is how I helped myself until you will come up with a proper solution. Maybe it is helpful in some way. Unfortunately I do not know how to correctly submit a patch, and I don't think it's production ready code quality anyways.
Kind regards,
Ekki
1. I extended Tree::Simple with three more predicate methods, which might be handy in other situations as well:
sub getSiblingsCount {
my $siblings;
return scalar( @{ $siblings = $_[0]->getAllSiblings } );
};
sub isFirstChild {
$_[0]->getIndex == 0
};
sub isLastChild {
my $self = shift;
if ( $self->getIndex == ($self->getSiblingsCount -1) ) {
return 1;
}
else {
return 0;
}
};
2. With that the traverse to generate a correctly nested <ul> list becomes:
my $treestring;
$tree->traverse(
sub {
my $t = shift;
if ($t->isFirstChild) {
$treestring .= "\n" . ' ' x $t->getDepth() . "<ul>\n";
};
$treestring .= ' ' x $t->getDepth();
$treestring .= '<li>' . $t->getNodeValue();
},
sub {
my $t = shift;
$treestring .= "</li>\n";
if ($t->isLastChild) {
$treestring .= ' ' x $t->getDepth() . "</ul>\n";
};
}
);
Show quoted text> -----Original Message-----
> From: ron@savage.net.au via RT [mailto:bug-Tree-Simple-View@rt.cpan.org]
> Sent: Sunday, April 16, 2017 1:13 AM
> To: e.plicht@wimo.com
> Cc: EKKIP@cpan.org
> Subject: Re: [rt.cpan.org #121099] Incorrect nesting of HTML list
>
>
> <URL:
https://rt.cpan.org/Ticket/Display.html?id=121099 >
>
> Hi Ekki
>
> Hmmm. Much more difficult than I was hoping. Still trying....
>
> On 14/04/17 10:06, ron@savage.net.au via RT wrote:
> (long) weekend.
> >
> > On 13/04/17 19:25, Ekkehard Plicht via RT wrote:
> >> Thu Apr 13 05:25:57 2017: Request 121099 was acted upon.
> >> Transaction: Ticket created by e.plicht@wimo.com
> >> Queue: Tree-Simple-View
> >> Subject: Incorrect nesting of HTML list
> >> Broken in: (no value)
> >> Severity: (no value)
> >> Owner: Nobody
> >> Requestors: e.plicht@wimo.com
> >> Status: new
> >> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=121099 >
> >>
> >>
> >> Hello,
> >> many thanks for providing the Tree::Simple::View::HTML module!
> >>
> >> Unfortunately it produces incorrectly nested output, not conforming to
> >> HTML5:
> >>
> >> <UL>
> >> <LI>1</LI>
> >> <UL>
> >> <LI>1.1</LI>
> >> <LI>1.2</LI>
> >> </UL>
> >> <LI>2</LI>
> >> <UL>
> >> <LI>2.1</LI>
> >> </UL>
> >> <LI>3</LI>
> >> </UL>
> >>
> >>
> >> Correct would be:
> >>
> >> <UL>
> >> <LI>1
> >> <UL>
> >> <LI>1.1</LI>
> >> <LI>1.2</LI>
> >> </UL>
> >> </LI>
> >> <LI>2
> >> <UL>
> >> <LI>2.1</LI>
> >> </UL>
> >> </LI>
> >> <LI>3</LI>
> >> </UL>
> >>
> >> see
https://www.w3.org/wiki/HTML_lists#Nesting_lists
> >>
> >>
> >> Any chance of having a 'html5' option which changes the nesting to the
> >> correct form?
> >>
> >> Many thanks.
> >>
> >> Kind regards,
> >> Ekki
> >>
> >
>
> --
> Ron Savage - savage.net.au
>