MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何使Matlab帮助正确显示奇怪网址的Web链接? (https://www.labfans.com/bbs/showthread.php?t=24224)

poster 2019-12-10 20:48

如何使Matlab帮助正确显示奇怪网址的Web链接?
 
通常,如果我在foo.m文件中foo.m以下形式的注释:

% See also: [URL="http://en.wikipedia.org/etc"]link name[/URL] 该链接出现在帮助浏览器中, [I]即[/I]在Matlab中,我发出

>> help foo 我得到类似
[INDENT]另请参阅: [URL="http://en.wikipedia.org/etc"]链接名称[/URL]

[/INDENT]到目前为止,一切都很好。但是,有些网址包含有趣的字符,例如:

% See also: [URL]http://en.wikipedia.org/wiki/Kernel_(statistics)[/URL] Matlab无法在帮助浏览器中正确呈现此内容。当我查看帮助时,它看起来像这样:
[INDENT]另请参阅: [URL="http:///home/user/etc/matlab/statistics"]统计信息[/URL] )“> [url]http://en.wikipedia.org/wiki/内核_([/url] [URL="http:///home/user/etc/matlab/statistics"]统计信息[/URL] )

[/INDENT]链接指向名为“ statistics”的本地目录。我尝试了各种引号转义和反斜杠,但是无法使帮助浏览器正常工作。



[B]回答:[/B]

用字符代码对有趣的字符进行网址转义。

function foo %FOO Function with funny help links % % Link to [URL="http://en.wikipedia.org/wiki/Kernel_%28statistics%29"]some page[/URL]. Matlab urlencode()函数将向您显示要使用的代码。但是,请保持冒号和斜线不变。

>> disp(urlencode('Kernel_(statistics)')) Kernel_%28statistics%29 这是一个引用URL路径元素的函数,保留了需要保留的部分。

function escapedUrl = escape_url_for_helptext(url) ixColon = find(url == ':', 1); if isempty(ixColon) [proto,rest] = deal('', url); else [proto,rest] = deal(url(1:ixColon), url(ixColon+1:end)); end parts = regexp(rest, '/', 'split'); encodedParts = cellfun(@urlencode, parts, 'UniformOutput', false); escapedUrl = [proto join(encodedParts, '/')]; function out = join(strs, glue) strs(1:end-1) = strcat(strs(1:end-1), {glue}); out = cat(2, strs{:}); 要使用它,只需输入您的整个URL。

>> escape_url_for_helptext('[url]http://en.wikipedia.org/wiki/Kernel_(statistics)'[/url]) ans = [url]http://en.wikipedia.org/wiki/Kernel_%28statistics%29[/url]

[url=https://stackoverflow.com/questions/4442347]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:05

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.