Mercurial > octave
annotate scripts/miscellaneous/publish.m @ 28892:3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
* audiorecorder.m, interp3.m, iscolormap.m, spinmap.m, expm.m, copyfile.m,
delete.m, edit.m, inputParser.m, movefile.m, narginchk.m, nargoutchk.m,
publish.m, tar.m, tempdir.m, ode23.m, ode23s.m, ode45.m, odeplot.m, sqp.m,
matlabroot.m, savepath.m, expand_rel_paths.m, datetick.m, lighting.m,
material.m, rticks.m, shading.m, thetaticks.m, view.m, xticklabels.m, xticks.m,
yticklabels.m, yticks.m, zticklabels.m, zticks.m, colorbar.m, errorbar.m,
hist.m, isocaps.m, light.m, line.m, patch.m, shrinkfaces.m, stairs.m,
surface.m, allchild.m, ancestor.m, cla.m, clf.m, findobj.m, gca.m, hggroup.m,
isgraphics.m, ishandle.m, print.m, struct2hdl.m, arch_rnd.m, speed.m, clock.m:
Use parentheses '()' after function invocation to distinguish between a variable
and a function.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 10 Oct 2020 17:55:56 -0700 |
parents | bd51beb6205e |
children | 90fea9cc9caa |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2010-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27846
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
7 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
13 ## (at your option) any later version. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
14 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
18 ## GNU General Public License for more details. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
19 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24491
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
25 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
27 ## @deftypefn {} {} publish (@var{file}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
28 ## @deftypefnx {} {} publish (@var{file}, @var{output_format}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
29 ## @deftypefnx {} {} publish (@var{file}, @var{option1}, @var{value1}, @dots{}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
30 ## @deftypefnx {} {} publish (@var{file}, @var{options}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
31 ## @deftypefnx {} {@var{output_file} =} publish (@var{file}, @dots{}) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
32 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
33 ## Generate a report from the Octave script file @var{file} in one of several |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
34 ## output formats. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
35 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
36 ## The generated reports interpret any Publishing Markup in comments, which is |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
37 ## explained in detail in the GNU Octave manual. Assume the following example, |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
38 ## using some Publishing Markup, to be the contents of the script file |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
39 ## @file{pub_example.m}: |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
40 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
41 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
42 ## @group |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
43 ## ## Headline title |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
44 ## # |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
45 ## # Some *bold*, _italic_, or |monospaced| Text with |
25024
3c817af70eed
maint: use https for all Octave project URLs
Mike Miller <mtmiller@octave.org>
parents:
24534
diff
changeset
|
46 ## # a <https://www.octave.org link to *GNU Octave*>. |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
47 ## ## |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
48 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
49 ## # "Real" Octave commands to be evaluated |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
50 ## sombrero () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
51 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
52 ## %% @sc{matlab} comment style ('%') is supported as well |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
53 ## % |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
54 ## % * Bulleted list item 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
55 ## % * Bulleted list item 2 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
56 ## % |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
57 ## % # Numbered list item 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
58 ## % # Numbered list item 2 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
59 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
60 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
61 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
62 ## To publish this script file, type @code{publish ("pub_example.m")}. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
63 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
64 ## With only @var{file} given, a HTML report is generated in a subdirectory |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
65 ## @file{html} relative to the current working directory. The Octave commands |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
66 ## are evaluated in a separate context and any figures created while executing |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
67 ## the script file are included in the report. All formatting syntax of |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
68 ## @var{file} is treated according to the specified output format and included |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
69 ## in the report. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
70 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
71 ## Using @code{publish (@var{file}, @var{output_format})} is equivalent to the |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
72 ## function call using a structure |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
73 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
74 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
75 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
76 ## @var{options}.format = @var{output_format}; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
77 ## publish (@var{file}, @var{options}) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
78 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
79 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
80 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
81 ## @noindent |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
82 ## which is described below. The same holds for using option/value pairs |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
83 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
84 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
85 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
86 ## @var{options}.@var{option1} = @var{value1}; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
87 ## publish (@var{file}, @var{options}) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
88 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
89 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
90 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
91 ## The structure @var{options} can have the following field names. If a field |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
92 ## name is not specified, the default value is used: |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
93 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
94 ## @itemize @bullet |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
95 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
96 ## @samp{format} --- Output format of the published script file, one of |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
97 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
98 ## @samp{html} (default), @samp{doc}, @samp{latex}, @samp{ppt}, |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
99 ## @samp{pdf}, or @samp{xml}. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
100 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
101 ## The output formats @samp{doc}, @samp{ppt}, and @samp{xml} are not currently |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
102 ## supported. To generate a @samp{doc} report, open a generated @samp{html} |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
103 ## report with your office suite. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
104 ## |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
105 ## In Octave custom formats are supported by implementing all callback |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
106 ## subfunctions in a function file named |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
107 ## @samp{__publish_<custom format>_output__.m}. To obtain a template for the |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
108 ## HTML format type: |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
109 ## |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
110 ## @example |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
111 ## @group |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
112 ## edit (fullfile (fileparts (which ("publish")), ... |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
113 ## "private", "__publish_html_output__.m")) |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
114 ## @end group |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
115 ## @end example |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
116 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
117 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
118 ## @samp{outputDir} --- Full path of the directory where the generated report |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
119 ## will be located. If no directory is given, the report is generated in a |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
120 ## subdirectory @file{html} relative to the current working directory. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
121 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
122 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
123 ## @samp{stylesheet} --- Not supported, only for @sc{matlab} compatibility. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
124 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
125 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
126 ## @samp{createThumbnail} --- Not supported, only for @sc{matlab} |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
127 ## compatibility. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
128 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
129 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
130 ## @samp{figureSnapMethod} --- Not supported, only for @sc{matlab} |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
131 ## compatibility. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
132 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
133 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
134 ## @samp{imageFormat} --- Desired format for any images produced while |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
135 ## evaluating the code. The allowed image formats depend on the output format: |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
136 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
137 ## @itemize @bullet |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
138 ## @item @samp{html}, @samp{xml} --- @samp{png} (default), any image format |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
139 ## supported by Octave |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
140 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
141 ## @item @samp{latex} --- @samp{epsc2} (default), any image format supported by |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
142 ## Octave |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
143 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
144 ## @item @samp{pdf} --- @samp{jpg} (default) or @samp{bmp}, note @sc{matlab} |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
145 ## uses @samp{bmp} as default |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
146 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
147 ## @item @samp{doc} or @samp{ppt} --- @samp{png} (default), @samp{jpg}, |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
148 ## @samp{bmp}, or @samp{tiff} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
149 ## @end itemize |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
150 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
151 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
152 ## @samp{maxWidth} and @samp{maxHeight} --- Maximum width (height) of the |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
153 ## produced images in pixels. An empty value means no restriction. Both |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
154 ## values must be set in order for the option to work properly. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
155 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
156 ## @samp{[]} (default), integer value @geq{} 0 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
157 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
158 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
159 ## @samp{useNewFigure} --- Use a new figure window for figures created by the |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
160 ## evaluated code. This avoids side effects with already opened figure |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
161 ## windows. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
162 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
163 ## @samp{true} (default) or @samp{false} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
164 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
165 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
166 ## @samp{evalCode} --- Evaluate code of the Octave source file |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
167 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
168 ## @samp{true} (default) or @samp{false} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
169 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
170 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
171 ## @samp{catchError} --- Catch errors while evaluating code and continue |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
172 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
173 ## @samp{true} (default) or @samp{false} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
174 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
175 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
176 ## @samp{codeToEvaluate} --- Octave commands that should be evaluated prior to |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
177 ## publishing the script file. These Octave commands do not appear in the |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
178 ## generated report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
179 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
180 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
181 ## @samp{maxOutputLines} --- Maximum number of output lines from code |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
182 ## evaluation which are included in output. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
183 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
184 ## @samp{Inf} (default) or integer value > 0 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
185 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
186 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
187 ## @samp{showCode} --- Show the evaluated Octave commands in the generated |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
188 ## report |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
189 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
190 ## @samp{true} (default) or @samp{false} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
191 ## @end itemize |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
192 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
193 ## The option output @var{output_file} is a string with path and file name |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
194 ## of the generated report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
195 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
196 ## @seealso{grabcode} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
197 ## @end deftypefn |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
198 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
199 function output_file = publish (file, varargin) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
200 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
201 if (nargin < 1) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
202 print_usage (); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
203 endif |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
204 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
205 if (exist (file, "file") != 2) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
206 error ("publish: FILE does not exist"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
207 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
208 |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
209 ## Check file to be in Octave's load path |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
210 [file_path, file_name, file_ext] = fileparts (file); |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
211 if (isempty (file_path)) |
28892
3cac3ceb9629
maint: Use coding style with parentheses after function name to distinguish from a variable.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
212 file_path = pwd (); |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
213 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
214 if (exist ([file_name, file_ext]) != 2) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
215 error (["publish: " file " is not in the load path"]); |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
216 endif |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
217 |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
218 ## Check file extension and that file is an Octave script |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
219 file_info = __which__ (file_name); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
220 if (! strcmp (file_ext, ".m") || ! strcmp (file_info.type, "script")) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
221 error ("publish: only script files can be published"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
222 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
223 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
224 ## Check file to be parsable |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
225 __parse_file__ (file); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
226 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
227 ## Get structure with necessary options |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
228 options = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
229 if (numel (varargin) == 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
230 ## Call: publish (file, format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
231 if (ischar (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
232 options.format = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
233 ## Call: publish (file, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
234 elseif (isstruct (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
235 options = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
236 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
237 error ("publish: second argument must be OUTPUT_FORMAT or OPTIONS"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
238 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
239 ## Call: publish (file, Name1, Value1, Name2, Value2, ...) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
240 elseif (rem (numel (varargin), 2) == 0 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
241 && all (cellfun (@ischar, varargin(1:2:end)))) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
242 options = cell2struct (varargin(2:2:end), varargin(1:2:end), 2); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
243 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
244 error ("publish: invalid arguments"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
245 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
246 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
247 ## Validate options struct |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
248 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
249 ## Options for the output |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
250 if (! isfield (options, "format")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
251 options.format = "html"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
252 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
253 ## FIXME: Implement remaining formats |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
254 if (any (strcmpi (options.format, {"doc", "ppt", "xml"}))) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
255 error ('publish: Output format "%s" is not yet supported', |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
256 options.format); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
257 endif |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
258 ## Supported or custom output format |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
259 supported_formats = {"html", "doc", "latex", "ppt", "xml", "pdf"}; |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
260 if (! any (strcmpi (options.format, supported_formats))) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
261 ## Check existence of custom formatter |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
262 custom_formatter = ["__publish_", options.format, "_output__"]; |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
263 if (! exist (custom_formatter, "file")) |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
264 error (['publish: Custom output format "%s" requires the ', ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
265 "formatter function:\n\n\t%s\n\n\t", ... |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
266 'See "help publish" for more information.'], |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
267 options.format, custom_formatter); |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
268 endif |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
269 else |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
270 options.format = validatestring (options.format, supported_formats); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
271 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
272 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
273 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
274 if (! isfield (options, "outputDir")) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
275 ## Matlab R2016a doc says default is "", but specifies to create a |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
276 ## subdirectory named "html" in the current working directory. |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
277 options.outputDir = fullfile (file_path, "html"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
278 elseif (! ischar (options.outputDir)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
279 error ("publish: OUTPUTDIR must be a string"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
280 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
281 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
282 if (! isfield (options, "stylesheet")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
283 options.stylesheet = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
284 elseif (! ischar (options.stylesheet)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
285 error ("publish: STYLESHEET must be a string"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
286 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
287 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
288 ## Options for the figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
289 if (! isfield (options, "createThumbnail")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
290 options.createThumbnail = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
291 elseif (! isscalar (options.createThumbnail) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
292 || ! isreal (options.createThumbnail)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
293 error ("publish: CREATETHUMBNAIL must be TRUE or FALSE"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
294 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
295 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
296 if (! isfield (options, "figureSnapMethod")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
297 options.figureSnapMethod = "entireGUIWindow"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
298 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
299 options.figureSnapMethod = validatestring (options.figureSnapMethod, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
300 {"entireGUIWindow", "print", "getframe", "entireFigureWindow"}); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
301 ## FIXME: implement other SnapMethods |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
302 warning ("publish: option FIGURESNAPMETHOD currently not supported"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
303 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
304 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
305 if (! isfield (options, "imageFormat")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
306 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
307 case "latex" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
308 options.imageFormat = "epsc2"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
309 case "pdf" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
310 ## Note: Matlab R2016a uses bmp as default |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
311 options.imageFormat = "jpg"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
312 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
313 options.imageFormat = "png"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
314 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
315 elseif (! ischar (options.imageFormat)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
316 error ("publish: IMAGEFORMAT must be a string"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
317 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
318 ## Check valid imageFormat for chosen format |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
319 ## html, latex, and xml accept any imageFormat |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
320 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
321 case {"doc", "ppt"} |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
322 options.imageFormat = validatestring (options.imageFormat, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
323 {"png", "jpg", "bmp", "tiff"}); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
324 case "pdf" |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
325 options.imageFormat = validatestring (options.imageFormat, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
326 {"bmp", "jpg"}); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
327 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
328 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
329 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
330 if (! isfield (options, "maxHeight")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
331 options.maxHeight = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
332 elseif (! isscalar (options.maxHeight) || options.maxHeight < 1) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
333 error ("publish: MAXHEIGHT must be a positive integer"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
334 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
335 options.maxHeight = uint64 (options.maxHeight); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
336 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
337 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
338 if (! isfield (options, "maxWidth")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
339 options.maxWidth = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
340 elseif (! isscalar (options.maxWidth) || options.maxWidth < 1) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
341 error ("publish: MAXWIDTH must be a positive integer"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
342 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
343 options.maxWidth = uint64 (options.maxWidth); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
344 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
345 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
346 if (! isfield (options, "useNewFigure")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
347 options.useNewFigure = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
348 elseif (! isscalar (options.useNewFigure) || ! isreal (options.useNewFigure)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
349 error ("publish: USENEWFIGURE must be TRUE or FALSE"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
350 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
351 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
352 ## Options for the code |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
353 if (! isfield (options, "evalCode")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
354 options.evalCode = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
355 elseif (! isscalar (options.evalCode) || ! isreal (options.evalCode)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
356 error ("publish: EVALCODE must be TRUE or FALSE"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
357 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
358 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
359 if (! isfield (options, "catchError")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
360 options.catchError = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
361 elseif (! isscalar (options.catchError) || ! isreal (options.catchError)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
362 error ("publish: CATCHERROR must be TRUE or FALSE"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
363 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
364 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
365 if (! isfield (options, "codeToEvaluate")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
366 options.codeToEvaluate = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
367 elseif (! ischar (options.codeToEvaluate)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
368 error ("publish: CODETOEVALUTE must be a string"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
369 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
370 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
371 if (! isfield (options, "maxOutputLines")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
372 options.maxOutputLines = Inf; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
373 elseif (! isscalar (options.maxOutputLines) || options.maxOutputLines < 0) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
374 error ("publish: MAXOUTPUTLINES must be an integer >= 0"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
375 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
376 options.maxOutputLines = uint64 (options.maxOutputLines); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
377 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
378 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
379 if (! isfield (options, "showCode")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
380 options.showCode = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
381 elseif (! isscalar (options.showCode) || ! isreal (options.showCode)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
382 error ("publish: SHOWCODE must be TRUE or FALSE"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
383 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
384 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
385 doc.title = ""; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
386 doc.intro = ""; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
387 doc.body = cell (); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
388 doc.m_source = deblank (read_file_to_cellstr (file)); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
389 doc.m_source_file_name = file; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
390 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
391 ## Split code and paragraphs, find formatting |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
392 doc = parse_m_source (doc); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
393 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
394 ## Create output directory |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
395 [status, msg] = mkdir (options.outputDir); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
396 if (status != 1) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
397 error ("publish: cannot create output directory: %s", msg); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
398 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
399 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
400 if (options.evalCode) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
401 doc = eval_code (doc, options); |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
402 eval_context ("clear"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
403 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
404 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
405 output_file = create_output (doc, options); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
406 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
407 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
408 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
409 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
410 function doc = parse_m_source (doc) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
411 ## PARSE_M_SOURCE First parsing level |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
412 ## This function extracts the overall structure (paragraphs and code |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
413 ## sections) given in doc.m_source. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
414 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
415 ## The result is written to doc.body, which then contains a cell |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
416 ## vector of structs, either of |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
417 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
418 ## a) {struct ("type", "code", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
419 ## "lines", [a, b], ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
420 ## "output", [])} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
421 ## b) {struct ("type", "section", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
422 ## "content", title_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
423 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
424 ## Second parsing level is invoked for the paragraph contents, resulting |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
425 ## in more elements for doc.body. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
426 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
427 if (isempty (doc.m_source)) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
428 return; # Nothing to parse |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
429 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
430 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
431 ## Parsing helper functions |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
432 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
433 ## Checks line to have N "%" or "#" lines |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
434 ## followed either by a space or end of string |
25698
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
435 function r = is_publish_markup (cstr, N) |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
436 str = char (cstr); |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
437 |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
438 r = any (strncmp (str, {"%%%", "##"}, N)); |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
439 if (r) |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
440 len = length (str); |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
441 if (len == N) |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
442 r = true; |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
443 elseif (len > N && str(N+1) == " ") |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
444 r = true; |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
445 else |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
446 r = false; |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
447 endif |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
448 endif |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
449 |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
450 return; |
ac386820f2b6
Return true when strncmp matches, but number of characters exceeds strlen (bug #54373)
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
451 endfunction |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
452 ## Checks line of cellstring to be a paragraph line |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
453 is_paragraph = @(cstr) is_publish_markup (cstr, 1); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
454 ## Checks line of cellstring to be a section headline |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
455 is_head = @(cstr) is_publish_markup (cstr, 2); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
456 ## Checks line of cellstring to be a headline without section break, using |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
457 ## the cell mode in Matlab (for compatibility), just treated as a new head. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
458 is_no_break_head = @(cstr) is_publish_markup (cstr, 3); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
459 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
460 ## Find the indices of paragraphs starting with "%%", "##", or "%%%" |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
461 par_start_idx = find (cellfun (is_head, doc.m_source) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
462 | cellfun (is_no_break_head, doc.m_source)); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
463 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
464 ## If the whole document is code |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
465 if (isempty (par_start_idx)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
466 doc.body{end+1}.type = "code"; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
467 doc.body{end}.content = strtrim (strjoin (doc.m_source, "\n")); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
468 doc.body{end}.lines = [1, length(doc.m_source)]; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
469 doc.body{end}.output = {}; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
470 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
471 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
472 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
473 ## Determine continuous range of paragraphs |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
474 par_end_idx = [par_start_idx(2:end) - 1, length(doc.m_source)]; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
475 for i = 1:numel (par_end_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
476 idx = find (! cellfun (is_paragraph, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
477 doc.m_source(par_start_idx(i) + 1:par_end_idx(i)))); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
478 if (! isempty (idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
479 par_end_idx(i) = par_start_idx(i) + idx(1) - 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
480 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
481 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
482 ## Code sections between paragraphs |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
483 code_start_idx = par_end_idx(1:end-1) + 1; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
484 code_end_idx = par_start_idx(2:end) - 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
485 ## Code at the beginning? |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
486 if (par_start_idx(1) > 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
487 code_start_idx = [1, code_start_idx]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
488 code_end_idx = [par_start_idx(1) - 1, code_end_idx]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
489 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
490 ## Code at the end? |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
491 if (par_end_idx(end) < length (doc.m_source)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
492 code_start_idx = [code_start_idx, par_end_idx(end) + 1]; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
493 code_end_idx = [code_end_idx, length(doc.m_source)]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
494 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
495 ## Remove overlaps |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
496 idx = code_start_idx > code_end_idx; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
497 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
498 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
499 ## Remove empty code blocks |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
500 idx = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
501 for i = 1:numel (code_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
502 if (all (cellfun (@(cstr) isempty (char (cstr)), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
503 doc.m_source(code_start_idx(i):code_end_idx(i))))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
504 idx = [idx, i]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
505 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
506 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
507 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
508 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
509 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
510 ## Try to find a document title and introduction text |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
511 ## 1. First paragraph must start in first line |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
512 ## 2. Second paragraph must start before any code |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
513 title_offset = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
514 if (is_head (doc.m_source{1}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
515 && ! isempty (par_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
516 && par_start_idx(1) == 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
517 && (isempty (code_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
518 || (length (par_start_idx) > 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
519 && par_start_idx(2) < code_start_idx(1)))) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
520 doc.title = doc.m_source{1}; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
521 doc.title = doc.title(4:end); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
522 content = doc.m_source(2:par_end_idx(1)); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
523 ## Strip leading "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
524 content = cellfun (@(c) cellstr (c(3:end)), content); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
525 doc.intro = parse_paragraph_content (content); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
526 title_offset = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
527 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
528 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
529 ## Add non-empty paragraphs and code to doc |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
530 j = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
531 i = (1 + title_offset); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
532 while (i <= numel (par_start_idx) || j <= numel (code_start_idx)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
533 ## Add code while there is code left |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
534 ## and code is before the next paragraph or there are no more paragraphs |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
535 while (j <= numel (code_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
536 && (i > numel (par_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
537 || par_start_idx(i) > code_start_idx(j))) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
538 doc.body{end+1}.type = "code"; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
539 lines = [code_start_idx(j), code_end_idx(j)]; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
540 doc.body{end}.content = ... |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
541 strtrim (strjoin (doc.m_source(lines(1):lines(2)), "\n")); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
542 doc.body{end}.lines = lines; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
543 doc.body{end}.output = {}; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
544 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
545 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
546 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
547 if (i <= numel (par_start_idx)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
548 type_str = "section"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
549 title_str = doc.m_source{par_start_idx(i)}; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
550 if (is_head (doc.m_source(par_start_idx(i)))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
551 title_str = title_str(4:end); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
552 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
553 title_str = title_str(5:end); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
554 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
555 ## Append, if paragraph title is given |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
556 if (! isempty (title_str)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
557 doc.body{end+1}.type = type_str; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
558 doc.body{end}.content = title_str; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
559 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
560 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
561 content = doc.m_source(par_start_idx(i) + 1:par_end_idx(i)); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
562 ## Strip leading "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
563 content = cellfun (@(c) cellstr (c(3:end)), content); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
564 doc.body = [doc.body, parse_paragraph_content(content)]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
565 i++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
566 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
567 endwhile |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
568 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
569 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
570 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
571 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
572 function p_content = parse_paragraph_content (content) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
573 ## PARSE_PARAGRAPH_CONTENT second parsing level |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
574 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
575 ## Parses the content of a paragraph (without potential title) and |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
576 ## returns a cell vector of structs, that can be appended to doc.body, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
577 ## either of |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
578 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
579 ## a) {struct ("type", "preformatted_code", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
580 ## "content", code_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
581 ## b) {struct ("type", "preformatted_text", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
582 ## "content", text_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
583 ## c) {struct ("type", "bulleted_list", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
584 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
585 ## d) {struct ("type", "numbered_list", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
586 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
587 ## e) {struct ("type", "include", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
588 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
589 ## f) {struct ("type", "graphic", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
590 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
591 ## g) {struct ("type", "html", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
592 ## "content", html_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
593 ## h) {struct ("type", "latex", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
594 ## "content", latex_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
595 ## i) {struct ("type", "text", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
596 ## "content", text_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
597 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
598 ## Option i) might contain: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
599 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
600 ## * Italic "_", bold "*", and monospaced "|" text |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
601 ## * Inline "$" and block "$$" LaTeX math |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
602 ## * Links |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
603 ## * Trademark symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
604 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
605 p_content = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
606 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
607 if (isempty (content)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
608 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
609 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
610 |
23926
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
611 ## Extract <html> and <latex> blocks recursively. |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
612 content_str = strjoin (content, "\n"); |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
613 tags = {"html", "latex"}; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
614 for i = 1:length(tags) |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
615 tok = regexp (content_str, ... |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
616 ['(.*?)(^|\n\n)(<', tags{i}, '>)\n(.*?)\n(<\/', ... |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
617 tags{i}, '>)($|\n\n)(.*)'], "tokens", "once"); |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
618 if (! isempty (tok)) |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
619 ## If there was some text before that block --> recursion |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
620 if (! strcmpi (tok{1}, ["<", tags{i}, ">"])) |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
621 p_content = parse_paragraph_content (strsplit (tok{1}, "\n")); |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
622 tok(1:2) = []; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
623 endif |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
624 ## Extract the block content |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
625 p_content{end+1}.type = tags{i}; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
626 p_content{end}.content = tok{2}; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
627 ## If there was some text after that block --> recursion |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
628 if (length (tok) == 5) |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
629 p_content = [p_content, ... |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
630 parse_paragraph_content(strsplit (tok{5}, "\n"))]; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
631 endif |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
632 return; |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
633 endif |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
634 endfor |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
635 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
636 ## Split into blocks separated by empty lines |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
637 idx = [0, find(cellfun (@isempty, content)), length(content) + 1]; |
23926
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
638 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
639 ## For each block |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
640 for i = find (diff (idx) > 1) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
641 block = content(idx(i) + 1:idx(i+1) - 1); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
642 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
643 ## Octave code (two leading spaces) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
644 if (all (cellfun (@(c) strncmp (char (c), " ", 2), block))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
645 p_content{end+1}.type = "preformatted_code"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
646 block = cellfun (@(c) cellstr (c(3:end)), block); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
647 p_content{end}.content = strjoin (block, "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
648 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
649 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
650 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
651 ## Preformatted text (one leading space) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
652 if (all (cellfun (@(c) strncmp (char (c), " ", 1), block))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
653 p_content{end+1}.type = "preformatted_text"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
654 block = cellfun (@(c) cellstr (c(2:end)), block); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
655 p_content{end}.content = strjoin (block, "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
656 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
657 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
658 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
659 ## Bulleted list starts with "* " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
660 if (strncmp (block{1}, "* ", 2)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
661 p_content{end+1}.type = "bulleted_list"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
662 tmpstr = strjoin (block, "\n"); |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
663 ## Remove first "* " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
664 tmpstr = tmpstr(3:end); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
665 ## Split items |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
666 p_content{end}.content = strsplit (tmpstr, "\n* "); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
667 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
668 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
669 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
670 ## Numbered list starts with "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
671 if (strncmp (block{1}, "# ", 2)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
672 p_content{end+1}.type = "numbered_list"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
673 tmpstr = strjoin (block, "\n"); |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
674 ## Remove first "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
675 tmpstr = tmpstr(3:end); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
676 ## Split items |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
677 p_content{end}.content = strsplit (tmpstr, "\n# "); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
678 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
679 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
680 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
681 ## Include <include>fname.m</include> |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
682 if (! isempty (fname = regexpi (strjoin (block, ""), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
683 '^<include>(.*)</include>$', |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
684 "tokens"))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
685 ## Includes result in preformatted code |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
686 p_content{end+1}.type = "preformatted_code"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
687 include_code = read_file_to_cellstr (strtrim ((fname{1}){1})); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
688 p_content{end}.content = strjoin (include_code, "\n"); |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22113
diff
changeset
|
689 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
690 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
691 endif |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22113
diff
changeset
|
692 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
693 ## Graphic <<myGraphic.png>> |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
694 if (! isempty (fname = regexpi (strjoin (block, ""), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
695 '^<<(.*)>>$', |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
696 "tokens"))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
697 p_content{end+1}.type = "graphic"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
698 p_content{end}.content = strtrim ((fname{1}){1}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
699 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
700 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
701 |
23926
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
702 ## Now it can be only normal text or markups belonging to normal text |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
703 ## that are handled while output generation: |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
704 ## |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
705 ## * Italic "_", bold "*", and monospaced "|" text |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
706 ## * Inline "$" and block "$$" LaTeX math |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
707 ## * Links |
58b76c741c3d
publish: improve detecion of block markup (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23923
diff
changeset
|
708 ## * Trademark symbols |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
709 p_content{end+1}.type = "text"; |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
710 p_content{end}.content = strjoin (block, "\n"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
711 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
712 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
713 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
714 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
715 function m_source = read_file_to_cellstr (file) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
716 ## READ_FILE_TO_CELLSTR reads a given file line by line into a cellstring |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
717 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
718 fid = fopen (file, "r"); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
719 i = 0; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
720 do |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
721 m_source{++i} = fgetl (fid); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
722 until (! ischar (m_source{i})) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
723 fclose (fid); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
724 m_source = m_source(1:end-1); # No EOL |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
725 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
726 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
727 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
728 function ofile = create_output (doc, options) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
729 ## CREATE_OUTPUT creates the desired output file |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
730 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
731 formatter = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
732 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
733 case "html" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
734 formatter = @__publish_html_output__; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
735 case {"latex", "pdf"} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
736 formatter = @__publish_latex_output__; |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
737 otherwise |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
738 ## Custom formatter |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
739 formatter = eval (["@__publish_", options.format, "_output__"]); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
740 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
741 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
742 ## Use title, or if not given, the m-file name |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
743 title_str = doc.title; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
744 if (isempty (title_str)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
745 [~, title_str] = fileparts (doc.m_source_file_name); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
746 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
747 |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
748 content = formatter ("header", |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
749 formatter ("escape_special_chars", title_str), |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
750 format_output (doc.intro, formatter, options), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
751 get_toc (doc.body, formatter)); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
752 content = [content, format_output(doc.body, formatter, options)]; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
753 content = [content, formatter("footer", strjoin (doc.m_source, "\n"))]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
754 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
755 ## Write file |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
756 [~, ofile] = fileparts (doc.m_source_file_name); |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
757 ofile_name = [ofile, formatter("output_file_extension")]; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
758 ofile = fullfile (options.outputDir, ofile_name); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
759 fid = fopen (ofile, "w"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
760 fputs (fid, content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
761 fclose (fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
762 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
763 ## Compile LaTeX, if compiler found |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
764 if (strcmp (options.format, "pdf")) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
765 status = system ("pdflatex --version"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
766 if (status == 0) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
767 for i = 1:2 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
768 ## FIXME: This looks very likely to break when switching OS |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
769 system (["cd ", options.outputDir," && pdflatex ", ofile_name]); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
770 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
771 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
772 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
773 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
774 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
775 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
776 function toc_cstr = get_toc (cstr, formatter) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
777 ## GET_TOC extracts the table of contents from a cellstring (e.g., doc.body) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
778 ## with each section headline as a cell in a returned cellstring. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
779 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
780 toc_cstr = cell (); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
781 for i = 1:numel (cstr) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
782 if (strcmp (cstr{i}.type, "section")) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
783 toc_cstr{end+1} = format_text (cstr{i}.content, formatter); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
784 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
785 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
786 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
787 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
788 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
789 function str = format_output (cstr, formatter, options) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
790 ## FORMAT_OUTPUT steps through all blocks (doc.intro or doc.body) in cstr and |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
791 ## produces a single result string with the source code in the desired output |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
792 ## format. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
793 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
794 ## formatter has the only knowledge how to enforce the target format |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
795 ## and produces for each block the necessary target format source string. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
796 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
797 str = ""; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
798 for i = 1:numel (cstr) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
799 switch (cstr{i}.type) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
800 case "code" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
801 if (options.showCode) |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
802 str = [str, formatter("code", cstr{i}.content)]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
803 endif |
23191
5f79bb3fdd28
* scripts/general/publish.m: Avoid creation of empty ouput blocks.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23188
diff
changeset
|
804 if ((options.evalCode) && (! isempty (cstr{i}.output))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
805 str = [str, formatter("code_output", cstr{i}.output)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
806 endif |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
807 case {"text", "section"} |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
808 str = [str, formatter(cstr{i}.type, ... |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
809 format_text (cstr{i}.content, formatter))]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
810 case {"bulleted_list", "numbered_list"} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
811 items = cellfun (@(str) format_text(str, formatter), ... |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
812 cstr{i}.content, "UniformOutput", false); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
813 str = [str, formatter(cstr{i}.type, items)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
814 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
815 str = [str, formatter(cstr{i}.type, cstr{i}.content)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
816 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
817 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
818 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
819 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
820 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
821 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
822 function str = format_text (str, formatter) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
823 ## FORMAT_TEXT formats inline formats in strings. |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
824 ## These are: links, block/inline math, bold, italic, monospaced, (TM), (R) |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
825 |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
826 ## Helper to clarify the following regular expressions. It is suitable for |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
827 ## inline formatting, that is delimited literally at start and end by |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
828 ## 'delim'. 'term' is an indicating character for the end delimiter. |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
829 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
830 ## Best explained by example ('^' start and '$' end of input): |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
831 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
832 ## Positive matches: |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
833 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
834 ## ^*bold*$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
835 ## ^*bold*.$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
836 ## ^(*bold*)$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
837 ## ^ *bold* $ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
838 ## ^Text *bold* text$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
839 ## ^*bold text*$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
840 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
841 ## Negative matches: |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
842 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
843 ## ^Text*bold*text$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
844 ## ^*bold *$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
845 ## ^* bold* $ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
846 ## ^*bold text *$ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
847 ## |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
848 regex_helper = @(delim, term) ['(^|(?<=\s)|(?=\W))', delim, ... |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
849 '(?!\s)[^', term, ']*(?<!\s)', delim, '($|(?=\s)|(?=\W))']; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
850 |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
851 ## Regular expressions for the formats: |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
852 ## |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
853 ## 1) Links "<http://www.someurl.com>" |
27846
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
854 ## 2) Links "<octave:Function SOME TEXT>" |
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
855 ## 3) Links "<http://www.someurl.com SOME TEXT>" |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
856 ## 4) LaTeX block math "$$x^2$$" |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
857 ## 5) LaTeX inline math "$x^2$" |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
858 ## 6) Bold *text* |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
859 ## 7) Italic _text_ |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
860 ## 8) Monospaced |text| |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
861 ## 9) (TM) or (R) |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
862 regexes = {'<\S{3,}[^\s<>]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
863 '<octave:[^\s<>]* *[^<>$]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
864 '<\S{3,}[^\s<>]* *[^<>$]*>', ... |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
865 regex_helper('\$\$', '$'), ... |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
866 regex_helper('\$', '$'), ... |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
867 regex_helper('\*', '*'), ... |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
868 regex_helper('_', '_'), ... |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
869 regex_helper('\|', '|'), ... |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
870 '\((TM|R)\)'}; |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
871 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
872 ## Function to escape some special characters for the GNU Octave manual, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
873 ## see https://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
874 texinfo_esc = @(str) strrep (strrep (str, "-", "_002d"), "_", "_005f"); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
875 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
876 ## Substitute all occurrences with placeholders |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
877 placeholder_cstr = {}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
878 plh = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
879 for i = 1:numel (regexes) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
880 cstr = regexp (str, regexes{i}, "match"); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
881 for j = 1:numel (cstr) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
882 plh += 1; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
883 str = regexprep (str, regexes{i}, ["PUBLISHPLACEHOLDER" num2str(plh)], |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
884 "once"); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
885 switch (i) |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
886 case 1 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
887 ## Links "<http://www.someurl.com>" |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
888 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
889 cstr{j} = formatter ("link", url(2:end-1), url(2:end-1)); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
890 case 2 |
27846
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
891 ## Links "<octave:Function SOME TEXT>" |
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
892 idx = strfind (cstr{j}, " ")(1); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
893 url = cstr{j}; |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
894 url = texinfo_esc (url(9:idx-1)); |
23317
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
895 v = version (); |
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
896 if (v(end) == '+') |
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
897 v = "interpreter"; |
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
898 endif |
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
899 url = sprintf ( ... |
ef94844a3c12
* publish.m: Refer to the online manual of the current Octave version.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23220
diff
changeset
|
900 "https://www.gnu.org/software/octave/doc/%s/XREF%s.html", v, url); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
901 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
902 txt = format_text (txt(idx+1:end-1), formatter); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
903 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
904 case 3 |
27846
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
905 ## Links "<http://www.someurl.com SOME TEXT>" |
4075474fd9d0
fix URL parsing of `publish` (bug #57426).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
27216
diff
changeset
|
906 idx = strfind (cstr{j}, " ")(1); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
907 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
908 url = url(2:idx-1); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
909 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
910 txt = format_text (txt(idx+1:end-1), formatter); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
911 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
912 case 4 |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
913 ## LaTeX block math "$$" |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
914 txt = cstr{j}; |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
915 cstr{j} = formatter ("blockmath", txt(3:end-2)); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
916 case 5 |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
917 ## LaTeX inline math "$" |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
918 txt = cstr{j}; |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
919 cstr{j} = formatter ("inlinemath", txt(2:end-1)); |
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
920 case 6 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
921 ## Bold |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
922 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
923 cstr{j} = formatter ("bold", format_text (txt(2:end-1), formatter)); |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
924 case 7 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
925 ## Italic |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
926 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
927 cstr{j} = formatter ("italic", format_text (txt(2:end-1), formatter)); |
23923
62dc81691d73
publish: improve detection of inline markup and fix MathJax usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23921
diff
changeset
|
928 case 8 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
929 ## Monospaced |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
930 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
931 cstr{j} = formatter ("monospaced", format_text (txt(2:end-1), ... |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
932 formatter)); |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
933 case 9 |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
934 ## (TM) or (R) |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
935 txt = cstr{j}; |
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
936 cstr{j} = formatter (txt(2:end-1)); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
937 endswitch |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
938 endfor |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
939 placeholder_cstr = [placeholder_cstr, cstr]; |
22306
2cd1afd0f12f
publish.m: prevent formatting of inline and block math.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22299
diff
changeset
|
940 endfor |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
941 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
942 ## Replace special symbols |
23964
1a0cbb573a67
publish: Improve escaping of special characters in output (bug #51782)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23926
diff
changeset
|
943 str = formatter ("escape_special_chars", str); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
944 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
945 ## Restore placeholders |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
946 for i = plh:-1:1 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
947 str = strrep (str, ["PUBLISHPLACEHOLDER" sprintf("%d", i)], |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
948 placeholder_cstr{i}); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
949 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
950 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
951 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
952 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
953 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
954 function doc = eval_code (doc, options) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
955 ## EVAL_CODE Third level parsing |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
956 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
957 ## Generates the output of the script code and takes care of generated |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
958 ## figures. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
959 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
960 ## Necessary as the code does not run interactively |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
961 page_screen_output (false, "local"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
962 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
963 ## Remember previously opened figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
964 fig_ids = findall (0, "type", "figure"); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
965 [~, fig_name] = fileparts (doc.m_source_file_name); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
966 fig_num = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
967 fig_list = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
968 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
969 ## Evaluate code, that does not appear in the output. |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
970 eval_code_helper (options.codeToEvaluate); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
971 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
972 ## Create a new figure, if there are existing plots |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
973 if (! isempty (fig_ids) && options.useNewFigure) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
974 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
975 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
976 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
977 for i = 1:numel (doc.body) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
978 if (strcmp (doc.body{i}.type, "code")) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
979 r = doc.body{i}.lines; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
980 code_str = strjoin (doc.m_source(r(1):r(2)), "\n"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
981 if (options.catchError) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
982 try |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
983 doc.body{i}.output = eval_code_helper (code_str); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
984 catch err |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
985 doc.body{i}.output = cellstr (["error: ", err.message, ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
986 "\n\tin:\n\n", code_str]); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
987 end_try_catch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
988 else |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
989 doc.body{i}.output = eval_code_helper (code_str); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
990 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
991 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
992 ## Check for newly created figures ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
993 fig_ids_new = setdiff (findall (0, "type", "figure"), fig_ids); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
994 ## ... and save them |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
995 for j = 1:numel (fig_ids_new) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
996 drawnow (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
997 if (isempty (get (fig_ids_new(j), "children"))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
998 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
999 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1000 fname = [fig_name, "-", sprintf("%d", fig_num)]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1001 if (strncmp (options.imageFormat, "eps", 3)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1002 fname = [fname ".eps"]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1003 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1004 fname = [fname "." options.imageFormat]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1005 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1006 print_opts = {fig_ids_new(j), ... |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1007 fullfile(options.outputDir, fname), ... |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1008 ["-d" options.imageFormat], "-color"}; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1009 if (! isempty (options.maxWidth) && ! isempty (options.maxHeight)) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
1010 print_opts{end+1} = sprintf ("-S%d,%d", options.maxWidth, |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
1011 options.maxHeight); |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
1012 elseif (! isempty (options.maxWidth) || ! isempty (options.maxHeight)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1013 warning (["publish: specify both options.maxWidth ", ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
1014 "and options.maxHeight"]); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1015 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1016 print (print_opts{:}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1017 fig_num++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1018 delete (fig_ids_new(j)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1019 fig_elem = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1020 fig_elem{1} = struct ("type", "graphic", "content", fname); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1021 if (isfield (fig_list, num2str (i))) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1022 fig_elem = [getfield(fig_list, sprintf ("%d", i)), fig_elem]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1023 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1024 fig_list = setfield (fig_list, sprintf ("%d", i), fig_elem); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1025 ## Create a new figure, if there are existing plots |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1026 if (isempty (setdiff (findall (0, "type", "figure"), fig_ids)) ... |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1027 && ! isempty (fig_ids) && options.useNewFigure) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1028 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1029 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1030 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1031 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1032 ## Truncate output to desired length |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1033 if (options.maxOutputLines < length (doc.body{i}.output)) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1034 doc.body{i}.output = doc.body{i}.output(1:options.maxOutputLines); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1035 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1036 doc.body{i}.output = strjoin (doc.body{i}.output, "\n"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1037 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1038 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1039 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1040 ## Close any figures opened by publish function |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1041 delete (setdiff (findall (0, "type", "figure"), fig_ids)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1042 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1043 ## Insert figures to document |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1044 fig_code_blocks = fieldnames (fig_list); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1045 body_offset = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1046 for i = 1:numel (fig_code_blocks) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1047 elems = getfield (fig_list, fig_code_blocks{i}); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1048 ## Compute index where the figure(s) has to be inserted |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1049 j = str2double (fig_code_blocks{i}) + body_offset; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1050 doc.body = [doc.body(1:j), elems, doc.body(j+1:end)]; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1051 body_offset = body_offset + numel (elems); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1052 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1053 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1054 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1055 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1056 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1057 function cstr = eval_code_helper (__code__) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1058 ## EVAL_CODE_HELPER evaluates a given string with Octave code in an extra |
23547
8133a5041662
publish.m: Fix corruption of results for some code inputs (bug #51178).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1059 ## temporary context and returns a cellstring with the eval output. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1060 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1061 if (isempty (__code__)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1062 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1063 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1064 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1065 eval_context ("load"); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1066 cstr = evalc (__code__); |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1067 ## Split string by lines and preserve blank lines. |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1068 cstr = strsplit (strrep (cstr, "\n\n", "\n \n"), "\n"); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1069 eval_context ("save"); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1070 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1071 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1072 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1073 function cstr = eval_context (op) |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1074 ## EVAL_CONTEXT temporary evaluation context. |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1075 persistent ctext |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1076 |
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1077 ## Variable cstr in "eval_code_helper" is newly created anyways. |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1078 forbidden_var_names = {"__code__"}; |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1079 |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1080 switch (op) |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1081 case "save" |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1082 ## Clear previous context |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1083 ctext = containers.Map; |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1084 ## Get variable names |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1085 var_names = evalin ("caller", "whos"); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1086 var_names = {var_names.name}; |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1087 ## Store all variables to context |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1088 for i = 1:length (var_names) |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1089 if (! any (strcmp (var_names{i}, forbidden_var_names))) |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1090 ctext(var_names{i}) = evalin ("caller", var_names{i}); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1091 end |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1092 endfor |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1093 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1094 case "load" |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1095 if (! isempty (ctext)) |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1096 keys = ctext.keys (); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1097 for i = 1:length (keys) |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1098 assignin ("caller", keys{i}, ctext(keys{i})); |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1099 endfor |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1100 endif |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1101 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1102 case "clear" |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1103 ## Clear any context |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1104 ctext = []; |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1105 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1106 otherwise |
25750
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1107 ## Do nothing |
e30a2492eb85
publish.m: Use Octave coding conventions for comments and logical negation.
Rik <rik@octave.org>
parents:
25749
diff
changeset
|
1108 |
25749
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1109 endswitch |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1110 endfunction |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1111 |
af43eb4e6502
publish.m: Improve code evaluation and add classdef support.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
25698
diff
changeset
|
1112 |
27216
823b4bcf79fc
unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1113 ## Note: Functional BIST tests are located in the 'test/publish' directory. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1114 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1115 ## Test input validation |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1116 %!error publish () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1117 %!error publish (1) |
22706 | 1118 %!error <FILE does not exist> publish ("%%_non_existent_file_%%.m") |
1119 %!error <only script files can be published> publish ("publish.m") | |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1120 %!error publish ("test_script.m", "format", "html", "showCode") |