[JS] Find hyperlinks in a block of text

Is there any way I can easily, given a block of text, find which hyperlinks have their SourceTexts inside that block of text, or overlapping it?
The only way I could think of was to loop through all the hyperlinks in the document and then check to see if any character in their SourceText was === to any character in the block of text we're searching.  That seems a little wasteful.

This works, but it's slow:
// Returns an array of Hyperlinks whose SourceTexts are
// contained within (or overlapping with) textObj
function checkHyperlinks (textObj, doc) {
  var foundLinks = new Array();
  var overlap;
  for (var linkIndex=doc.hyperlinks.length-1; linkIndex >= 0; linkIndex--) {
    overlap = false;
    var link = doc.hyperlinks[linkIndex];
    var linkText = link.source.sourceText;
    for (c=0; c < linkText.length; c++) {
      for (d=0; d < textObj.length; d++) {
        if (linkText.characters[c] == textObj.characters[d]) {
          overlap = true;
          break;
      if (overlap) break;
    if (overlap) {
      foundLinks.push (link);
  return foundLinks;

Similar Messages

  • Move a block of text from one document to another

    How to make a script moving a block of text from a defined area to next document?

    Here is the beast.
    --[SCRIPT exportTextBlocks]
    Save the script as a Script, an Application or an Application Bundle: exportTextBlocks.xxx
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
    Maybe you would have to create the folder Pages and even the folder Applications by yourself.
    select something in the source document
    menu Scripts > Pages > exportTextBlocks
    creates a new Pages document with the chunks of texts which where delimited by the markers.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    --=====
    Yvan KOENIG (Vallauris, FRANCE)
    26 avril 2009
    --=====
    Here it would be easy to edit it if required
    property marker : "______"
    on run
    my activateGUIscripting()
    tell application "Pages" to tell document 1
    set nDocSource to name
    set source to body text
    end tell -- Pages
    set source to my decoupe(source, marker)
    set extraits to {}
    repeat with i from 1 to ((count of source) - 1) by 2
    copy item (i + 1) of source to end of extraits
    end repeat
    copy "" to end of extraits
    set extraits to my recolle(extraits, marker & return)
    set destName to dateTimeStamp() & ".pages"
    set destDoc to my makeNewPagesDoc(destName, path to documents folder as text)
    tell application "Pages"
    set body text of document destName to extraits (* inserts the extracted blocks *)
    save document destName
    my selectIworkDoc(name, nDocSource) (* back to source document *)
    end tell -- Pages
    end run
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    on recolle(l, d)
    local t
    set AppleScript's text item delimiters to d
    set t to l as text
    set AppleScript's text item delimiters to ""
    return t
    end recolle
    --=====
    on dateTimeStamp()
    return (do shell script "date " & quote & "+P%Y%m%d-%H%M%S" & quote)
    end dateTimeStamp
    --=====
    on makeNewPagesDoc(n, d)
    local f, t
    set f to d & n
    set t to ((path to applications folder as text) & "iWork '09:Pages.app:Contents:Resources:Templates:Blank.template:") as alias
    tell application "Pages"
    open t
    save document 1 as n in file f
    end tell -- Pages
    return d as alias
    end makeNewPagesDoc
    --=====
    Use GUI scripting
    on selectIworkDoc(a, n)
    local m
    if a = "Pages" then
    set m to 9
    else if a = "Numbers" then
    set m to 10
    else if a = "Keynote" then
    set m to 11
    else
    error "The application “" & a & "“ is not accepted !"
    end if
    tell application a to activate
    tell application "System Events" to tell application process a to tell menu bar 1 to tell menu bar item m to tell menu 1 to click menu item n
    end selectIworkDoc
    --=====
    on activateGUIscripting()
    tell application "System Events"
    if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
    end tell
    end activateGUIscripting
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE dimanche 26 avril 2009 22:32:24)

  • Newbie Mac user:  Selecting block of text via the keyboard only?

    Hi,
    I'm switching over to a Mac from a PC and haven't been able to find an answer to this question. How do I select a block of text only by using the keyboard?
    As an example, on the PC from wherever the cursor is in a document, if I then hit Ctrl-Shift-end, the entire rest of the document from the cursor down is selected. Another similar task would be to select all of the text from the cursor to the end of the line, which on the PC can be done with Shift-end.
    Are there Mac equivalents?
    Thanks.
    Les
    MacBook Pro Mac OS X (10.4.10)
    MacBook Pro   Mac OS X (10.4.9)  

    COMMAND-SHIFT-end to select from the cursor to the end of the line. COMMAND-SHIFT-pagedown selects from cursor to end of document, use pageup to select entire document.
    Other alternatives:
    Press SHIFT and use the right arrow key to select characters. Use OPTION-SHIFT and right arrow to select words. COMMAND-right arrow key moves cursor to end of line and OPTION-right arrow moves cursor to next word.
    See also: Mac OS X Keyboard Shortcuts.
    In many instances wherever Windows uses CTRL in a shortcut the Mac uses COMMAND (Apple Key - ⌘)

  • Blocking Incoming Texts By Sender?

    I'm asking this for a friend who is receiving incoming SPAM texts. The only way I know to block incoming texts is to have your carrier disable texting totally. I couldn't find anything in the iOS 6.1 User Guide about blocking incoming texts.
    So, does anyone know if it is possible to do this or if there is an app that can do this?

    No, you misread what I posted. The first part of the sentence referred to all cariers employing a process whereby you can report spam messages. For AT&T that would be here, and there is no charge:
    http://www.att.com/esupport/article.jsp?sid=KB115812&cv=820&title=Block%20spam%2 0text%20messages%20on%20your%20wireless%20phone#fbid=ozLqTsdlTGL
    Since spammers frequently change the spoofed numbers they send with just blocking a single number will not generally work. If you want to block a number of that psycho ex-girlfriend AT&T has a service that lets you do so for a fee ($4.95 per month). I believe Verizon lets you do up to 10 numbers for free. This works for the psycho ex but not well for spammers.
    There is no fee to turn off all texting and I never said there was.

  • How can I access copy and paste history in iphone 4, absent some app, if I have copied another block of text before pasting the first?

    Is there ANY way to access the copy/paste history in iphone4 without an app? I have the latest verdsion of ios, and I'm using an iPhone 4... The issue arose when I copied a large, VERY large block of text, and then another before I pasted the huge one that took forever to hammer out and was unsaved by any other method, and now I really need it all back!!! Please help! Is there no "clipboard" or similar tool that remembers copied text history for a while, or am I SOL on this one? I can tell you this, as important as the lost words are to me, I don't think I could summon the energy or creativity to repeat it, so any suggestions would be greatly appreciated, and possibly rewarded with cupcakes and affectionate (albeit digital) hugs. Thanks in advance!

    I'm currently using Linux Fedora system.
    Doesn't matter. There's no standard way for D&D on Linux, no single API.
    Every application has its own mechanism which may or may not be compatible with any other.
    Gnome and KDE groups are doing some work to provide a common standard but as you know the Linux zealots are completely opposed to anyone telling them what to do (such as creating standards) and won't in general follow them.

  • Find hyperlinks in pdf's

    How can I find hyperlinks in pdf's? We have an external service which checks hyperlinks in our pdf's but does not tell you the location of them, so I know I may have an invalid link but can't find it. Any help at all would be appreciated

    Select the link tool and then the links should become visible.  Of course if they're links that Acrobat makes automatically because it finds a web address you'll have to do a search for www. or http:

  • Update 4.1.2 deleting large blocks of text following backspace correction

    OK, this is a difficult for me to explain, but here goes nothing.  I have been having an issue since the update.  When typing a message, when I backspace to correct a wrong word/spelling, and then select the correct word from the predictive text bar, most of my message gets erased and replaced with the one word I selected.  Even weirder, the word gets inserted in between the few characters of remaining text.  The first couple times it happened, I thought I had accidentally selected the block of text with my cursor, but that was not the case.  The text is not selected, but acts as though it is and gets overwritten/deleted.  This is happening in Messaging and Gmail (and I am assuming all other typing applications).
    Is anyone else having this issue?  It is making me wan to throw my phone out the window!  Please let me know if you know a fix for this.

    Mine is doing the same thing!  I got the update last night and it is deleting practically my entire message when I backspace.  Also, the puncuation options do not pop up anymore like they used to at the top of the keyboard unless you hit space and then backspace. 
    I'm right there with you...I want to throw this thing out the window.  I've seen some cool things this update did, but things I hardly ever would use.  The fact it messed with my texting (something I do a lot) has really ****** me off.

  • How do I delete a block of text on my IPad. For example, when I want to forward an email

    How do I delete a block of text on my IPad. For example, when I want to forward an email & want to delete the previous sender's info.

    OK, Duh...press and hold on the text and a small menu will pop up. Then use Select, Select All, or just drag the blue handles to select the text you want.

  • Speaking selected blocks of text in preview

    Hello everyone.
    Hi, I am a fan of Speech functionality and use 'Start Speaking' in Preview for reading blocks of text back to myself.  Whatever text was selected is what would be read.  Now suddenly, every time I try to do this, it starts reading from the start of the document, regardless of what is selected. I discovered that selecting View > PDF Display > Single Page instead of Single Page Continuous makes it at least start reading from the beginning of the page I am on, but this is still annoying in most cases.  The behaviour works as before in web browsers, but not Preview.
    Any idea why this is? Did I change something? Why would the behaviour suddenly change?
    Thanks

    Never mind , a post in the sidebar answered the question.

  • Any way to block spam texts like blocking a ph #?

    Is there some way to block incoming texts addresses? Am I missing something? When I press on the text address, I'm not seeing a "Block" option, just the ability to Delete it.

    There are a lot of phone/message blockers like the one above by SamZTB. Mr Number is probably one of the most popular. I personally use Call Blocker. You can set up White and Black lists and I just have it block all calls and texts not in my contacts list. The only thing I didn't like is that it nags you to buy it when you start or stop it. It was worth buying it to me though. Just do a search for call blockers. Many also include  a caller ID.
    There are a lot, so good searching.
    Pat

  • Using nested styles to break blocks of text into different pages

    Hello everyone,
    I'm treating data collected through a Google Docs form and I've already set it up so that the questions appear on the left and are followed by the respective answers sequentially so that I have a simple way to copy paste the whole information to Indesign. Then I'm going to use nested styles to define individual styles for the questions and answers.
    What I can't do, however... and I'm not even sure if it's possible, is how to tell Indesign to break text that is laid out sequentially into different lines or to break blocks of text so that they start in the beggining of the next page without having to resize the text frames by hand.
    As a visual example this is what the data I've exported out of excel looks like:
    Question 1 (tab) Answer A1 (line break)
    Question 2 (tab) Answer A2 (line break)
    Question 3 (tab) Answer A3 (line break)
    Question 1 (tab) Answer B1 (line break)
    Question 2 (tab) Answer B2 (line break)
    Question 3 (tab) Answer B3 (line break)
    (and so on in groups of 3 questions)
    And I want to turn it into:
    Question 1 (turn the tabs into line breaks)
    Answer A1
    Question 2
    Answer A2
    Question 3
    Answer A3
    (and then start at the beggining of a new page)
    Question 1
    Answer B1
    Question 2
    Answer B2
    Question 3
    Answer B3
    I can't define the size of the text frames so that the next group of questions+answers starts at the beggining of a new page because some of the answers are multi-line fields and thus the number of lines of the answers are variable and they can come short of the text frame edge or pass it.
    Can anyone share some insight of how to do this (or if it is at all possible)?
    Thank you very much!
    MACC

    Thank you very much for your input.
    I'm trying to automate this process as much as possible because I don't want to have to crunch the data manually myself later on, instead just teach someone else how to do it.
    The first search and replace action seems basic enough but regarding the second one I would have to manually assign that paragraph style to the line where the data would break because one can only assign character styles in nested styles, right?
    Also I've heard that ID CS5 automatically creates new pages based on a template when you paste information inside the first page, is that so? That would be great because that way the person wouldn't have to manually create pages and link the contents throughout the document but instead simply open my template and paste the information within the first master page. That's not possible with CS4, is it?
    Thank you very much!

  • Possible to modify blocks of text as defined by Touch Up Text tool?

    I have scanned a document and OCRed it. Using the Touch Up Text Tool, I can approach the text, but the text areas are not as defined by the tool. Is there a way to modify a block as defined? I.e. There is a heading over 2 columns of text. The OCR process defined this as one block of text.

    Thank you very much for your input.
    I'm trying to automate this process as much as possible because I don't want to have to crunch the data manually myself later on, instead just teach someone else how to do it.
    The first search and replace action seems basic enough but regarding the second one I would have to manually assign that paragraph style to the line where the data would break because one can only assign character styles in nested styles, right?
    Also I've heard that ID CS5 automatically creates new pages based on a template when you paste information inside the first page, is that so? That would be great because that way the person wouldn't have to manually create pages and link the contents throughout the document but instead simply open my template and paste the information within the first master page. That's not possible with CS4, is it?
    Thank you very much!

  • Syncing a Block of Text Between Two Documents

    I use Word 2011 on my Mac and I have two rather long MS Word documents (call them A and B) that are completely different from one another except for one block of text (call it C) which is the same in both documents. If Pages is capable of doing what I am describing below I will transition to that platform.
    The contents of C need to change frequently and I am looking for a way to ensure that if I make a change to C in A it automatically makes that change in B and vice-versa. I would need changes to any other type of content associated with C, such as footnotes, to remain consistent between A and B as well. I've tried googling around but don't even know what a feature like this would be called.
    Thanks in advance,

    Pages doesn't have the feature. Yo can download and read the Pages User Guide from http://www.apple.com/support/pages/  to learn more about Pages

  • How can I remove multiple hyperlinks from a slab of text?

    Hi everyone,
    I copy a lot of text from websites into Pages documents, and I'm looking for a way to remove multiple hyperlinks from a slab of text all at once without having to remove each hyperlink individually? This would save me a lot of time!
    Not sure if Pages actually has this feature - if not then it would be a good feature request. It would be similar to MS Word's function to clear a slab of text of all formatting (including hyperlinks).
    Any tips would be much appreciated!
    Thanks,
    -Chris

    Select all the text concerned. Then:
    This will stop them being live links but they will probably be blue and underlined. Click the underline button twice, and use the colour selector to turn them black.

  • Can I cut, copy and paste a block of text in PL/SQL Developer?

    I have been using TextPad to put together SQL statements by using the cut, copy and pasting of BLOCKS of text.
    Example:
    I copy the describe of a table, replace varchar, number, date will 10 spaces and then copy the column names in a block and paste it further down the TextPad.
    Then I join the lines into one string, replace the spaces with commas
    Then I insert in front of the column name the INSERT INTO table_name(
    Then I get the values by copying from somewhere else and paste then in block text where they need to go. ETC, ETC.
    Thank you, Bill

    In 2.0 you should be able to just type
    INSERT INTO emp(
    and do multiple selections from code completion list of suggested emp columns (by holding ctrl or shift key). Same for "select" and "from" clauses (with optional auto aliasing).

Maybe you are looking for

  • Problem after deleting the records........

    Hi Folks, Kindly help me with this report. At one point I am deleting the itfinal internal table w.r.t to HKONT.Before deleting I am having all the values for LIFNR and AWKey,but once deleting(as mentioned earlier) I am not getting these two values.T

  • My phone fell down on the floor and shutt off not working again

    my phone fell down on the floor and shutt off not working again

  • Genius in iPod classic 80GB ? Is it working?

    Hi everyone I am new here with my first 'issue' of my ipod. I always thought I can use geniuas with my ipod classic until I actually started to using it. I cannot see any option called genius in my ipod classic 80GB. Is something wrong with my ipod o

  • Standby ACE unresponsive

    Hello, My standby ACE has gone to unresponsive mode and shows something like this peer state: FSM_FT_STATE_UNKNOWN This is for all the contexts in the slot module. My question is how do we bring it back to HOT_STANDBY when all contexts are unresponsi

  • Itunes deleted my playlist?

    So apparently when you delete a playlist on your iPhone it deletes that same playlist in iTunes. I thought it was the other way around? Long story short I was recording a video and needed more memory to record so I deleted the playlists on my iphone