Loading ...
Sorry, an error occurred while loading the content.

321Re: Smart/intelligent text formatting

Expand Messages
  • acummingsus
    Sep 26, 2005
      --- In ntb-scripts@yahoogroups.com, "rpdooling" <rpdooling@y...> wrote:
      > Alan,
      >
      > >>is there another script that can be run afterwords to remove the
      > hard paragraph breaks at the end of each line?<<
      >
      > Never mind. Sorry. Select All. Join lines. Duh.

      (new clips are enclosed at bottom)

      Well, if you'd rather be lazy and have Perl do the work instead, I had
      also needed to add a modification anyways. So, new mod/update
      included below, here goes:

      Hi Rick,

      I'm not sure wether you want all lines joined or only want consecutive
      (so to speak) lines joined.

      At doc for Text-Autoformat:

      http://search.cpan.org/~dconway/Text-Autoformat-1.13/lib/Text/Autoformat.pm

      I couldn't locate any option to run lines together.

      But to do so, join lines, is very easy to do with the Perl
      substitution operator:

      s///; <- skeleton of such/said operator

      s/-2Breplaced-/--replace_with_this--/any_option(s)_go_here;

      Look at bottom where clips R included herein for: # newly added line

      It uses substitution operator to join *all* lines together (replaces
      with a space). If do not want that then remove the plus character

      +

      remove that + makes it do only one line break at a time rather than
      multiple consecutive line breaks at each_time/spot (note: the g for
      global option is used, thus each "spot/time/occurrence").

      Also in clip below, look for: <new>

      I meant to re post and do that a while back but forgot to do so.

      Yet even more: the all option makes it process all text passed to it

      my $formatted = autoformat($rawtext, {all=>1});

      my $formatted = autoformat($rawtext);

      if do like that latter, without the all option, then it processes only
      the first paragraph of text even if you pass it multiple paragraphs.

      I just now discovered this next url for the first time:

      http://search.cpan.org/~abw/Template-Toolkit-2.14/lib/Template/Plugin/Autoformat.pm

      A template interface to text-autoformat. (make my own templates for
      to have available the output of various and different format
      patterns). Pick/choose a template to run according to a particular
      desired output format.

      Goodness, as to the amount of possibilities that exists here!

      Probably a caution I should previously had is to work up to (biggest,
      huge file size). (I'd guess it means above a few megabytes in file
      size)-- most common texts don't get up to near that big at all.

      My intent so far for myself equate to use it for formatting email
      replies and similar where the size of text is not overly huge. It
      slurps an entire file into memory/ram. And, ram is finite though it
      typically takes an overly huge file size in order to bring any
      problem. This slurping is commonly something that's done. But there
      can be a type of a situation (*really* huge file) where some other
      solution (such as tie, etc.) would be preferred.

      Alan.

      Dear Alan:

      The text::autoformat works great, but it puts a hard return at the end
      of each line. Is there an option or something that can be set to avoid
      that? Alternatively, is there another script that can be run afterwords
      to remove the hard paragraph breaks at the end of each line?

      Thanks

      Rick

      --- In ntb-scripts@yahoogroups.com, "acummingsus" <acumming@c...> wrote:
      > Text::Autoformat
      >
      > been using that Perl module on Linux. Impressive.
      >
      > http://search.cpan.org/~dconway/Text-Autoformat-
      > 1.13/lib/Text/Autoformat.pm
      >
      > There's a bit of doc and what it will do.
      >
      > I just installed that module on my Win 2k and works super in Notetab.
      >
      > ppm equals perl package manager
      >
      > http://www.google.com/search?q=ppm+repositories
      >
      > bribes a ppm repository has Text-Autoformat (mine Windows Perl is
      > Activestate Perl 5.8.X) (Additionally I also saw the module there for
      > Perl 5.6.X)
      >
      > ppm> help
      >
      > ppm> help repository
      >
      > ppm> rep add bribes http_url_2_the_bribes_repo
      >
      > ppm> search text-autoformat
      >
      > ppm> install text-autoformat
      >
      > ppm> quit
      >
      > line length default of 72 char lines for now (well, 2 code lines
      > R with "all" so U can comment the one and un comment the other
      > line containing "all" which provides two choices of formatting).
      > May develop it more with more choices, bells, and whistles. Two
      > clips next:

      H="t_a_format"
      ^!RunPerl taform

      H="_taform"
      #!perl -w

      use strict;
      use Text::Autoformat;
      my $rawtext;

      # ----------------<new>----------------------------
      # <depracated>
      # while (<DATA>) {
      # while (<>) {
      # $rawtext = "$rawtext$_";
      # }
      # </depracated>

      {
      # file slurp method. Significantly beats depracated
      local( $/ ) ; # faster than while loop. This
      $rawtext = <> # just slurps file into scalar variable
      }
      # ------------------</new>-------------------------

      # my $formatted = autoformat($rawtext, {left=>20, right=>60, all=>1});
      my $formatted = autoformat($rawtext, {all=>1});
      # my $formatted = autoformat $rawtext;

      # newly added line is next (joins lines)
      $formatted =~ s/\n+/ /g;
      print "$formatted\n";
      # print "\n$rawtext\n"
      # ----end----

      >
      > Thanks for the tip on autoformat..

      You're welcome.

      I ran across it from somewhere Perl out there. I found it interesting.

      --
      Alan.
    • Show all 19 messages in this topic