function [H, HC] = spm_browser(url,F,pos,format) % Display an HTML document within a MATLAB figure % FORMAT H = spm_browser(url,F,pos,[format]) % % url - string containing URL (e.g. 'http://...' or 'file://...') % F - figure handle or Tag [Default: Graphics] % pos - position within figure in pixel units with the format [left, % bottom, width, height]. [Default: full window with 10px margin] % format - data format {['html'],'wiki'} % 'wiki' option uses Wikipedia wiki markup: % http://en.wikipedia.org/wiki/Wikipedia:Cheatsheet % % H - handle to the Java component % HC - handle to the HG container %__________________________________________________________________________ % Copyright (C) 2011-2012 Wellcome Trust Centre for Neuroimaging % Guillaume Flandin % $Id: spm_browser.m 6409 2015-04-16 16:19:38Z guillaume $ %-Input arguments %-------------------------------------------------------------------------- if nargin < 1 url = 'http://www.fil.ion.ucl.ac.uk/spm/'; end if nargin < 2 || isempty(F) F = spm_figure('GetWin','Graphics'); end try, isUpdate = ismethod(F,'setCurrentLocation'); catch, isUpdate=false; end if ~isUpdate, F = spm_figure('FindWin',F); end if (nargin < 3 || isempty(pos)) && ~isUpdate u = get(F,'Units'); set(F,'Units','pixels'); pos = get(F,'Position'); set(F,'Units',u); pos = [10, 10, pos(3)-20, pos(4)-20]; end if nargin < 4 || isempty(format) format = 'html'; end %-Display %-------------------------------------------------------------------------- try % if usejava('awt') && spm_check_version('matlab','7.4') >= 0 %-Create HTML browser panel %---------------------------------------------------------------------- if ~isUpdate browser = com.mathworks.mlwidgets.html.HTMLBrowserPanel; [H, HC] = javacomponent(browser,pos,F); else H = F; HC = []; end %-Set content %---------------------------------------------------------------------- if strcmpi(format,'html') && any(strncmp(url,{'file','http','ftp:'},4)) H.setCurrentLocation(strrep(url,'\','/')) elseif strcmpi(format,'wiki') H.setHtmlText(wiki2html(url)); elseif all(~strncmp(url,{'file','http','ftp:'},4)) H.setHtmlText(url); end drawnow catch H = []; HC = []; end %========================================================================== function html = wiki2html(wiki) % Convert Wiki markup document into HTML fid = fopen(wiki); if fid~=-1 wiki = fscanf(fid,'%c'); fclose(fid); else html = [sprintf('\n\nwiki2html\n\n'), ... sprintf('\n'), ... sprintf('

Cannot read %s

',wiki), ... sprintf('\n\n')]; return; end % Section headings wiki = regexprep(wiki,'======[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?======','
$1
'); wiki = regexprep(wiki,'=====[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?=====','
$1
'); wiki = regexprep(wiki,'====[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?====','

$1

'); wiki = regexprep(wiki,'===[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?===','

$1

'); wiki = regexprep(wiki,'==[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?==','

$1

'); wiki = regexprep(wiki,'=[\s]*?([0-9A-Za-z].[^=\[]*)[\s]*?=','

$1

'); % Horizontal line wiki = regexprep(wiki,'----','
'); % Inline elements wiki = regexprep(wiki,'''''''''''([0-9A-Za-z].*)''''''''''',... '$1'); wiki = regexprep(wiki,'''''''([0-9A-Za-z].*)''''''','$1'); wiki = regexprep(wiki,'''''([0-9A-Za-z].*)''''','$1'); % Paragraphs wiki = regexprep(wiki,'\n([^#\*=].*)','

$1

'); % unordered list wiki = regexprep(wiki,'\*([^*]*)','
  • $1
  • '); wiki = regexprep(wiki,'([^])
  • ','$1'); % ordered list wiki = regexprep(wiki,'^#[:]?[#]* (.*)','
  • $1
  • '); wiki = regexprep(wiki,'([^][>]?[\n])
  • ','$1
    1. '); wiki = regexprep(wiki,'<\/li>\n(?!
    2. )','
    '); % tables wiki = regexprep(wiki,'^{\|\n\|-',''); wiki = regexprep(wiki,'^\|-',''); wiki = regexprep(wiki,'^!\s(.*)',''); wiki = regexprep(wiki,'^\|\s(.*)',''); wiki = regexprep(wiki,'^\|}','
    $1$1
    '); html = [sprintf('\n\nwiki2html\n\n'), ... sprintf('\n'), ... wiki, ... sprintf('\n\n')];