Re: need a newline between paragraphs....



On Wed, Nov 25, 2009 at 01:08:39PM -0700, Chad Perrin wrote:
On Tue, Nov 24, 2009 at 01:19:42PM -0800, Gary Kline wrote:
On Tue, Nov 24, 2009 at 01:07:41PM -0700, Chad Perrin wrote:

precisely. in this case, every paragraph that is not on a
newline wraps. so anything that has an EOL is a new
paragraph.

If I understand you correctly, the following should work for your
purposes (as a naive implementation of the concept):

my $contents;

{
undef $/;
open(my $fh, '<', $in_filename) or die $!;
$contents = <$fh>;
}

$contents =~ s/\n+/\n\n/g;

{
open(my $fh, '>', $out_filename) or die $!;
print($fh $contents);
}

That assumes that you want to turn any and all instances of one or more
consecutive newlines into exacty two newlines. More finagling might be
required if there may be other adjacent whitespace, which would need to
account for not only possible adjacent whitespace but also possible
whitespace at the beginning of a line with other text on it. Maybe
something like this:

$contents =~ s/\s*\n+/\n\n/g;

. . . though I haven't thought it through in too much depth with regards
to the implications in edge case circumstances (thus the "naive
implementation" comment above).


Turns out that the problem was resolved by the

print $fh "$_$/"; or close to that. Since I scrubbed 100% of
newlines -- and axing all whitespace before and after lines --
before handing off the large file to OpenOffice, there wasn't
any concern about extra whitespace messing stuff up.


there are a few places that require different formatting;
these are easily re-done thanks to OOo!

I'm the kind of guy who would look for a way to automate things so that
re-formatting in OOo wouldn't be necessary, but as long as you're happy,
I guess we win. Good luck!


Hm. Y'know, if *somebody* would just make having vim as an
option along with OOo, along with wrapping all the lines, life
would be (abs)Perfect. I would nevr complain about anything;
not ever.

My fingers know vi; I've used vi since BillJoy invented it and
handed me the first docs. It only took a couple weeks to
learn, and I still don't know all the tricks. But enough to
do what I *NEED* to, and with fewer fumbles _(or hurting my
arm/shoulder that using the word-processor with mouse + keybd).

having scripts to switch between file and file.txt|.odt gets
pretty close :-)

thanks much,

gary



--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]



--
Gary Kline kline@xxxxxxxxxxx http://www.thought.org Public Service Unix
http://jottings.thought.org http://transfinite.thought.org
The 7.31a release of Jottings: http://jottings.thought.org/index.php

_______________________________________________
freebsd-questions@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: need a newline between paragraphs....
    ... every paragraph that is not on a ... purposes (as a naive implementation of the concept): ... consecutive newlines into exacty two newlines. ... required if there may be other adjacent whitespace, ...
    (freebsd-questions)
  • Re: Wild Card Search II
    ... >> Search for a paragraph starting with some letters followed by "." ... >> Include whitespace after ".": ... >> Apply the formatting to the result. ... >> Sub Test661 ...
    (microsoft.public.word.vba.general)
  • Re: Wild card Help II
    ... Search for a paragraph starting with some letters followed by "." ... Include whitespace after ".": ... Sub Test661 ... .MatchWholeWord = False ...
    (microsoft.public.word.vba.general)
  • Re: newlines with XmlTextWriter
    ... nodes at the bottom where whitespace is significant. ... I have a feeling that if there are any newlines in the tree (or maybe any ... and it only puts its own in if there are none at all in the DOM. ... Can you give an example of the formatting you want? ...
    (microsoft.public.dotnet.xml)
  • Re: problems with making wordwrap
    ... white space at the beginning of new lines. ... but whitespace within a line ... The first gsub replaces newlines inside of paragraphs into spaces, but leaves newlines between paragraphs unchanged. ...
    (comp.lang.ruby)