77% * https://www.mathworks.com/help/matlab/matlab_prog/marking-up-matlab-comments-for-publishing.html
88%
99% for package code -- assumes no classes and depth == 1
10- function publish_gen_index_html(pkg_name , tagline , outdir )
10+ %
11+ % if *.mex* files are present, publish fails
12+
13+ function publish_gen_index_html(pkg_name , tagline , project_url , outdir )
14+ arguments
15+ pkg_name (1 ,1 ) string
16+ tagline (1 ,1 ) string
17+ project_url (1 ,1 ) string
18+ outdir (1 ,1 ) string
19+ end
1120
1221pkg = what(" +" + pkg_name );
1322% "+" avoids picking up cwd of same name
@@ -24,37 +33,50 @@ function publish_gen_index_html(pkg_name, tagline, outdir)
2433 mkdir(outdir );
2534end
2635
27- txt = [" <!DOCTYPE html> <head> <title>" + pkg_name + " API</title> <body>" , ...
28- " <h1>" + pkg_name + " API</h1>" , ...
29- " <p>" + tagline + " </p>" , ...
30- " <p>" + git_txt + " </p>" , ...
31- " <h2>API Reference</h2>" ];
36+ txt = [" <!DOCTYPE html>" , ...
37+ " <head>" ,...
38+ ' <meta name="color-scheme" content="dark light">' , ...
39+ ' <meta name="viewport" content="width=device-width, initial-scale=1">' , ...
40+ ' <meta name="generator" content="Matlab ' + matlabRelease().Release + ' ">' , ...
41+ " <title>" + pkg_name + " API</title>" , ...
42+ " </head>" , ...
43+ " <body>" , ...
44+ " <h1>" + pkg_name + " API</h1>" , ...
45+ " <p>" + tagline + " </p>" , ...
46+ " <p>" + git_txt + " </p>" , ...
47+ " <p>Project URL: <a href=" + project_url + " >" + project_url + " </a></p>" , ...
48+ " <h2>API Reference</h2>" ];
3249fid = fopen(readme , ' w' );
3350fprintf(fid , join(txt , " \n" ));
3451
3552for sub = pkg .m .'
3653
3754s = sub{1 };
3855[~ , name ] = fileparts(s );
56+
3957doc_fn = publish(pkg_name + " ." + name , evalCode= false , outputDir= outdir );
4058disp(doc_fn )
4159
42- % inject summary into Readme.md
43- summary = split(string(help(pkg_name + " ." + name )), newline );
44- words = split(strip(summary (1 )), " " );
60+ % inject summary for each function into Readme.md
61+ help_txt = split(string(help(pkg_name + " ." + name )), newline );
62+ words = split(strip(help_txt (1 )), " " );
4563
46- % purposefully this will error if no docstring
64+ % error if no docstring
4765fname = words(1 );
48- if (lower(fname ) ~= lower(name ))
49- error(" fname %s does not match name %s" , fname , name )
50- end
66+ assert(lower(fname ) == lower(name ), " fname %s does not match name %s \nis there a docstring at the top of the .m file?" , fname , name )
5167
5268line = " <a href=" + name + " .html>" + fname + " </a> " ;
5369if (length(words ) > 1 )
5470 line = line + join(words(2 : end ));
5571end
5672
57- fprintf(fid , line + " <br>\n" );
73+ req = " " ;
74+
75+ if contains(help_txt(2 ), " requires:" ) || contains(help_txt(2 ), " optional:" )
76+ req = " <strong>(" + strip(help_txt(2 ), " " ) + " )</strong>" ;
77+ end
78+
79+ fprintf(fid , line + " " + req + " <br>\n" );
5880
5981end
6082
0 commit comments