文字方塊或文字編輯框中的超連結?有沒有辦法將超連結插入文字方塊或文字編輯框?我知道您可以在具有表達式列類型的 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 );
)));