如何让Matlab帮助正确显示怪异URL的web链接?

如何让Matlab帮助正确显示怪异URL的web链接?,url,matlab,Url,Matlab,通常,如果我在文件foo.m中包含以下形式的注释: % See also: <a href="http://en.wikipedia.org/etc">link name</a> 我得到的是 另见: 到目前为止还不错。但是,有些网址具有有趣的字符,例如: % See also: <a href="http://en.wikipedia.org/wiki/Kernel_(statistics)">http://en.wi

通常,如果我在文件
foo.m
中包含以下形式的注释:

% See also: <a href="http://en.wikipedia.org/etc">link name</a>
我得到的是

另见:

到目前为止还不错。但是,有些网址具有有趣的字符,例如:

% See also: <a href="http://en.wikipedia.org/wiki/Kernel_(statistics)">http://en.wikipedia.org/wiki/Kernel_(statistics)</a>
%另请参见:
Matlab无法在“帮助”浏览器中正确呈现此内容。当我查看帮助时,它看起来如下所示:

另见: )">http://en.wikipedia.org/wiki/Kernel_()


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

Url使用字符代码转义有趣的字符

function foo
%FOO Function with funny help links
%
% Link to <a href="http://en.wikipedia.org/wiki/Kernel_%28statistics%29">some page</a>.
这里有一个函数,它将引用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('http://en.wikipedia.org/wiki/Kernel_(statistics)')
ans =
http://en.wikipedia.org/wiki/Kernel_%28statistics%29

为了完整性,我还必须在链接文本中转义:
%另请参见:
。如果
对中包含内核(统计信息),则Matlab无法正确渲染。感谢您的捕获,我正在为看不到它而拍头。
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{:});
>> escape_url_for_helptext('http://en.wikipedia.org/wiki/Kernel_(statistics)')
ans =
http://en.wikipedia.org/wiki/Kernel_%28statistics%29