<?xml version="1.0" encoding="windows-1252"?>
<node id="606820" title="Re: Drop formatting to paste plain text from Clipboard" created="2007-03-27 14:01:47" updated="2007-03-27 10:01:47">
<type id="11">
note</type>
<author id="245320">
chanio</author>
<data>
<field name="doctext">
Actually, I am fond of these simple tasks that can make our lives easier...&lt;p&gt;
When I call this script I use to mention one or two arguments that would make additional effects to the text...&lt;p&gt;
The following code, adds some formating to the text. By default, it writes columns of 60 characters. But it is possible to specify any number of columns.
    &lt;code&gt;
   
	my $cant;
	$cant =shift || 60 ;        ## DEFAULT: 60 COLS.
	use Text::Format;

	my $anco;		          ## 1ST.LINE LEFT MARGIN
	$anco = length($1)  	if ($text=~/^( +)/);## MARGIN? 
	$anco = 0 		if ($anco &lt; 1 or 
 	                            $anco &gt;= $cant);## ERROR?
	$cant -= $anco;		 ## FORMAT WITHOUT LEFT MARGIN TO ADD
	
	my @tod = (split(/\n+ */,$text));
	$text=new Text::Format({  columns =&gt; $cant,
				  text =&gt; \@tod, 
				  justify =&gt; 1, 
				  firstIndent =&gt; 0}); 

	$result.= join(" ", ($text-&gt;paragraphs()));
	
	if ($anco)		         ## FORMAT WITH 1ST. LINE MARGIN...
	{
		@tod= (split(/\n+ */,$result));## GET EVERY LINE
		my $cant= ' ' x $anco;           ## LEFT MARGIN IN SPACES
		$result = $cant.
			  join("\n$cant",@tod);  ## ADD LEFT MARGIN AND OUTPUT
	}
	$CLIP-&gt;Set($result);			## TO THE CLIPBOARD...

    &lt;/code&gt;
I can also transform plain text into HTML code, extract certain phrases with REGEX, 
transform the text into a commented block, unescape characters or escape them, 
sort the lines, turn them all into upper/lowercase and even eval some code
while leaving it's result as the output.
  &lt;p&gt;
This is what I call a useful toolbox..
&lt;p&gt;&lt;!-- BORRAME --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-245320"&gt;
&lt;ul&gt;&lt;li&gt; &lt;i&gt;Landlords production is only eaten by landlords...&lt;/i&gt;&lt;p&gt;
&lt;li&gt; [http://knopper.net/knoppix/index-en.html|Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established]&lt;/ul&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
605154</field>
<field name="parent_node">
605154</field>
</data>
</node>
