Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Convert nested list HTML TOC to JS Tree ?

by renodino (Curate)
on Jun 02, 2007 at 21:29 UTC ( #618927=perlquestion: print w/ replies, xml ) Need Help??
renodino has asked for the wisdom of the Perl Monks concerning the following question:

I've hacked a simple script to convert the index/TOC of POD::ProjectDocs output to a Javascripted tree (using a slightly altered version of dtree).

Turns out the solution can be generalized to convert any HTML with a nested list (<ul> or <ol>) TOC to a JS Tree widget...which makes me think there's a CPAN module that already does this, but I haven't found the search terms to locate it.

(As an example of the different output, see this old page vs. the converted page.)

  1. Does anyone know of such a module ?
  2. If non-existant, is a solution CPAN worthy ?
  3. If CPAN worthy, suggested names ? Working title is HTML::ListToJSTree (or maybe HTML::TOCtoJSTree ?)

Update
Done. See HTML::ListToTree.


Perl Contrarian & SQL fanboy

Comment on Convert nested list HTML TOC to JS Tree ?
Re: Convert nested list HTML TOC to JS Tree ?
by shmem (Canon) on Jun 03, 2007 at 09:55 UTC
    Nice hack.

    I'm not aware of a CPAN Module, but that's just me, and yes, I think it could be CPAN worthy. You might want to post the POD as a RFC meditation to get more feedback.

    But without looking at the source, I see two distinct tasks in your hack:

    • convert a nested HTML list into an internal tree (probably via some HTML parser)
    • output that tree as JavaScript code

    There are some modules which do the first part, not necessary with HTML input. Pod::Simple::SimpleTree comes to mind. I would suggest to provide the JavaScript generating via your module with interfaces to existing tree generating modules.

    On the name - maybe Tree::JS::dTree, since it could be used for other trees than just HTML lists?

    Minor nit - your converted page lacks the TOP id in the box div :-)

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Convert nested list HTML TOC to JS Tree ?
by trwww (Priest) on Jun 03, 2007 at 19:58 UTC
      Thnx for the links. I also found a use.perl.org entry reviewing Pod::POM::Web with a screenshot link. And then found several other solutions on CPAN. I'd forgotten about the Pod::POM namespace.

      But based on what I've seen thus far, Pod::ProjectDocs comes closest to what I'm after: a minimal solution to format the complete POD for a project, and that I can subclass for some add'l features I need. I don't really need/want a full webserver based solution, just the docs, and I'd rather not have to navigate an entire document model. With ProjectDocs, I can just grab or filter out what I need with a few regexen. Then just copy it up to a website for public consumption.

      Which leads me to think I've got 2 distinct issues:

      1. The general problem of converting nested HTML lists to a JS tree
      2. The specific issue of easing navigation of POD project docs
      (Note that if the nested lists were in their own div, or if the outermost list had a unique ID, the conversion could be done entirely in Javascript. But that much recursive Javascript in the browser makes me nervous).

      After some minor changes to my HTML nested lists hack, I successfully applied it to some other non-POD web pages in dire need of refreshing/easier navigation. Which also leads me to think that using HTML nested lists might be a nice notation for generating JS tree widgets, since the HTML would be pretty standard, whereas there are about 1,000,000 different JS tree widget APIs roaming the web.


      Perl Contrarian & SQL fanboy

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://618927]
Approved by Corion
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-08-20 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (105 votes), past polls