-
1. Re: [JS CS4] insertionPoints problem
pkahrel Sep 23, 2010 8:55 AM (in response to Skempy)Something like this maybe:
if (myPar.characters[-1].contents = "\r")
myPar.contents = myPar.contents.replace (/.+/, "\r");
else
myPar.contents = "";
Peter
-
2. Re: [JS CS4] insertionPoints problem
[Jongware] Sep 23, 2010 12:19 PM (in response to pkahrel)Peter, any idea why this doesn't work?
myPar.contents = myPar.contents.replace (/.+$/, "");
It seems for Javascript the final returns are included in the string, whereas with GREP S&R it leaves them.
(Feel free to call it an "implementation difference".)
-
3. Re: [JS CS4] insertionPoints problem
Marc Autret Sep 23, 2010 2:46 PM (in response to [Jongware])I think this should work in any case:
myPar.contents = myPar.contents.replace(/[^\r]+/,"");
@Jongware
myPar.contents = myPar.contents.replace (/.+$/, "");
doesn't work because the regexp /.+$/ matches the whole myPar.contents string, including "\r" which ends any paragraph (except the last one in the story). By the way, /.+$/ is exactly the same as /.+/, since the dot matches any character and the plus is greedy.
In GREP the behavior of .+ is usually different because the single line mode is OFF by default, which means that the dot matches any character except the paragraph end mark. But if you revert the single line modifier in GREP:
(?s).+
then you grab the entire text available*, like /.+/ does in JavaScript RegExp.
* This rule has an exception mentioned by Laurent Tournier in its GREP & InDesign French book: (?s).+ will break on any footnote call (!)
@+
Marc
-
4. Re: [JS CS4] insertionPoints problem
[Jongware] Sep 23, 2010 2:53 PM (in response to Marc Autret)Marc: Would the multiline flag 'm' as mentioned on http://www.websina.com/bugzero/kb/regexp.html make my suggestion work?
(Sorry, busy with sth else & no time to try myself )
-
5. Re: [JS CS4] insertionPoints problem
Marc Autret Sep 23, 2010 3:15 PM (in response to [Jongware])Yeah, it's a good idea, but the /m modifier makes ^ and $ break on the "\n" character on Windows platforms (I don't know how it behaves on Mac...).
As InDesign uses "\r" in paragraph termination, /.+$/m won't work as expected...
-
6. Re: [JS CS4] insertionPoints problem
pkahrel Sep 24, 2010 1:46 AM (in response to [Jongware])myPar.contents = myPar.contents.replace (/.+$/, "");
This was my first try, too, and I was surprised to see that that didn't work. I'm sure it should work: . matches everything except line ends, and surely \r is a line end. As Marc said, it looks as if \n is seen as a line end, \r is not. I've run into that problem before.
Marc's solution works fine, though!
Peter
-
7. Re: [JS CS4] insertionPoints problem
Skempy Sep 24, 2010 2:19 AM (in response to Marc Autret)Peter, Marc, Jongware,
Thank you all for your replies, I doubt there could be a better set of Scripting brains involved in my problem.
Marc's
myPar.contents = myPar.contents.replace(/[^\r]+/,"");
almost achieves what I need, but this results in the Paragraph Style of the deleted text being applied to the following paragraph.
Simon.
-
8. Re: [JS CS4] insertionPoints problem
Skempy Sep 24, 2010 4:16 AM (in response to Skempy)This seems to work...
if (myPar.characters[-1].contents == '\r') {
myPar.insertionPoints.itemByRange(0,-2).contents = ""
}else {
myPar.contents = ""
}A slight modification of Peter's code but leaving the original end of paragraph instead of replacing it (which picks up the formating from the following paragraph).
I do, however, like the idea of a Grep replace statement if anyone can get one to work.
Thanks
Simon.



