poster
2019-12-10, 20:48
通常,如果我在foo.m文件中foo.m以下形式的注释:
% See also: link name (http://en.wikipedia.org/etc) 该链接出现在帮助浏览器中, 即在Matlab中,我发出
>> help foo 我得到类似
另请参阅: 链接名称 (http://en.wikipedia.org/etc)
到目前为止,一切都很好。但是,有些网址包含有趣的字符,例如:
% See also: http://en.wikipedia.org/wiki/Kernel_(statistics) Matlab无法在帮助浏览器中正确呈现此内容。当我查看帮助时,它看起来像这样:
另请参阅: 统计信息 (http:///home/user/etc/matlab/statistics) )“> http://en.wikipedia.org/wiki/内核_( 统计信息 (http:///home/user/etc/matlab/statistics) )
链接指向名为“ statistics”的本地目录。我尝试了各种引号转义和反斜杠,但是无法使帮助浏览器正常工作。
回答:
用字符代码对有趣的字符进行网址转义。
function foo %FOO Function with funny help links % % Link to some page (http://en.wikipedia.org/wiki/Kernel_%28statistics%29). 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('http://en.wikipedia.org/wiki/Kernel_(statistics)') ans = http://en.wikipedia.org/wiki/Kernel_%28statistics%29
更多&回答... (https://stackoverflow.com/questions/4442347)
% See also: link name (http://en.wikipedia.org/etc) 该链接出现在帮助浏览器中, 即在Matlab中,我发出
>> help foo 我得到类似
另请参阅: 链接名称 (http://en.wikipedia.org/etc)
到目前为止,一切都很好。但是,有些网址包含有趣的字符,例如:
% See also: http://en.wikipedia.org/wiki/Kernel_(statistics) Matlab无法在帮助浏览器中正确呈现此内容。当我查看帮助时,它看起来像这样:
另请参阅: 统计信息 (http:///home/user/etc/matlab/statistics) )“> http://en.wikipedia.org/wiki/内核_( 统计信息 (http:///home/user/etc/matlab/statistics) )
链接指向名为“ statistics”的本地目录。我尝试了各种引号转义和反斜杠,但是无法使帮助浏览器正常工作。
回答:
用字符代码对有趣的字符进行网址转义。
function foo %FOO Function with funny help links % % Link to some page (http://en.wikipedia.org/wiki/Kernel_%28statistics%29). 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('http://en.wikipedia.org/wiki/Kernel_(statistics)') ans = http://en.wikipedia.org/wiki/Kernel_%28statistics%29
更多&回答... (https://stackoverflow.com/questions/4442347)