Skip to main content
The Gothamite
Known Participant
January 21, 2014
Answered

Move URLs in Text to End of Story Or Link Text. Also: Tables

  • January 21, 2014
  • 1 reply
  • 2457 views

Hello everyone

I'm currently working on a script that translates Textile Markup into formatted InDesign-Text. This worked fine for the most part, seeing as it's not really hard to do by FindChangeByList. Some things are a bit trickier than other things, though. Namely URLs in the text. In Textile, all URLs are like so. Let's say I'd like to link to Google. So I'd type this: "Google":http://www.google.com This would produce Google. I can isolate the word and delete the URL by [\\\"](.+?)[\\\"]:\\?\\S+ and then replacing by $1. So far so good.

However!

It would be awesome, if the URLs were still in the text. So I'd either like to have it like so: Google or that the word Google (or any $1, really) stands in the text and then the link is added to the end of the text as a kind of "Sources"-paragraph-thing. How can this be done? Can I do it by FindChangeByList? Because that would be cool, seeing as then I'd only need to run one script.

And here's a general question: How can I translate Textile-Tables into Formatted InDesign-Tables?

For reference, this would be a table with one header row.

|_. name |_. age |_. sex |

| joan | 24 | f |

| archie | 29 | m |

| bella | 45 | f |

Can this be done?

Thank you very much for your help!

This topic has been closed for replies.
Correct answer Jump_Over

Wow, this works like a charm. You really are awesome at this. Also, sorry I was away, I suddenly found myself swamped in work and didn't have time to attend to this thing which isn't due until the 17th.

There's one little flaw in this that I can see. Links in our writings can look something like this: "Try it out on Google":www.google.com and of course, if you're going "Link first word to second word" then that won't really work. Any ideas on how I can tackle that? Also, I'd like to apply a characterstyle to the finished hyperlink. Can this be done?

EDIT: I just managed to apply a character style. I'm a twit. The script now begins with

function textile_link(){

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = "[\\\"](.+?)[\\\"]:(http\\\S+)";

app.changeGrepPreferences.changeTo = "$1\t$2";

app.changeGrepPreferences.appliedCharacterStyle = "URL";

and the rest is (thus far) identical to yours.

EDIT II: I've looked at what I need from a sort of general standpoint: I need the script to make a hyperlink that displays as $1 and links to $2,


Hi,

OK. If you can assume that $2 is  exactly one word ==> we could modify above like this:

//...

mSource = mDoc.hyperlinkTextSources.add(mText[0].words.itemByRange(0,-2).texts[0]);

mDest = mDoc.hyperlinkURLDestinations.add(mText[0].words[-1].contents);

//...

Jarek

1 reply

Jump_Over
Legend
January 21, 2014

Hi,

In case of translating to table for mText (if it refers to your example) use this:

mText.convertToTable("|","\r");

In case of URLs in text you can not use find...replace method, I am afraid.

With more info it could be done with some "move_function ()" or "hyperlink_function ()" which can be involved after doc.findGrep() prepares an array with parts of texts.

Jarek

The Gothamite
Known Participant
January 22, 2014

Thanks, Jarek

I don't think I'll have the time to test this today, but I'll get around to it. I had one odd thought, though, thinking along the lines of Find/Replace again. What if I did this?

Find: [\\\"](.+?)[\\\"]:(http\\S+)

Replace: $1 .+ $2

Or something along those lines in general? Would that work?

Jump_Over
Legend
January 22, 2014

Hi,

You cant use wildcards (".+") for Replace, at sure.

I am still not sure about your goal but you could test something alike:

find: (...)(...)(...)     word - url - rest_of_para

replace: $1$3$2

Jarek