AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Solved] Problem with Unwrap script

 
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English)
View previous topic :: View next topic  
Author Message
foliator



Joined: 13 Nov 2011
Posts: 23

PostPosted: Mon Oct 07, 2013 1:40 am    Post subject: [Solved] Problem with Unwrap script Reply with quote

I use the script Unwrap.js very often for stripping out unwanted line breaks in order to reflow paragraphs, but it frequently leaves line breaks in the middle of some paragraphs. Using the special characters plugin I can see the CR/LFs and eliminate them, but in a long document that takes a lot of time. Does anyone know what would cause the problem, and is there a way I can solve it without debugging the script? I have no experience working with JavaScript.

BTW, this problem has never disappeared after updating AkelPad.


Last edited by foliator on Wed Oct 09, 2013 2:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5359

PostPosted: Mon Oct 07, 2013 5:59 am    Post subject: Reply with quote

foliator
Unwrap.js? Probably this is old name of LinesUnwrap.js. If yes, can you write with what concrete text you have problems.
Back to top
View user's profile Send private message Send e-mail
foliator



Joined: 13 Nov 2011
Posts: 23

PostPosted: Mon Oct 07, 2013 3:04 pm    Post subject: Reply with quote

Yes, it's the same script; I think I must have renamed it. Here's a small example. Below is a single paragraph from a Gutenberg text file of Charles Dickens' Tale of Two Cities. I've used the script on it while posting this message and pasted in the results. Hopefully the forum's input form won't change it when I post this.

1) The original paragraph, with its CR/LF at the end of each line:

All these things, and a thousand like them, came to pass in and close
upon the dear old year one thousand seven hundred and seventy-five.
Environed by them, while the Woodman and the Farmer worked unheeded,
those two of the large jaws, and those other two of the plain and the
fair faces, trod with stir enough, and carried their divine rights
with a high hand. Thus did the year one thousand seven hundred
and seventy-five conduct their Greatnesses, and myriads of small
creatures--the creatures of this chronicle among the rest--along the
roads that lay before them.

2) The paragraph after using the script. As you can see, it's only partly unwrapped:

All these things, and a thousand like them, came to pass in and close upon the dear old year one thousand seven hundred and seventy-five.
Environed by them, while the Woodman and the Farmer worked unheeded, those two of the large jaws, and those other two of the plain and the fair faces, trod with stir enough, and carried their divine rights with a high hand. Thus did the year one thousand seven hundred and seventy-five conduct their Greatnesses, and myriads of small creatures--the creatures of this chronicle among the rest--along the roads that lay before them.
Back to top
View user's profile Send private message
Drugmix



Joined: 08 Apr 2013
Posts: 424

PostPosted: Mon Oct 07, 2013 4:03 pm    Post subject: Reply with quote

I think the script doesn't transform cr/lf after a dot into a dot and a space after it.

If it would - then all the text would be transformed into a single paragraph.
The problem is: how to distinguish the end of a paragraph from a the end of a sentence in the middle of a paragraph?

The only idea is to transform the initial text so that paragraphs are separated with TWO new line characters.
Back to top
View user's profile Send private message
foliator



Joined: 13 Nov 2011
Posts: 23

PostPosted: Mon Oct 07, 2013 4:47 pm    Post subject: Reply with quote

Drugmix wrote:
I think the script doesn't transform cr/lf after a dot into a dot and a space after it.

If it would - then all the text would be transformed into a single paragraph.
The problem is: how to distinguish the end of a paragraph from a the end of a sentence in the middle of a paragraph?

The only idea is to transform the initial text so that paragraphs are separated with TWO new line characters.

Actually, the rest of the paragraphs in that file are already separated that way, just the way the paragraphs look in this post. If I highlight several paragraphs in the file, they unwrap separately too, but the task is not fully completed. As an experiment I took several paragraphs and added yet another new line character to the end of each one. I still had the incorrect result. The paragraphs were properly separated, but not fully wrapped.

Naturally it would be unwise to use a script like this on an entire document in one operation, anyway, because there may be some lists or poems that have very short lines; they would wind up as paragraphs. Been there, done that -- undid that. Laughing
Back to top
View user's profile Send private message
Instructor
Site Admin


Joined: 06 Jul 2006
Posts: 5359

PostPosted: Wed Oct 09, 2013 5:10 am    Post subject: Reply with quote

foliator
Remove ".?!:;" from paragraph's delimiters:
Code:
  //Unwrap lines
  //pSelText=pSelText.replace(/([^.?!:;\n])\n[ \t]*([^\n])/g, "$1 $2");
  pSelText=pSelText.replace(/([^\n])\n[ \t]*([^\n])/g, "$1 $2");
Back to top
View user's profile Send private message Send e-mail
foliator



Joined: 13 Nov 2011
Posts: 23

PostPosted: Wed Oct 09, 2013 2:37 pm    Post subject: [Solved] Problem with Unwrap script Reply with quote

Instructor wrote:
foliator
Remove ".?!:;" from paragraph's delimiters:
Code:
  //Unwrap lines
  //pSelText=pSelText.replace(/([^.?!:;\n])\n[ \t]*([^\n])/g, "$1 $2");
  pSelText=pSelText.replace(/([^\n])\n[ \t]*([^\n])/g, "$1 $2");

Thank you, Instructor, that fixed it. The script now works perfectly, even on a large portion of text with lots of paragraphs! Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Discussion (English) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group