This content has been marked as final. Show 14 replies
>squares in the name of the bookmark. Am I doing something wrong.
No. Bookmarks are designed to hold simple text only -- no formatting, font, or (indeed) tabs and other special spaces. I solve this by storing the text in a string, replacing all of these with a simple single space, and using the string as bookmark name.
>What is the correct way to point to a specific paragraph? Do i make a hyperlinkTextDestination (the InsertionPoint) first and assign the bookmark to it?
It is a bit confusing. I remember going through it line by line until it finally worked. This comes from my code:
h = app.activeDocument.hyperlinkTextDestinations.add(theStory.paragraphs[i]);
bm = level2bm.bookmarks.add(h);
bm.destination.name = "Hi!";
bm.name = "Actual text for the bookmark";
Thank you for your help!!!
I still have one more question.
What is the best way to do replacements in a string? (For changing the special spaces and tabs to a simple space)
To replace all kinds of spaces to 'normal' spaces, do this:
s = s.replace (/\s+/g, " ");
\s matches all white space, including em- and en-spaces, tabs, and returns.
That's exactly what I meant. Cheers, Peter!
Thanks Peter and jongware!
Is there also a possibility to replace XML-Tags? Otherwise there are plenty of squares in the bookmark-name. :-/
Sure. For some reason, XML tags are substituted with 0xFEFF when converted to JS strings (both open and close tags). Knowing that,
>s = s.replace (/[\s+\ufeff]/g, " ");
should do the trick. [Untested.]
Right! Tags are coded as "0xFEFF"! <br />But with your suggestion you just find "e" and "f"!?<br /><br />... I already tried <FEFF> but this failed too!? :-(<br /><br />:-)<br />M.
Nope, didn't work at all!?
As I said,
>you'll have to find an alternative way [..]
Some (a lot) educated guesses later:
>s = s.replace (/\uFEFF/g, "");
Many thanks, Jong!
... and sorry, I read your last answer too fast!
Now I've got another issue: I didn't found a method to sort the bookmarks? Did anyone got an idea how to solve this problem? ... my bookmarks are pretty messed up! :-/