HTML::FormatText does exactly what you want.
#!/usr/bin/perl use strict; use warnings; use utf8::all; use HTML::FormatText; use HTML::TreeBuilder::XPath; my $page = q{ <div class="contents"> &#160;<ul> <li>ChainCtrlBuildChain() : <a class="el" href="_chain_controller_8c.html#acb2c56087a2072b6445 +a54c17662d118">ChainController.c</a> </li> <li>ChainCtrlDumpChain() : <a class="el" href="_chain_controller_8c.html#a13ed5a02bf232b115b9a5 +8cdd13dadd7">ChainController.c</a> </li> <li>ChainCtrlExit() : <a class="el" href="_chain_controller_8c.html#a9e30e46ebc5411537efe9 +5a286e27cb4">ChainController.c</a> </li> <li>ChainCtrlGetBitStreamChan() : <a class="el" href="_chain_controller_8c.html#a00faa6e64ea466d4ec573 +39017e57e71">ChainController.c</a> </li> <li>ChainCtrlInit() : <a class="el" href="_chain_controller_8c.html#aed300a388eff2fa9c7565 +025982faab1">ChainController.c</a> </li> </ul> </div><!-- contents --> }; my $tree = HTML::TreeBuilder::XPath->new_from_content($page); my(@trees) = $tree->findnodes('//div[@class="contents"]'); foreach $tree(@trees) { my $formatter = HTML::FormatText->new( leftmargim => 0, rightmargin => 50, ); print $formatter->format($tree); }

In reply to Re: using TreeBuilder in perl by Khen1950fx
in thread using TreeBuilder in perl by anirban0328

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.