Google App Script. How can i get hyperlink name? - google-apps-script

Have troubles with extracting url from text in google document. I found method getLinkUrl(offset). It works fine, but if i for example add link not directly to text but via menu item Insert -> Link i can specify some name for link, for example name, that will be displayed in text will be StackOverflow and the link is https://stackoverflow.com, so when i use method getLinkUrl() i will get hyperlink but not the name. I need to get position of this link on text, so i need to get this word StackOverflow but i didn't find corresponding method for this.
Is someone know how i can get this word or its start and end indexes?
I know about attributeIndices property which contains indexes of starting of special formatting of text and it can be used in this case, but if link is last word in paragraph, there is no any more attribute index in this array, so i can not determine length of this word.
Would be appreciate for any advice)

Related

Can't access Edit button for custom JIRA field, due to HTML tag in field description

In our JIRA instance, someone thought that because you could put html tags in description fields, that meant that you needed a full complement of tags to use them-- like, including <html> and, critically </html>
So, now we've got a custom field with a description containing a </html> tag, and as you might expect, the browser is not showing anything past that last tag, including any option to delete or edit the field.
Is there any way to use an API, etc to delete this field or change its description?
I'm on JIRA 4.1.2 (I know...)
Managed to solve the issue...
I used either the JIRA Advanced search, or right-click>>Inspect
element to get the ID of the field.
Then hovered over one of the "Configure" links that were showing to get the URL to the configure screen.
Then, I put the correct ID in the URL, and I was able to get back in and remove the offending tags.
That resolved the issue on the Custom Fields screen. Unfortunately, this technique had also been used on the "Field Configuration" screen, which is organized a bit differently.
The URLs to the "Edit" screens from the field configuration are formatted differently, with id= being the particular field configuration you're working with (don't change this one), and position= being the position in the list of the field you're working with (0 based index).
The easiest thing for me was to
Go to the field above the one that was messed up
Click on the Edit link, then
Increment the position parameter in the URL to give me the field I actually needed to change.
Deleted out the rogue HTML and everything was back to normal.

How to insert a clickable hyperlink with Outlook AddIn?

I am working on an Outlook AddIn which pastes a text in the body of email.
I am not using any of the following.
email.Body
email.HTMLBody
Instead, I use:
email.GetInspector.WordEditor.Content.InsertBefore()or InsertAfter()
The reason of that choice is justified by the fact that the latter mentioned line of code keeps the email formatting, the default user's fonts, as well as the signature formatting.
Now, when I try to paste a link into the email, it doesn't appear as a hyperlink, but just as a string. My link only becomes a clickable hyperlink when I click space or enter after it.
I can't use the URI class because I am also pasting text in a string format along with the link.
I tried to add the tags myself and saved the email as .htm here is the line where my link is posted. The tags are not translated into HTML.
<a href="http://whatever.com">http://whatever.com</a>
And if don't put the tags myself, it's just the same thing, but without all the &quot, &gt, &lt... and of course no HTML tag, which makes no clickable hyperlink.
Anyone knows how to fix this ?
The Document class from the Word object model provides the Hyperlinks property which returns a Hyperlinks collection that represents all the hyperlinks in the specified document.
You need to use the Add method of the Hyperlinks class. It returns a Hyperlink object that represents a new hyperlink added to a range, selection, or document.

find contact us pages using google importxml xpath

I am trying to pull links to contact pages from a list of urls in column B. I have tried the following but I get an error:
=IMPORTXML(B10,"//a[contains('contact')]/#href")
I want to be able to get href value for every a element that has anchor text containing the word "contact".
Any help would be appreciated.
Without seeing the URL you import, I can only comment on the XPath expression. Your expression is not valid, contains() always takes two arguments. Use
=IMPORTXML(B10,"//a[contains(.,'contact')]/#href")
If that does not give the expected result, you have to tell us the URL of the document you are importing.

extracting value from a <ul> with specific text text using HTMLAgilitypack

I'm trying to extract a link from http://www.raws.dri.edu/cgi-bin/rawLIST.pl?idIAN1+id
this site contains an unsorted list and I want to get the link for Daily Summary.
So far I've tried using an xpath string of "//ul/li/a" using the .SelectNodes() method. Doing so returns only the first item in the list which is what I want but ultimately in the future I may want to get the link to a different page so being able to specify which link to retrieve is what I need.
If you use //ul/li/a, you should get all the <a> links, not one.
If you want to extract the links that contain some text (e.g. Time Series Graph), you can do:
//ul/li/a[contains(text(), 'Time Series Graph')]
Similar, if you're looking for some specific text in the href attribute:
//ul/li/a[contains(#href, 'Time Series Graph')]
By the way, I see you have asked many questions pointing to the same website, etc. My suggestion is: Learn a little bit of XPath, the basics, and read a tutorial about how HtmlAgilityPack works (pretty simple once you understand the basics of XPath), and then start working on that scraper.

Can I word wrap a URL inside a HTML hyperlink

Is there a way to separate the URL name in a hyperlink so it continues onto the next line? In the application I am using I need to use a long URL and the space is limited so it wraps around to the next line. However, a space is automatically added to it and the link is then broken. Is there a continuation character to tell the application to keep link together or a way to use a shorter variable name that contains the longer actual URL?
No, HTML treats any and all whitespace characters (including multiple series of them) as a single space. You cannot disable this.
Is it absolutely necessary to put the URL as the hyperlink text?
In fact, showing a shorter meaningful description about the URL would be better for the hyperlink text.
meaning descr
I don't the actual requirement, but thought to leave this comment for you.