Mercurial > octave
annotate scripts/general/publish.m @ 23549:c8daadf7543b
publish.m: Use Octave coding conventions.
* publish.m: use Octave coding conventions. Use double quotes for strings
which contain escaped characters such as newlines. Correct input validation
test when only one option of maxWidth or maxHeight is set. Rename temporary
file to have extension ".var" rather than ".mat" since it is not a .mat file.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 06 Jun 2017 15:11:33 -0700 |
parents | 05bbca224a14 |
children | ab1aa0e57b72 |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
22707
diff
changeset
|
1 ## Copyright (C) 2016-2017 Kai T. Ohlhus <k.ohlhus@gmail.com> |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
2 ## Copyright (C) 2010 Fotios Kasolis <fotios.kasolis@gmail.com> |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
3 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
4 ## 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
|
5 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
9 ## (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
|
10 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
11 ## 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
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22708
diff
changeset
|
14 ## 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
|
15 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
16 ## 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
|
17 ## along with Octave; see the file COPYING. If not, see |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
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 ## -*- texinfo -*- |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
21 ## @deftypefn {} {} publish (@var{file}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
22 ## @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
|
23 ## @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
|
24 ## @deftypefnx {} {} publish (@var{file}, @var{options}) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
25 ## @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
|
26 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
27 ## 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
|
28 ## output formats. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
29 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
30 ## 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
|
31 ## 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
|
32 ## 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
|
33 ## @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
|
34 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
35 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
36 ## @group |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
37 ## ## Headline title |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
38 ## # |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
39 ## # Some *bold*, _italic_, or |monospaced| Text with |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
40 ## # a <http://www.octave.org link to *GNU Octave*>. |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
41 ## ## |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
42 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
43 ## # "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
|
44 ## sombrero () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
45 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
46 ## %% @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
|
47 ## % |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
48 ## % * Bulleted list item 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
49 ## % * Bulleted list item 2 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
50 ## % |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
51 ## % # Numbered list item 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
52 ## % # 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
|
53 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
54 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
55 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
56 ## 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
|
57 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
58 ## 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
|
59 ## @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
|
60 ## 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
|
61 ## 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
|
62 ## @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
|
63 ## in the report. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
64 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
65 ## 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
|
66 ## 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
|
67 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
68 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
69 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
70 ## @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
|
71 ## 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
|
72 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
73 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
74 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
75 ## @noindent |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
76 ## 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
|
77 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
78 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
79 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
80 ## @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
|
81 ## 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
|
82 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
83 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
84 ## |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
85 ## 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
|
86 ## 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
|
87 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
88 ## @itemize @bullet |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
89 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
90 ## @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
|
91 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
92 ## @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
|
93 ## @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
|
94 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
95 ## 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
|
96 ## 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
|
97 ## 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
|
98 ## |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
99 ## 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
|
100 ## 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
|
101 ## @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
|
102 ## HTML format type: |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
103 ## |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
104 ## @example |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
105 ## @group |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
106 ## edit (fullfile (fileparts (which ("publish")), ... |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
107 ## "private", "__publish_html_output__.m")) |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
108 ## @end group |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
109 ## @end example |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
110 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
111 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
112 ## @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
|
113 ## 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
|
114 ## 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
|
115 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
116 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
117 ## @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
|
118 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
119 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
120 ## @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
|
121 ## compatibility. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
122 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
123 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
124 ## @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
|
125 ## compatibility. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
126 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
127 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
128 ## @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
|
129 ## 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
|
130 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
131 ## @itemize @bullet |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
132 ## @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
|
133 ## supported by Octave |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
134 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
135 ## @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
|
136 ## Octave |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
137 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
138 ## @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
|
139 ## 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
|
140 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
141 ## @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
|
142 ## @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
|
143 ## @end itemize |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
144 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
145 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
146 ## @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
|
147 ## 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
|
148 ## 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
|
149 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
150 ## @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
|
151 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
152 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
153 ## @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
|
154 ## 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
|
155 ## windows. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
156 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
157 ## @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
|
158 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
159 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
160 ## @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
|
161 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
162 ## @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
|
163 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
164 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
165 ## @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
|
166 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
167 ## @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
|
168 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
169 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
170 ## @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
|
171 ## 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
|
172 ## generated report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
173 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
174 ## @item |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
175 ## @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
|
176 ## 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
|
177 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
178 ## @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
|
179 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
180 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
181 ## @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
|
182 ## report |
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{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
|
185 ## @end itemize |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
186 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
187 ## 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
|
188 ## of the generated 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 ## @seealso{grabcode} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
191 ## @end deftypefn |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
192 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
193 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
|
194 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
195 if (nargin < 1) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
196 print_usage (); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
197 endif |
22113
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 if (exist (file, "file") != 2) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
200 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
|
201 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
202 |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
203 ## 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
|
204 [file_path, file_name, file_ext] = fileparts (file); |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
205 if (isempty (file_path)) |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
206 file_path = pwd; |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
207 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
208 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
|
209 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
|
210 endif |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
211 |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
212 ## 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
|
213 file_info = __which__ (file_name); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
214 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
|
215 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
|
216 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
217 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
218 ## 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
|
219 __parse_file__ (file); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
220 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
221 ## 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
|
222 options = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
223 if (numel (varargin) == 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
224 ## Call: publish (file, format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
225 if (ischar (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
226 options.format = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
227 ## Call: publish (file, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
228 elseif (isstruct (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
229 options = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
230 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
231 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
|
232 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
233 ## 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
|
234 elseif (rem (numel (varargin), 2) == 0 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
235 && 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
|
236 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
|
237 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
238 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
|
239 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
240 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
241 ## Validate options struct |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
242 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
243 ## Options for the output |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
244 if (! isfield (options, "format")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
245 options.format = "html"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
246 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
247 ## FIXME: Implement remaining formats |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
248 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
|
249 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
|
250 options.format); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
251 endif |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
252 ## Supported or custom output format |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
253 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
|
254 if (! any (strcmpi (options.format, supported_formats))) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
255 ## 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
|
256 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
|
257 if (! exist (custom_formatter, "file")) |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
258 error (['publish: Custom output format "%s" requires the ', ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
259 "formatter function:\n\n\t%s\n\n\t", ... |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
260 '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
|
261 options.format, custom_formatter); |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
262 endif |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
263 else |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
264 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
|
265 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
266 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
267 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
268 if (! isfield (options, "outputDir")) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
269 ## 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
|
270 ## 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
|
271 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
|
272 elseif (! ischar (options.outputDir)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
273 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
|
274 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
275 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
276 if (! isfield (options, "stylesheet")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
277 options.stylesheet = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
278 elseif (! ischar (options.stylesheet)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
279 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
|
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 ## Options for the figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
283 if (! isfield (options, "createThumbnail")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
284 options.createThumbnail = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
285 elseif (! isscalar (options.createThumbnail) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
286 || ! isreal (options.createThumbnail)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
287 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
|
288 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
289 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
290 if (! isfield (options, "figureSnapMethod")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
291 options.figureSnapMethod = "entireGUIWindow"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
292 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
293 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
|
294 {"entireGUIWindow", "print", "getframe", "entireFigureWindow"}); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
295 ## FIXME: implement other SnapMethods |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
296 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
|
297 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
298 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
299 if (! isfield (options, "imageFormat")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
300 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
301 case "latex" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
302 options.imageFormat = "epsc2"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
303 case "pdf" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
304 ## 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
|
305 options.imageFormat = "jpg"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
306 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
307 options.imageFormat = "png"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
308 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
309 elseif (! ischar (options.imageFormat)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
310 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
|
311 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
312 ## 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
|
313 ## 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
|
314 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
315 case {"doc", "ppt"} |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
316 options.imageFormat = validatestring (options.imageFormat, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
317 {"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
|
318 case "pdf" |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
319 options.imageFormat = validatestring (options.imageFormat, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
320 {"bmp", "jpg"}); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
321 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
322 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
323 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
324 if (! isfield (options, "maxHeight")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
325 options.maxHeight = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
326 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
|
327 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
|
328 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
329 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
|
330 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
331 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
332 if (! isfield (options, "maxWidth")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
333 options.maxWidth = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
334 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
|
335 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
|
336 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
337 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
|
338 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
339 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
340 if (! isfield (options, "useNewFigure")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
341 options.useNewFigure = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
342 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
|
343 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
|
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 ## Options for the code |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
347 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
|
348 options.evalCode = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
349 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
|
350 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
|
351 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
352 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
353 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
|
354 options.catchError = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
355 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
|
356 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
|
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, "codeToEvaluate")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
360 options.codeToEvaluate = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
361 elseif (! ischar (options.codeToEvaluate)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
362 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
|
363 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
364 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
365 if (! isfield (options, "maxOutputLines")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
366 options.maxOutputLines = Inf; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
367 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
|
368 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
|
369 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
370 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
|
371 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
372 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
373 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
|
374 options.showCode = true; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
375 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
|
376 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
|
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 doc.title = ""; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
380 doc.intro = ""; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
381 doc.body = cell (); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
382 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
|
383 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
|
384 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
385 ## 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
|
386 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
|
387 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
388 ## Create output directory |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
389 [status, msg] = mkdir (options.outputDir); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
390 if (status != 1) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
391 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
|
392 endif |
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 if (options.evalCode) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
395 doc = eval_code (doc, options); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
396 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
397 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
398 output_file = create_output (doc, options); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
399 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
400 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
401 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
402 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
403 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
|
404 ## 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
|
405 ## 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
|
406 ## 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
|
407 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
408 ## 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
|
409 ## 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
|
410 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
411 ## a) {struct ("type", "code", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
412 ## "lines", [a, b], ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
413 ## "output", [])} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
414 ## b) {struct ("type", "section", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
415 ## "content", title_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
416 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
417 ## 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
|
418 ## 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
|
419 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
420 if (isempty (doc.m_source)) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
421 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
|
422 endif |
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 ## Parsing helper functions |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
425 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
426 ## Checks line to have N "%" or "#" lines |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
427 ## followed either by a space or end of string |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
428 is_publish_markup = @(cstr, N) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
429 any (strncmp (char (cstr), {"%%%", "##"}, N)) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
430 && ((length (char (cstr)) == N) || ((char (cstr))(N + 1) == " ")); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
431 ## 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
|
432 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
|
433 ## 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
|
434 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
|
435 ## 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
|
436 ## 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
|
437 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
|
438 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
439 ## 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
|
440 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
|
441 | 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
|
442 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
443 ## 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
|
444 if (isempty (par_start_idx)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
445 doc.body{end+1}.type = "code"; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
450 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
451 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
452 ## Determine continuous range of paragraphs |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
453 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
|
454 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
|
455 idx = find (! cellfun (is_paragraph, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
456 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
|
457 if (! isempty (idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
458 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
|
459 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
460 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
461 ## Code sections between paragraphs |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
462 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
|
463 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
|
464 ## Code at the beginning? |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
465 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
|
466 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
|
467 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
|
468 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
469 ## Code at the end? |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
470 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
|
471 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
|
472 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
|
473 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
474 ## Remove overlaps |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
475 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
|
476 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
477 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
478 ## Remove empty code blocks |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
479 idx = []; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 idx = [idx, i]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
484 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
485 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
486 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
487 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
488 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
489 ## 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
|
490 ## 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
|
491 ## 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
|
492 title_offset = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
493 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
|
494 && ! isempty (par_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
495 && par_start_idx(1) == 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
496 && (isempty (code_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
497 || (length (par_start_idx) > 1 |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
498 && 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
|
499 doc.title = doc.m_source{1}; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
500 doc.title = doc.title(4:end); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
501 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
|
502 ## Strip leading "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
503 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
|
504 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
|
505 title_offset = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
506 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
507 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
508 ## 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
|
509 j = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
510 i = (1 + title_offset); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
511 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
|
512 ## 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
|
513 ## 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
|
514 while (j <= numel (code_start_idx) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
515 && (i > numel (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(i) > code_start_idx(j))) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
517 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
|
518 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
|
519 doc.body{end}.content = ... |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
520 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
|
521 doc.body{end}.lines = lines; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
522 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
|
523 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
524 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
525 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
526 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
|
527 type_str = "section"; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
528 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
|
529 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
|
530 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
|
531 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
532 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
|
533 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
534 ## 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
|
535 if (! isempty (title_str)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
536 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
|
537 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
|
538 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
539 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
540 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
|
541 ## Strip leading "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
542 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
|
543 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
|
544 i++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
545 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
546 endwhile |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
547 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
548 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
549 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
550 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
551 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
|
552 ## 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
|
553 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
554 ## 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
|
555 ## 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
|
556 ## either of |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
557 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
558 ## 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
|
559 ## "content", code_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
560 ## 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
|
561 ## "content", text_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
562 ## 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
|
563 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
564 ## 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
|
565 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
566 ## e) {struct ("type", "include", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
567 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
568 ## f) {struct ("type", "graphic", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
569 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
570 ## g) {struct ("type", "html", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
571 ## "content", html_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
572 ## h) {struct ("type", "latex", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
573 ## "content", latex_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
574 ## i) {struct ("type", "text", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
575 ## "content", text_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
576 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
577 ## Option i) might contain: |
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 ## * 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
|
580 ## * 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
|
581 ## * Links |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
582 ## * Trademark symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
583 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
584 p_content = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
585 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
586 if (isempty (content)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
587 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
588 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
589 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
590 ## 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
|
591 idx = [0, find(cellfun (@isempty, content)), length(content) + 1]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
592 ## For each block |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
593 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
|
594 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
|
595 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
596 ## 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
602 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
603 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
604 ## 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
610 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
611 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
612 ## Bulleted list starts with "* " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
613 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
|
614 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
|
615 tmpstr = strjoin (block, "\n"); |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
616 ## Remove first "* " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
617 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
|
618 ## Split items |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
619 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
|
620 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
621 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
622 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
623 ## Numbered list starts with "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
624 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
|
625 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
|
626 tmpstr = strjoin (block, "\n"); |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
627 ## Remove first "# " |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
628 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
|
629 ## Split items |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
630 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
|
631 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
632 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
633 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
634 ## Include <include>fname.m</include> |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
635 if (! isempty (fname = regexpi (strjoin (block, ""), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
636 '^<include>(.*)</include>$', |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
637 "tokens"))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
638 ## 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
|
639 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
|
640 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
|
641 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
|
642 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
643 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
644 endif |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22113
diff
changeset
|
645 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
646 ## Graphic <<myGraphic.png>> |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
647 if (! isempty (fname = regexpi (strjoin (block, ""), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
648 '^<<(.*)>>$', |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
649 "tokens"))) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
650 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
|
651 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
|
652 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
653 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
654 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
655 ## Parse remaining blocks line by line |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
656 j = 1; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
657 while (j <= numel (block)) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
658 ## HTML markup |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
659 if (strcmpi (block{j}, "<html>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
660 start_html = j + 1; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
661 while (j < numel (block) && ! strcmpi (block{j}, "</html>")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
662 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
663 endwhile |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
664 if (j == numel (block) && ! strcmpi (block{j}, "</html>")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
665 warning ("publish: no closing </html> found"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
666 else |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
667 j++; # Skip closing tag |
22113
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 if (j > start_html) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
670 p_content{end+1}.type = "html"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
671 p_content{end}.content = strjoin (block(start_html:j-2), "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
672 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
673 ## LaTeX markup |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
674 elseif (strcmpi (block{j}, "<latex>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
675 start_latex = j + 1; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
676 while (j < numel (block) && ! strcmpi (block{j}, "</latex>")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
677 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
678 endwhile |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
679 if (j == numel (block) && ! strcmpi (block{j}, "</latex>")) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
680 warning ("publish: no closing </latex> found"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
681 else |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
682 j++; # Skip closing tag |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
683 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
684 if (j > start_latex) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
685 p_content{end+1}.type = "latex"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
686 p_content{end}.content = strjoin (block(start_latex:j-2), "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
687 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
688 ## Remaining normal text or markups belonging to normal text |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
689 ## that are handled while output generation: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
690 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
691 ## * 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
|
692 ## * 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
|
693 ## * Links |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
694 ## * Trademark symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
695 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
696 if (j == 1 || isempty (p_content) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
697 || ! strcmp (p_content{end}.type, "text")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
698 p_content{end+1}.type = "text"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
699 p_content{end}.content = block{j}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
700 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
701 p_content{end}.content = strjoin ({p_content{end}.content, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
702 block{j}}, "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
703 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
704 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
705 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
706 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
707 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
708 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
709 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
710 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
711 function m_source = read_file_to_cellstr (file) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
712 ## 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
|
713 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
714 fid = fopen (file, "r"); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
715 i = 0; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
716 do |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
717 m_source{++i} = fgetl (fid); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
718 until (! ischar (m_source{i})) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
719 fclose (fid); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
720 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
|
721 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
722 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
723 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
724 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
|
725 ## 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
|
726 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
727 formatter = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
728 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
729 case "html" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
730 formatter = @__publish_html_output__; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
731 case {"latex", "pdf"} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
732 formatter = @__publish_latex_output__; |
23188
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
733 otherwise |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
734 ## Custom formatter |
e2e182a8e699
Allow custom output generators for code publishing.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23086
diff
changeset
|
735 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
|
736 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
737 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
738 ## 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
|
739 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
|
740 if (isempty (title_str)) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
741 [~, 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
|
742 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
743 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
744 content = formatter ("header", title_str, |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
745 format_output (doc.intro, formatter, options), |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
746 get_toc (doc.body, formatter)); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
747 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
|
748 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
|
749 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
750 ## Write file |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
751 [~, 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
|
752 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
|
753 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
|
754 fid = fopen (ofile, "w"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
755 fputs (fid, content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
756 fclose (fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
757 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
758 ## 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
|
759 if (strcmp (options.format, "pdf")) |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
760 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
|
761 if (status == 0) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
762 for i = 1:2 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
763 ## 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
|
764 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
|
765 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
766 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
767 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
768 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
769 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
770 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
771 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
|
772 ## 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
|
773 ## 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
|
774 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
775 toc_cstr = cell (); |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
776 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
|
777 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
|
778 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
|
779 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
780 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
781 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
782 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
783 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
784 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
|
785 ## 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
|
786 ## 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
|
787 ## format. |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
788 ## |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
789 ## 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
|
790 ## 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
|
791 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
792 str = ""; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
793 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
|
794 switch (cstr{i}.type) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
795 case "code" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
796 if (options.showCode) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
797 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
|
798 endif |
23191
5f79bb3fdd28
* scripts/general/publish.m: Avoid creation of empty ouput blocks.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23188
diff
changeset
|
799 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
|
800 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
|
801 endif |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
802 case {"text", "section"} |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 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
|
809 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
810 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
|
811 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
812 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
813 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
814 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
815 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
816 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
817 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
|
818 ## FORMAT_TEXT formats inline formats in strings. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
819 ## These are: links, bold, italic, monospaced, (TM), (R) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
820 |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
821 ## Regular expressions for the formats: |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
822 ## |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
823 ## * Links "<http://www.someurl.com>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
824 ## * Links "<octave:Function TEXT>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
825 ## * Links "<http://www.someurl.com TEXT>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
826 ## * inline "$" and block "$$" LaTeX math |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
827 regexes = {'<\S{3,}[^\s<>]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
828 '<octave:[^\s<>]* *[^<>$]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
829 '<\S{3,}[^\s<>]* *[^<>$]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
830 '\${1,2}.*?\${1,2}', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
831 '\*[^*]*\*', ... # Bold |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
832 '_[^_]*_', ... # Italic |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
833 '\|[^|]*\|'}; # Monospaced |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
834 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
835 ## 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
|
836 ## 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
|
837 texinfo_esc = @(str) strrep (strrep (str, "-", "_002d"), "_", "_005f"); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
838 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
839 ## Substitute all occurrences with placeholders |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
840 placeholder_cstr = {}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
841 plh = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
842 for i = 1:numel (regexes) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
843 cstr = regexp (str, regexes{i}, "match"); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
844 for j = 1:numel (cstr) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
845 plh += 1; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
846 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
|
847 "once"); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
848 switch (i) |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
849 case 1 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
850 ## Links "<http://www.someurl.com>" |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
851 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
852 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
|
853 case 2 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
854 ## Links "<octave:Function TEXT>" |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
855 idx = strfind (cstr{j}, " "); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
856 url = cstr{j}; |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
857 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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 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
|
863 "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
|
864 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
865 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
|
866 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
867 case 3 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
868 ## Links "<http://www.someurl.com TEXT>" |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
869 idx = strfind (cstr{j}, " "); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
870 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
871 url = url(2:idx-1); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
872 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
873 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
|
874 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
875 case 4 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
876 ## inline "$" and block "$$" LaTeX math --> do nothing |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
877 case 5 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
878 ## Bold |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
879 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
880 cstr{j} = formatter ("bold", format_text (txt(2:end-1), formatter)); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
881 case 6 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
882 ## Italic |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
883 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
884 cstr{j} = formatter ("italic", format_text (txt(2:end-1), formatter)); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
885 case 7 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
886 ## Monospaced |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
887 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
888 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
|
889 formatter)); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
890 endswitch |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
891 endfor |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
892 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
|
893 endfor |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
894 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
895 ## Replace special symbols |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
896 str = strrep (str, "(TM)", formatter ("TM")); |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
897 str = strrep (str, "(R)", formatter ("R")); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
898 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
899 ## Restore placeholders |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
900 for i = plh:-1:1 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
901 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
|
902 placeholder_cstr{i}); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
903 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
904 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
905 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
906 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
907 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
908 function doc = eval_code (doc, options) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
909 ## 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
|
910 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
911 ## 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
|
912 ## figures. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
913 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
914 ## 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
|
915 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
|
916 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
917 ## Remember previously opened figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
918 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
|
919 [~, 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
|
920 fig_num = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
921 fig_list = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
922 |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
923 ## File used as temporary context |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
924 tmp_context = [tempname() ".var"]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
925 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
926 ## Evaluate code, that does not appear in the output. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
927 eval_code_helper (tmp_context, options.codeToEvaluate); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
928 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
929 ## 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
|
930 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
|
931 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
932 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
933 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
934 for i = 1:numel (doc.body) |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
935 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
|
936 r = doc.body{i}.lines; |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
937 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
|
938 if (options.catchError) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
939 try |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
940 doc.body{i}.output = eval_code_helper (tmp_context, code_str); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
941 catch err |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
942 doc.body{i}.output = cellstr (["error: ", err.message, ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
943 "\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
|
944 end_try_catch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
945 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
946 doc.body{i}.output = eval_code_helper (tmp_context, code_str); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
947 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
948 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
949 ## 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
|
950 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
|
951 ## ... and save them |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
952 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
|
953 drawnow (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
954 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
|
955 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
956 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
957 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
|
958 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
|
959 fname = [fname ".eps"]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
960 else |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
961 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
|
962 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
963 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
|
964 fullfile(options.outputDir, fname), ... |
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
965 ["-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
|
966 if (! isempty (options.maxWidth) && ! isempty (options.maxHeight)) |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
967 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
|
968 options.maxHeight); |
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
969 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
|
970 warning (["publish: specify both options.maxWidth ", ... |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
971 "and options.maxHeight"]); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
972 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
973 print (print_opts{:}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
974 fig_num++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
975 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
|
976 fig_elem = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
977 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
|
978 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
|
979 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
|
980 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
981 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
|
982 ## 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
|
983 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
|
984 && ! 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
|
985 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
986 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
987 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
988 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
989 ## Truncate output to desired length |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
990 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
|
991 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
|
992 endif |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
993 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
|
994 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
995 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
996 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
997 ## 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
|
998 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
|
999 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1000 ## Remove temporary context |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1001 unlink (tmp_context); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1002 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1003 ## Insert figures to document |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1004 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
|
1005 body_offset = 0; |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1006 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
|
1007 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
|
1008 ## 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
|
1009 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
|
1010 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
|
1011 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
|
1012 endfor |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1013 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1014 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1015 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1016 |
22767
212333a97d8d
maint: Remove dangling ';' from m-file function declarations.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1017 function ___cstr___ = eval_code_helper (___context___, ___code___) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1018 ## 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
|
1019 ## 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
|
1020 |
23547
8133a5041662
publish.m: Fix corruption of results for some code inputs (bug #51178).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1021 ## FIXME: code may contain potential conflicting variables named ___code___, |
8133a5041662
publish.m: Fix corruption of results for some code inputs (bug #51178).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1022 ## ___context___, or ___cstr___. Is there a better solution? |
23549
c8daadf7543b
publish.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents:
23548
diff
changeset
|
1023 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1024 if (isempty (___code___)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1025 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1026 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1027 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1028 if (exist (___context___, "file") == 2) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1029 load (___context___); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1030 endif |
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 ___cstr___ = strsplit (evalc (___code___), "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1033 |
23547
8133a5041662
publish.m: Fix corruption of results for some code inputs (bug #51178).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1034 clear ___code___; |
8133a5041662
publish.m: Fix corruption of results for some code inputs (bug #51178).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
1035 save ("-binary", ___context___); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1036 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1037 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1038 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1039 ## FIXME: Missing any functional BIST tests |
23548 | 1040 ## FIXME: Need to create a temporary file for use with error testing |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1041 |
22705
e9a0aa0a49ed
Overhaul publish function and it's private helper functions.
Rik <rik@octave.org>
parents:
22674
diff
changeset
|
1042 ## Test input validation |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1043 %!error publish () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1044 %!error publish (1) |
22706 | 1045 %!error <FILE does not exist> publish ("%%_non_existent_file_%%.m") |
1046 %!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
|
1047 %!error publish ("test_script.m", "format", "html", "showCode") |