How to get Matlab to display web links correctly for weird urls?

Usually, if I include a foo.mform comment in the file :

% See also: <a href="http://en.wikipedia.org/etc">link name</a>

the link appears in help browswer, i.e. in matlab i release

>> help foo

and I get something like

See also: link name

so far so good. However, there are some web addresses with funny characters, for example:

% See also: <a href="http://en.wikipedia.org/wiki/Kernel_(statistics)">http://en.wikipedia.org/wiki/Kernel_(statistics)</a>

Matlab does not do this correctly in the help browser. When I look at the help, it looks like this:

See also: statistics ) "> http://en.wikipedia.org/wiki/Kernel_ ( statistics )

where the link is in the local directory with the name "statistics". I tried all kinds of quotes and backslashes, but can't get the help browser to work correctly.

+5
1

Url-escape .

function foo
%FOO Function with funny help links
%
% Link to <a href="http://en.wikipedia.org/wiki/Kernel_%28statistics%29">some page</a>.

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
+4

All Articles