文本框或文本编辑框中的超链接?有没有办法将超链接插入文本框或文本编辑框?我知道您可以在具有表达式列类型的 JMP 表中执行此操作,并且可以在窗口中创建一个充当超链接的按钮框。我还知道文本框的 << 标记语法,但这只允许您使用粗体、下划线和斜体。
回复:文本框或文本编辑框中的超链接?非常酷的方法@ih
回复:文本框或文本编辑框中的超链接?组合@Byron_JMP的 Web 浏览器框想法与您的正则表达式字符串,您可以保存带有嵌入链接的格式化 html 文件并将其显示在您的窗口中。突然之间,您对文本格式有了很大的控制权;您甚至可以让用户有选择地向链接语法添加一个友好的名称,例如 [JMP Website] http://www.jmp.com ,类似于一些标记语法。

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 );请注意正则表达式匹配表达式中不幸的斜杠,因为“\[”开始“转义字符”部分。
编辑以添加屏幕截图并再次修复拼写错误。
回复:文本框或文本编辑框中的超链接?感谢马克的建议。但是,我不希望我的用户必须嵌入 URL 标签。我的老板想出了一个效果很好的正则表达式:
// 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]);
);
);
回复:文本框或文本编辑框中的超链接?请参阅 Regex() 函数。 它可能有用。 正则表达式非常简单。
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"
);
回复:文本框或文本编辑框中的超链接?感谢您到目前为止的意见和建议。我无法知道用户评论中的 URL 位于何处。
这是一些示例输出:

这是一些示例代码。我通过使用 URL“标记” 和 使其变得简单。我一直在使用正则表达式来处理 URL 位置,以避免使用这些标记。如果有人有一个好的正则表达式来查找 URL,请告诉我。到目前为止,我在网上找到的信息取得了不同程度的成功。
// 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]);
);
);
回复:文本框或文本编辑框中的超链接?哦,让 mousebox(textBox) 成为一个可以多次使用的函数或表达式,其中只有文本(找到的链接)发生变化。
回复:文本框或文本编辑框中的超链接?这个解决方案需要一些额外的东西:一个 WrapListBox 和一个 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>
回复:文本框或文本编辑框中的超链接?您可以使用正则表达式来匹配超链接模式。
回复:文本框或文本编辑框中的超链接?我认为可以解析 html 链接的文本框内容(查找以“//:http”开头的模式),然后将按钮框附加到文本框,其中包含链接,对于每个模式被解析。
但这会非常复杂。 如果文本中的链接能够被识别并且可以点击,那就更好了。
回复:文本框或文本编辑框中的超链接?如果您同意整个框作为链接,那么您可以使用按钮框:
New Window( "Example",
Text box("Text Block 1"),
Button box( "http://www.jmp.com/", Web( "http://www.jmp.com/" ), Underline Style( 1 ) )
)回复:文本框或文本编辑框中的超链接?谢谢拜伦,这是一个很酷的脚本。但这不是我要找的。具体来说,我想将链接嵌入到文本框中并使其可单击。我的用户正在输入可能很长并且可以包含参考链接的评论。我正在研究一种解析链接并显示的方法:
文本块1(在文本框中)
链接1 (作为可点击的链接)
文本块2(在文本框中)
链接2 (作为可点击的链接)
文本块3
ETC。
这可能会被用户接受。
回复:文本框或文本编辑框中的超链接?我怀疑你正在寻找比这更复杂的东西,但是......
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 );
)));