Skip to content

Commit 053d685

Browse files
committed
Added a function to dump the HTML of a uifigure.
See `getHTML`.
1 parent d7e065b commit 053d685

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mlapptools.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,32 @@ function fontColor(uielement, newcolor)
118118
end
119119
end % aboutDojo
120120

121+
function [fullHTML] = getHTML(hUIFig)
122+
% A method for dumping the HTML code of a uifigure.
123+
% Intended for R2017b (and onward?) where the CEF url cannot be simply opened in a browser.
124+
125+
win = mlapptools.getWebWindow(hUIFig);
126+
% Get the outer html:
127+
fullHTML = win.executeJS('document.documentElement.outerHTML');
128+
% Replace some strings for conversion to work well:
129+
fullHTML = strrep(fullHTML,'%','%%');
130+
fullHTML = strrep(fullHTML,'><','>\n<');
131+
% Append the DOCTYPE header and remove quotes:
132+
fullHTML = sprintf(['<!DOCTYPE HTML>\n' fullHTML(2:end-1)]);
133+
134+
%% Optional things to do with the output:
135+
% Display as web page:
136+
%{
137+
web(['text://' fullHTML]);
138+
%}
139+
% Save as file:
140+
%{
141+
fid = fopen('uifig_raw.html','w');
142+
fprintf(fid,'%s',fullHTML);
143+
fclose(fid);
144+
%}
145+
end % getHTML
146+
121147
end % Public Static Methods
122148

123149
methods (Static = true, Access = private)

0 commit comments

Comments
 (0)