str2html

版本 1.0.0.0 (5.1 KB) 作者: Robert Cumming
Convert str to HTML format strings for use in uimenus and uicontrols
637.0 次下载
更新时间 2014/5/28

查看许可证

str2html Convert input str to html format for use in uicontrols/menus

uimenus and some uicontrols accept html format strings, e.g. pushbutton, listbox, popupmenu, menus, tooltips.

This function allows you to easily create html strings to display in the controls.

The function works by passing in a str and arg pairs:

htmlStr = str2html ( yourChar, P-V pairs )

yourChar 'a valid char string';

Valid arg pairs are:

'bold' true | ( false ) % bold format
'italic' true | ( false ) % italic format
'underline' true | ( false ) % underline format
'fontsize' 8 % size in int
'fontsize' '+2' % increment size from default
'colour' 'black' % colour of text
'fontname' 'MS Sans Serif' % font name
'superscript' '' % any superscript text ^
'subscript' '' % any subscript text ^
'bgcolour' 'white' % background colour
'prefix' '' % add your own prefix hmtl*
'suffix' '' % add your own suffix hmtl*
'userWarn' true | false % flag to display warnings

^ If sub & super script are added - then the subscript is added first.

* The idea of prefix and suffix is to add your own start and end tags to the html code that is generated - if only one is added a warning will be shown unless you add 'userWarn', false

For combing HTML format strings into one larger string, e.g. multi format on one line or multiple lines use:

yourCell{1} = str2html ( 'line1', pararm, value.... );
yourCell{2} = str2html ( 'line2', pararm, value.... );
yourCell{N} = str2html ( 'line2', pararm, value.... );

htmlStr = str2html ( yourCell, joinFormat )
The join format is a string to place between the cells, e.g. <br> or ' '.

The code uses persistent variables so you can change the default use following syntax. Note : No output.

str2html ( '*default*', 'bold', true )
str2html ( '*default*', 'fontname', 'Courier New' );

Special case for colour codes. e.g change default orange too:
str2html ( '*default*', colour:orange', '#FFBF40' );

This will change the defaults for THIS MATLAB session ONLY.

Reset all the changes made by the user.
str2html ( '*reset*' )

Examples:

str = str2html ( 'YOUR TEXT', 'bold', 1, 'italic', 1, 'underline', 1, 'fontsize', 5, 'colour', 'red', 'fontname', 'Courier New' )

str = str2html ( 'Change Background Colour', 'bgcolor', 'red', 'superscript', 'SuperScript', 'subscript', 'SUB', ...
'fontsize', '+2' )

% This adds a bullet point to your string.
str = str2html ( 'Add your own HTML code:', prefix', '<li>', 'suffix', '</li>' );

For multi format lines or multiple lines use multiple calls:
line1{1} = str2html ( 'line #1', 'bold', 1, 'fontname', 'Courier New' );
line1{2} = str2html ( 'No format' );
line1{3} = str2html ( 'underline', 'underline', 1 );
line1{4} = str2html ( 'italic', 'italic', 1, 'subscript', 'mySub' );
line1{5} = str2html ( 'finish', 'colour', 'green', 'superscript', 'mySuper!!' );
str{1} = str2html ( line1, ' ' )
str{2} = str2html ( 'line #2', 'italic', 1, 'color', 'red' );
str2 = str2html ( str, '\n' );
h = uicontrol ( 'style', 'listbox' );
set(h,'tooltipString', str2 );

DEVELOPER NOTE: This file uses mlock

Submission includes a test script to how some examples.

Copyright Robert Cumming, rcumming @ matpi.com
website: www.matpi.com

引用格式

Robert Cumming (2024). str2html (https://www.mathworks.com/matlabcentral/fileexchange/46755-str2html), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2013b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 MATLAB Report Generator 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0