Hyperlinks in Text Box or Text Edit Box?Is there a way to insert a hyperlink into a text box or text edit box? I know that you can do this in a JMP table with the expression column type, and that you can create a button box in a window that acts like a hyperlink. I'm also aware of the << markup syntax for text boxes, but that only lets you do bold, underline and italic.
Re: Hyperlinks in Text Box or Text Edit Box?Very cool approach @ih
Re: Hyperlinks in Text Box or Text Edit Box?Combining @Byron_JMP's Web Browser Box idea with your regex string you could save a formatted html file with embedded links and display that in your window. Suddenly you have a lot of control over the text formatting; you could even let users optionally add a friendly name to links syntax like [JMP Website]http://www.jmp.com, similar to some markup syntax.

Names Default To Here( 1 );
text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"[A Link]http://www.reference.md/files/D010/mD010489.html As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well.
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *http://www.ncbi.nlm.nih.gov/pubmed/12530994";
t = text;
//wrap links in a string with <A href="https://community.jmp.com/" target="_blank"> tags
findlinks = function({t, recct=0}, {url_regex, rgxmatch = {}, rtn=""},
recct++;
if(recct > 100,
throw("Recursion to deep: " || char(recct) || " levels. Still need to parse: '" || t || "'"));
url_regex = "^(.*?)(\!\[(.+)\])?((https?://){0,}(\w+\.){2,}\w+/?(\w+/?){0,}(\.\w+){0,1}/?)(\b.*)$";
rgxmatch = Regex Match(t, url_regex);
if( N Items(rgxmatch) == 0,
rtn = t, //No link
if( N Items(rgxmatch) == 10, //found a link
rtn = rgxmatch[2] ||
"</A><A href="" || rgxmatch[5] || "" target="_blank" rel="nofollow noopener noreferrer">" || if(is missing(rgxmatch[4]), rgxmatch[5], rgxmatch[4] ) || "</A>" ||
findlinks(rgxmatch[10], recct),
throw("Error matching regex in: '" || t || "'")
)
);
return(rtn)
);
//Create a simple html page from a block of text, save it to the temp files, and return the filename
texttohtmlfile = function({t},
Save text file("$TEMP/Temp HTML file.html", "" || findlinks(t) || "")
);
//Make a temp html file
fn = texttohtmlfile(text);
//Simple window to display html file, deletes the temp file when it closes
w = New Window("Example",wb = Web Browser Box());
w << On Close( Delete File( fn ) );
wb << Set Size(1000, 200);
wb << Set Auto Stretching( 1, 1 );
wb << Set Max Size( 1000, 1000 );
//Show the html file in the window
wb << Navigate( fn );Note the unfortunate slash bang in the regex match expression as "\[" begins an 'escaped character' section.
Edited to add screenshot and again to fix a typo.
Re: Hyperlinks in Text Box or Text Edit Box?Thanks for that suggestion Mark. However I don't want my users to have to embed tags for URLs. My boss came up with a regular expression which works pretty well:
// Sample text
text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"http://www.reference.md/files/D010/mD010489.html As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well.
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *http://www.ncbi.nlm.nih.gov/pubmed/12530994";
url_regex = "\b(https?://){0,}(\w+\.){2,}\w+/?(\w+/?){0,}(\.\w+){0,1}/?\b";
text_list = {};
link_list = {};
keep_going = 1;
istart = 1;
text_len = length(text);
i = 0;
while(keep_going,
new_text = substr(text, istart);
link_text = regex(new_text, url_regex);
if (!is missing(link_text),
// then
i++;
start_pos = contains(text, link_text, istart);
text_list[i] = substr(text, istart, (start_pos - istart - 1));
link_list[i] = link_text;
istart = start_pos + length(link_text);
,
// else no link found
i++;
text_list[i] = new_text;
keep_going = 0;
);
);
tb = {};
lb = {};
nt = nitems(text_list);
nw = new window("Test link",
vb = vlistbox(
)
);
for(i = 1, i <= nt, i++,
tb[i] = text box(text_list[i], << set width(400));
vb << append(tb[i]);
if (i < nt,
one_button = evalinsert("\[lb[i] = button box("^link_list[i]^", web("^link_list[i]^"), << underline style(1) )]\");
eval(parse(one_button));
vb << append(lb[i]);
);
);
Re: Hyperlinks in Text Box or Text Edit Box?See Regex() function. It might be useful. The regular expression would be pretty simple.
Names Default to Here( 1 );
text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"<L>http://www.reference.md/files/D010/mD010489.html</L> As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well.
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *<L>http://www.ncbi.nlm.nih.gov/pubmed/12530994</L>";
Regex( text,
"<L>(.+?)</L>",
"\1"
);
Re: Hyperlinks in Text Box or Text Edit Box?Thanks for your comments and suggestions so far. I don't have the luxury of knowing where the URLs are in the user comments.
Here's some sample output:

Here's some sample code. I made it easy by using URL "markers" and . I've been playing around with URL location using regex to avoid having to use these markers. If anyone has a good regular expression for finding URLs let me know. I'm having varied success with what I've found on the net so far.
// link markup example
text = "Periarthritis is defined as: Inflammation of the tissues around a joint. " ||
"<L>http://www.reference.md/files/D010/mD010489.html</L> As arthralgia, myalgia, tendonitis " ||
"and other musculoskeletal issues are listed events, periarthritis can be considered listed as well.
Comment: no good sentinel case — not a new signal; one case also reported somnolence and " ||
"another case reported “yawny” which could mean sleepy *<L>http://www.ncbi.nlm.nih.gov/pubmed/12530994</L>";
text_list = {};
link_list = {};
keep_going = 1;
istart = 1;
linkstart = "<L>";
linkend = "</L>";
text_len = length(text);
i = 0;
while(keep_going,
start_pos = contains(text, linkstart, istart);
if (start_pos,
end_pos = contains(text, linkend, istart);
if (end_pos,
i++;
text_list[i] = substr(text, istart, (start_pos - istart));
link_list[i] = substr(text, start_pos + 3, (end_pos - start_pos - 3));
istart = istart + end_pos - istart + 4;
);
);
if (!start_pos,
i++;
text_list[i] = substr(text, istart);
keep_going = 0;
);
);
tb = {};
lb = {};
nt = nitems(text_list);
nw = new window("Test link",
vb = vlistbox(
)
);
for(i = 1, i <= nt, i++,
tb[i] = text box(text_list[i], << set width(400));
vb << append(tb[i]);
if (i < nt,
one_button = evalinsert("\[lb[i] = button box("^link_list[i]^", web("^link_list[i]^"), << underline style(1) )]\");
eval(parse(one_button));
vb << append(lb[i]);
);
);
Re: Hyperlinks in Text Box or Text Edit Box?Oh and make the mousebox(textBox) a function or expression that can be used many times, where only the text, the found link, changes.
Re: Hyperlinks in Text Box or Text Edit Box?This solution requires a little extra something, something: a WrapListBox and a MouseBox.
Names Default To Here( 1 );
New Window( "WrapListBox",
Wrap List Box(
TextBox("This is a long comment to be followed by a link "),
MouseBox(TextBox(" <U>http://www.jmp.com</U> ",<<FONT color="">");
web(lnk);
(this<<CHILD></CHILD></FONT>
Re: Hyperlinks in Text Box or Text Edit Box?You could use a regular expression to match the hyperlink pattern.
Re: Hyperlinks in Text Box or Text Edit Box?I think it might be possible to parse the text box contents for an html link (find patterns that start with "//:http") and then append a button box to the text box, with the link in it, for each pattern that is parsed.
That's going to be pretty complex though. It would be so much better if the links were recognized in the text and were clickable.
Re: Hyperlinks in Text Box or Text Edit Box?If you are okay with the entire box being the link then you could use a button box:
New Window( "Example",
Text box("Text Block 1"),
Button box( "http://www.jmp.com/", Web( "http://www.jmp.com/" ), Underline Style( 1 ) )
)Re: Hyperlinks in Text Box or Text Edit Box?Thanks Byron that's a cool script. But it's not what I was looking for. Specifically I want to embed a link into a text box and have it be clickable. My users are entering comments which can be long and can contain reference links. I'm working on an approach where I parse out the links and display:
Text block1 (in a text box)
Link1 (as a clickable link)
Text block2 (in a text box)
Link2 (as a clickable link)
Text block3
etc.
That will probably be acceptable to users.
Re: Hyperlinks in Text Box or Text Edit Box?I suspect you're looking for something more sophistocated than this, but...
Names Default To Here( 1 );
New Window( "Example",
hlistbox("1",
wb = Web Browser Box(),
bb=Button Box( "Take Me to JMP",
wb << Navigate( "http://www.jmp.com" );
wb << Set Auto Stretching( 1, 1 );
wb << Set Max Size( 1000, 1000 );
)));