Skip to main content
RohitRojal
Participating Frequently
April 16, 2013
Question

Insert the line break in end of the all lines in the paragraph

  • April 16, 2013
  • 1 reply
  • 1146 views

Hi All,

I want to insert the line break in end of the all lines in the paragraph with javascript.

Rohit

This topic has been closed for replies.

1 reply

Vamitul
Legend
April 16, 2013

Hi!

This might be of help:

http://in-tools.com/article/scripts-blog/freeze-composition/

also a ancient script i wrote:

function isLetter(str) {

  return /^[a-z\u00C0-\u00ff]$/i.test(str);

}

function isBreak(str) {

  return /^[\u0021\u0022\u0023\u0025\u0026\u0027\u0028\u0029\u002A\u002C\u002D\u002E\u002F\u003A\u003B\u003F\u0040\u005B\u005C\u005D\u005F\u007B\u007D\u00A1\u00AB\u00B7\u00BB\u00BF\u037E\u0387\u055A\u055B\u058A\u05C3\u05F3\u05F4\u060C\u061B\u066A\u1806\u1808\u1809\u2010\u2011\u2012\u2013\u2014\u2015\u2018\u2019\u201A\u201B\u201C\u201D\u201E\u201F\u2032\u2033\u2034\u2035\u2036\u2037\u2039\u203A\uFF01\uFF02\uFF03\uFF05\uFF06\uFF07\uFF08\uFF09\uFF0A\uFF0C\uFF0D\uFF0E\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B\uFF3C\uFF3D\uFF3F\uFF5B\uFF5D\uFF65\d ]$/i.test(str);

}

function breakstory(myStory) {

for (a=myStory.lines.length-1;a>=+0; a--)

{

if (myStory.lines.characters.item(-1).isValid)

{

  if (isBreak(myStory.lines.characters.lastItem().contents))

    myStory.lines.insertionPoints[-1].contents = '\n';

if (isLetter(myStory.lines.characters.lastItem().contents) || myStory.lines.characters.lastItem().contents==SpecialCharacters.DISCRETIONARY_HYPHEN)

    myStory.lines.insertionPoints[-1].contents = '-\n';

   // else $.writeln(app.selection[0].lines.characters.item(-1).contents)

  

}}

}

for ( i=app.activeDocument.stories.length-1;i>=0; i--){

    breakstory (app.activeDocument.stories.item(i))}

RohitRojal
Participating Frequently
April 16, 2013

Hi Vamitul,

This script very helpfuly. Thanks a lot.

Rohit

BEGINNER_X
Legend
April 16, 2013

Hi Rohit,

Please see the below code, may it will be useful:

var myDoc = app.activeDocument

var myStories = app.activeDocument.stories.everyItem()

var myLines = app.activeDocument.stories.everyItem().lines.everyItem().getElements()

//~ alert(myLines.length)

for(i=0; i<myLines.length; i++)

{

    myLines.characters[-1].contents = "\n"

    }

Thanks

BEGINNER