Mercurial > octave
annotate scripts/general/publish.m @ 22674:c024fb103114 stable
minor improvements for publish.
* scripts/general/publish.m:
- Add support of GNU Octave HTML manual URLs like <octave:plot TEXT>.
- Avoid bad interleaved formatting with placeholders.
- No formatting of the document title.
* scripts/general/__publish_html_output__.m: Improve the simple syntax
highlighter.
* test/publish/test_script.m: Test the GNU Octave HTML manual URLs.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Thu, 27 Oct 2016 13:35:16 +0200 |
parents | ac45255ccd2c |
children | e9a0aa0a49ed 413a19bca7f3 |
rev | line source |
---|---|
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1 ## Copyright (C) 2016 Kai T. Ohlhus <k.ohlhus@gmail.com> |
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 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
9 ## your option) any later version. |
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 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
14 ## General Public License for more details. |
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 -*- |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
21 ## @deftypefn {} {} publish (@var{filename}) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
22 ## @deftypefnx {} {} publish (@var{filename}, @var{output_format}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
23 ## @deftypefnx {} {} publish (@var{filename}, @var{option1}, @var{value1}, @dots{}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
24 ## @deftypefnx {} {} publish (@var{filename}, @var{options}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
25 ## @deftypefnx {} {@var{output_file} =} publish (@var{filename}, @dots{}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
26 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
27 ## Generate reports from Octave script files in several output formats. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
28 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
29 ## The generated reports consider Publishing Markup in comments, |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
30 ## which is explained in detail in the GNU Octave manual. Assume the |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
31 ## following example, using some Publishing Markup, to be the content |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
32 ## of a script file named @samp{example.m}: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
33 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
34 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
35 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
36 ## %% Headline title |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
37 ## % |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
38 ## % Some *bold*, _italic_, or |monospaced| Text with |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
39 ## % a <http://www.octave.org link to *GNU Octave*>. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
40 ## %% |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
41 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
42 ## # "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
|
43 ## sombrero () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
44 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
45 ## ## Octave comment style supported as well |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
46 ## # |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
47 ## # * Bulleted list item 1 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
48 ## # * Bulleted list item 2 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
49 ## # |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
50 ## # # Numbered list item 1 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
51 ## # # Numbered list item 2 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
52 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
53 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
54 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
55 ## To publish this script file, type @code{publish ("example.m")}. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
56 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
57 ## With only @var{filename} given, a HTML report is generated in a |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
58 ## subdirectory @samp{html} relative to the current working directory. |
22330
53e246fd8124
doc: Spellcheck documentation ahead of 4.2 release.
Rik <rik@octave.org>
parents:
22307
diff
changeset
|
59 ## The Octave commands are evaluated in a separate context and any |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
60 ## figures created while executing the script file are included in the |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
61 ## report. All formatting syntax of @var{filename} is treated according |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
62 ## to the specified output format and included in the report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
63 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
64 ## Using @code{publish (@var{filename}, @var{output_format})} is |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
65 ## equivalent to the function call using a structure |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
66 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
67 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
68 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
69 ## @var{options}.format = @var{output_format}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
70 ## publish (@var{filename}, @var{options}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
71 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
72 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
73 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
74 ## @noindent |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
75 ## which is described below. The same holds for using option-value-pairs |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
76 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
77 ## @example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
78 ## @group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
79 ## @var{options}.@var{option1} = @var{value1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
80 ## publish (@var{filename}, @var{options}) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
81 ## @end group |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
82 ## @end example |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
83 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
84 ## The structure @var{options} can have the following field names. If a |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
85 ## field name is not specified, the default value is considered: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
86 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
87 ## @itemize @bullet |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
88 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
89 ## @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
|
90 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
91 ## @samp{html} (default), @samp{doc}, @samp{latex}, @samp{ppt}, |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
92 ## @samp{xml}, or @samp{pdf}. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
93 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
94 ## The output formats @samp{doc}, @samp{ppt}, and @samp{xml} are currently |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
95 ## not supported. To generate a @samp{doc} report, open a generated |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
96 ## @samp{html} report with your office suite. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
97 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
98 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
99 ## @samp{outputDir} --- Full path string of a directory, where the generated |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
100 ## report will be located. If no directory is given, the report is generated |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
101 ## in a subdirectory @samp{html} relative to the current working directory. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
102 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
103 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
104 ## @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
|
105 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
106 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
107 ## @samp{createThumbnail} --- 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
|
108 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
109 ## @item |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
110 ## @samp{figureSnapMethod} --- 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
|
111 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
112 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
113 ## @samp{imageFormat} --- Desired format for images produced, while |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
114 ## evaluating the code. The allowed image formats depend on the output |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
115 ## format: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
116 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
117 ## @itemize @bullet |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
118 ## @item @samp{html} and @samp{xml} --- @samp{png} (default), any other |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
119 ## image format supported by Octave |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
120 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
121 ## @item @samp{latex} --- @samp{epsc2} (default), any other image format |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
122 ## supported by Octave |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
123 ## |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22157
diff
changeset
|
124 ## @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
|
125 ## 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
|
126 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
127 ## @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
|
128 ## @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
|
129 ## @end itemize |
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 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
132 ## @samp{maxHeight} and @samp{maxWidth} --- Maximum height (width) of the |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
133 ## produced images in pixels. An empty value means no restriction. Both |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
134 ## values have to be set, to work properly. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
135 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
136 ## @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
|
137 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
138 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
139 ## @samp{useNewFigure} --- Use a new figure window for figures created by |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
140 ## the evaluated code. This avoids side effects with already opened figure |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
141 ## windows. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
142 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
143 ## @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
|
144 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
145 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
146 ## @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
|
147 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
148 ## @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
|
149 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
150 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
151 ## @samp{catchError} --- Catch errors while code evaluation and continue |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
152 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
153 ## @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
|
154 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
155 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
156 ## @samp{codeToEvaluate} --- Octave commands that should be evaluated prior |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
157 ## to publishing the script file. These Octave commands do not appear in the |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
158 ## generated report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
159 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
160 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
161 ## @samp{maxOutputLines} --- Maximum number of shown output lines of the |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
162 ## code evaluation |
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 ## @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
|
165 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
166 ## @item |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
167 ## @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
|
168 ## report |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
169 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
170 ## @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
|
171 ## @end itemize |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
172 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
173 ## The returned @var{output_file} is a string with the path and file name |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
174 ## of the generated report. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
175 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
176 ## @seealso{grabcode} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
177 ## @end deftypefn |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
178 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
179 function output_file = publish (file, varargin) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
180 narginchk (1, Inf); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
181 nargoutchk (0, 1); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
182 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
183 if (exist (file, "file") != 2) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
184 error ("publish: FILE does not exist."); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
185 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
186 |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
187 ## 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
|
188 [file_path, file_name, file_ext] = fileparts (file); |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
189 if (isempty (file_path)) |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
190 file_path = pwd; |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
191 endif |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
192 if (isempty (which ([file_name, file_ext]))) |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
193 error (["publish: ", file, " is not in the load path."]); |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
194 endif |
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
195 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
196 ## Check file extension and for an Octave script |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
197 file_info = __which__ (file_name); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
198 if ((! strcmp (file_ext, ".m")) || (! strcmp (file_info.type, "script"))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
199 error ("publish: Only Octave script files can be published."); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
200 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
201 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
202 ## 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
|
203 __parse_file__ (file); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
204 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
205 ## 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
|
206 options = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
207 if (numel (varargin) == 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
208 ## Call: publish (file, format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
209 if (ischar (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
210 options.format = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
211 ## Call: publish (file, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
212 elseif (isstruct (varargin{1})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
213 options = varargin{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
214 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
215 error ("publish: Invalid second argument."); |
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 ## Call: publish (file, Name1, Value1, Name2, Value2, ...) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
218 elseif ((rem (numel (varargin), 2) == 0) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
219 && (all (cellfun (@ischar, varargin)))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
220 for i = 1:2:numel(varargin) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
221 options = setfield (options, varargin{i}, varargin{i + 1}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
222 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
223 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
224 error ("publish: Invalid or inappropriate arguments."); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
225 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
226 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
227 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
228 ## Validate options struct |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
229 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
230 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
231 ## Options for the output |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
232 if (! isfield (options, "format")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
233 options.format = "html"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
234 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
235 options.format = validatestring (options.format, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
236 {"html", "doc", "latex", "ppt", "xml", "pdf"}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
237 ## TODO: implement remaining formats |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
238 if (any (strcmp (options.format, {"doc", "ppt", "xml"}))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
239 error ("publish: Output format currently not supported"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
240 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
241 endif |
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 if (! isfield (options, "outputDir")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
244 ## Matlab R2016a doc says default is "", but specifies to create a sub |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
245 ## directory named "html" in the current working directory. |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
246 options.outputDir = [file_path, filesep(), "html"]; |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
247 elseif (! ischar (options.outputDir)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
248 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
|
249 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
250 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
251 if (! isfield (options, "stylesheet")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
252 options.stylesheet = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
253 elseif (! ischar (options.stylesheet)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
254 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
|
255 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
256 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
257 ## Options for the figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
258 if (! isfield (options, "createThumbnail")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
259 options.createThumbnail = true; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
260 elseif ((! isscalar (options.createThumbnail)) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
261 || (! isbool (options.createThumbnail))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
262 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
|
263 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
264 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
265 if (! isfield (options, "figureSnapMethod")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
266 options.figureSnapMethod = "entireGUIWindow"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
267 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
268 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
|
269 {"entireGUIWindow", "print", "getframe", "entireFigureWindow"}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
270 ## TODO: implement |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
271 warning ("publish: option FIGURESNAPMETHOD currently not supported") |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
272 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
273 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
274 if (! isfield (options, "imageFormat")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
275 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
276 case "latex" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
277 options.imageFormat = "epsc2"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
278 case "pdf" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
279 ## 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
|
280 options.imageFormat = "jpg"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
281 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
282 options.imageFormat = "png"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
283 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
284 elseif (! ischar (options.imageFormat)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
285 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
|
286 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
287 ## check valid imageFormat for chosen format |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
288 ## 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
|
289 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
290 case {"doc", "ppt"} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
291 options.imageFormat = validatestring (options.imageFormat, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
292 {"png", "jpg", "bmp", "tiff"}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
293 case "pdf" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
294 options.imageFormat = validatestring (options.imageFormat, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
295 {"bmp", "jpg"}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
296 endswitch |
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, "maxHeight")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
300 options.maxHeight = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
301 elseif ((! isscalar (options.maxHeight)) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
302 || (uint64 (options.maxHeight) == 0)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
303 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
|
304 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
305 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
|
306 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
307 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
308 if (! isfield (options, "maxWidth")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
309 options.maxWidth = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
310 elseif ((! isscalar (options.maxWidth)) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
311 || (uint64 (options.maxWidth) == 0)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
312 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
|
313 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
314 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
|
315 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
316 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
317 if (! isfield (options, "useNewFigure")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
318 options.useNewFigure = true; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
319 elseif (! isbool (options.useNewFigure)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
320 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
|
321 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
322 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
323 ## Options for the code |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
324 if (!isfield (options, "evalCode")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
325 options.evalCode = true; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
326 elseif ((! isscalar (options.evalCode)) || (! isbool (options.evalCode))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
327 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
|
328 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
329 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
330 if (!isfield (options, "catchError")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
331 options.catchError = true; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
332 elseif ((! isscalar (options.catchError)) || (! isbool (options.catchError))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
333 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
|
334 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
335 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
336 if (!isfield (options, "codeToEvaluate")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
337 options.codeToEvaluate = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
338 elseif (! ischar (options.codeToEvaluate)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
339 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
|
340 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
341 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
342 if (! isfield (options, "maxOutputLines")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
343 options.maxOutputLines = Inf; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
344 elseif (! isscalar (options.maxOutputLines)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
345 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
|
346 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
347 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
|
348 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
349 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
350 if (!isfield (options, "showCode")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
351 options.showCode = true; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
352 elseif ((! isscalar (options.showCode)) || (! isbool (options.showCode))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
353 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
|
354 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
355 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
356 doc_struct.title = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
357 doc_struct.intro = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
358 doc_struct.body = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
359 doc_struct.m_source = deblank (read_file_to_cellstr (file)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
360 doc_struct.m_source_file_name = file; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
361 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
362 ## Split code and paragraphs, find formatting |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
363 doc_struct = parse_m_source (doc_struct); |
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 ## Create output directory |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
366 [mkdir_stat, mkdir_msg] = mkdir (options.outputDir); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
367 if (mkdir_stat != 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
368 error ("publish: cannot create output directory. %s", mkdir_msg); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
369 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
370 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
371 if (options.evalCode) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
372 doc_struct = eval_code (doc_struct, options); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
373 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
374 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
375 output_file = create_output (doc_struct, options); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
376 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
377 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
378 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
379 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
380 function doc_struct = parse_m_source (doc_struct) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
381 ## 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
|
382 ## This function extracts the overall structure (paragraphs and code |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
383 ## sections) given in doc_struct.m_source. |
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 ## The result is written to doc_struct.body, which then contains a cell |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
386 ## 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
|
387 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
388 ## a) {struct ("type", "code", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
389 ## "lines", [a, b], ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
390 ## "output", [])} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
391 ## b) {struct ("type", "section", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
392 ## "content", title_str)} |
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 ## Second parsing level is invoked for the paragraph contents, resulting |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
395 ## in more elements for doc_struct.body. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
396 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
397 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
398 ## If there is nothing to parse |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
399 if (isempty (doc_struct.m_source)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
400 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
401 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
402 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
403 ## Parsing helper functions |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
404 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
405 ## Checks line to have N "%" or "#" lines |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
406 ## followed either by a space or is end of string |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
407 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
|
408 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
|
409 && ((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
|
410 ## 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
|
411 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
|
412 ## 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
|
413 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
|
414 ## 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
|
415 ## 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
|
416 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
|
417 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
418 ## Find the indices of paragraphs starting with "%%", "##", or "%%%" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
419 par_start_idx = find ( ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
420 cellfun (is_head, doc_struct.m_source) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
421 | cellfun (is_no_break_head, doc_struct.m_source)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
422 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
423 ## 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
|
424 if (isempty (par_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
425 doc_struct.body{end + 1}.type = "code"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
426 doc_struct.body{end}.content = strtrim (strjoin (... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
427 doc_struct.m_source(1:length(doc_struct.m_source)), "\n")); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
428 doc_struct.body{end}.lines = [1, length(doc_struct.m_source)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
429 doc_struct.body{end}.output = {}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
430 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
431 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
432 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
433 ## Determine continuous range of paragraphs |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
434 par_end_idx = [par_start_idx(2:end) - 1, length(doc_struct.m_source)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
435 for i = 1:length(par_end_idx) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
436 idx = find (! cellfun (is_paragraph, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
437 doc_struct.m_source(par_start_idx(i) + 1:par_end_idx(i)))); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
438 if (! isempty (idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
439 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
|
440 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
441 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
442 ## Code sections between paragraphs |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
443 code_start_idx = par_end_idx(1:end - 1) + 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
444 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
|
445 ## Code at the beginning? |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
450 ## Code at the end? |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
451 if (par_end_idx(end) < length (doc_struct.m_source)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
452 code_start_idx = [code_start_idx, par_end_idx(end) + 1]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
453 code_end_idx = [code_end_idx, length(doc_struct.m_source)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
454 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
455 ## Remove overlaps |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
456 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
|
457 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
458 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
459 ## Remove empty code blocks |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
460 idx = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
461 for i = 1:length(code_start_idx) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
462 if (all (cellfun (@(cstr) isempty (char (cstr)), ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
463 doc_struct.m_source(code_start_idx(i):code_end_idx(i))))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
464 idx = [idx, i]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
465 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
466 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
467 code_start_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
468 code_end_idx(idx) = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
469 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
470 ## 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
|
471 ## 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
|
472 ## 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
|
473 title_offset = 0; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
474 if ((is_head (doc_struct.m_source{1})) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
475 && (! isempty (par_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
476 && (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
|
477 && ((isempty (code_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
478 || ((length (par_start_idx) > 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
479 && (par_start_idx(2) < code_start_idx(1))))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
480 doc_struct.title = doc_struct.m_source{1}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
481 doc_struct.title = doc_struct.title(4:end); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
482 content = doc_struct.m_source(2:par_end_idx(1)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
483 ## Strip leading "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
484 content = cellfun(@(c) cellstr (c(3:end)), content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
485 doc_struct.intro = parse_paragraph_content (content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
486 title_offset = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
487 endif |
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 ## Add non-empty paragraphs and code to doc_struct |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
490 j = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
491 i = (1 + title_offset); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
492 while ((i <= length(par_start_idx)) || (j <= length(code_start_idx))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
493 ## 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
|
494 ## and code is before the next paragraph or there are no more paragraphs |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
495 while ((j <= length(code_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
496 && ((i > length(par_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
497 || (par_start_idx(i) > code_start_idx(j)))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
498 doc_struct.body{end + 1}.type = "code"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
499 lines = [code_start_idx(j), code_end_idx(j)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
500 doc_struct.body{end}.content = strtrim (strjoin (... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
501 doc_struct.m_source(lines(1):lines(2)), "\n")); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
502 doc_struct.body{end}.lines = lines; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
503 doc_struct.body{end}.output = {}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
504 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
505 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
506 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
507 if (i <= length(par_start_idx)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
508 type_str = "section"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
509 title_str = doc_struct.m_source{par_start_idx(i)}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
510 if (is_head (doc_struct.m_source(par_start_idx(i)))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
511 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
|
512 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
513 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
|
514 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
515 ## 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
|
516 if (! isempty (title_str)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
517 doc_struct.body{end + 1}.type = type_str; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
518 doc_struct.body{end}.content = title_str; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
519 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
520 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
521 content = doc_struct.m_source(par_start_idx(i) + 1:par_end_idx(i)); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
522 ## Strip leading "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
523 content = cellfun(@(c) cellstr (c(3:end)), content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
524 doc_struct.body = [doc_struct.body, parse_paragraph_content(content)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
525 i++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
526 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
527 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
528 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
529 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
530 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
531 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
532 function [p_content] = parse_paragraph_content (content) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
533 ## 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
|
534 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
535 ## Parses the content of a paragraph (without potential title) and |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
536 ## returns a cell vector of structs, that can be appended to |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
537 ## doc_struct.body, either of |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
538 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
539 ## 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
|
540 ## "content", code_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
541 ## 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
|
542 ## "content", text_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
543 ## 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
|
544 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
545 ## 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
|
546 ## "content", {"item1", "item2", ..})} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
547 ## e) {struct ("type", "include", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
548 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
549 ## f) {struct ("type", "graphic", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
550 ## "content", file_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
551 ## g) {struct ("type", "html", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
552 ## "content", html_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
553 ## h) {struct ("type", "latex", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
554 ## "content", latex_str)} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
555 ## i) {struct ("type", "text", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
556 ## "content", text_str)} |
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 ## Option i) might contain: |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
559 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
560 ## * 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
|
561 ## * 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
|
562 ## * Links |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
563 ## * Trademark symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
564 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
565 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
566 p_content = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
567 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
568 if (isempty (content)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
569 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
570 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
571 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
572 ## Split into blocks seperated by empty lines |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
573 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
|
574 ## For each block |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
575 for i = find (diff(idx) > 1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
576 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
|
577 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
578 ## 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
|
579 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
|
580 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
|
581 block = cellfun(@(c) cellstr (c(3:end)), block); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
582 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
|
583 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
584 endif |
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 ## 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
|
587 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
|
588 p_content{end+1}.type = "preformatted_text"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
589 block = cellfun(@(c) cellstr (c(2:end)), block); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
590 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
|
591 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
592 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
593 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
594 ## Bulleted list starts with "* " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
595 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
|
596 p_content{end+1}.type = "bulleted_list"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
597 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
|
598 ## Revove first "* " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
599 p_content{end}.content = p_content{end}.content(3:end); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
600 ## Split items |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
601 p_content{end}.content = strsplit (p_content{end}.content, "\n* "); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
602 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
603 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
604 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
605 ## Numbered list starts with "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
606 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
|
607 p_content{end+1}.type = "numbered_list"; |
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 ## Revove first "# " |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
610 p_content{end}.content = p_content{end}.content(3:end); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
611 ## Split items |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
612 p_content{end}.content = strsplit (p_content{end}.content, "\n# "); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
613 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
614 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
615 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
616 ## Include <include>fname.m</include> |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
617 if (! isempty ([~,~,~,~,fname] = regexpi (strjoin (block, ""), ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
618 '^<include>(.*)<\/include>$'))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
619 ## 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
|
620 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
|
621 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
|
622 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
|
623 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
624 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
625 endif |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22113
diff
changeset
|
626 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
627 ## Graphic <<myGraphic.png>> |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
628 if (! isempty ([~,~,~,~,fname] = regexpi (strjoin (block, ""), ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
629 '^<<(.*)>>$'))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
630 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
|
631 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
|
632 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
633 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
634 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
635 ## 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
|
636 j = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
637 while (j <= length(block)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
638 ## HTML markup |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
639 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
|
640 start_html = j + 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
641 while ((j < length(block)) && ! strcmpi (block{j}, "</html>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
642 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
643 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
644 if ((j == length(block)) && ! strcmpi (block{j}, "</html>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
645 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
|
646 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
647 j++; ## Skip closing tag |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
648 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
649 if (j > start_html) |
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 = "html"; |
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 = 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
|
652 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
653 ## LaTeX markup |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
654 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
|
655 start_latex = j + 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
656 while ((j < length(block)) && ! strcmpi (block{j}, "</latex>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
657 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
658 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
659 if ((j == length(block)) && ! strcmpi (block{j}, "</latex>")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
660 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
|
661 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
662 j++; ## Skrip closing tag |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
663 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
664 if (j > start_latex) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
665 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
|
666 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
|
667 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
668 ## 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
|
669 ## 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
|
670 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
671 ## * 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
|
672 ## * 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
|
673 ## * Links |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
674 ## * Trademark symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
675 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
676 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
677 if ((j == 1) || isempty (p_content) ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
678 || ! 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
|
679 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
|
680 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
|
681 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
682 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
|
683 block{j}}, "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
684 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
685 j++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
686 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
687 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
688 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
689 endfunction |
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 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
692 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
693 function m_source = read_file_to_cellstr (file) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
694 ## READ_FILE_TO_CELLSTR reads a given file line by line to a cellstring |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
695 fid = fopen (file, "r"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
696 i = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
697 m_source{i} = fgetl (fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
698 while (ischar (m_source{i})) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
699 i++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
700 m_source{i} = fgetl (fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
701 endwhile |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
702 fclose(fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
703 m_source = cellstr (m_source(1:end-1)); ## No EOL |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
704 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
705 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
706 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
707 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
708 function ofile = create_output (doc_struct, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
709 ## 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
|
710 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
711 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
712 formatter = []; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
713 ofile_ext = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
714 switch (options.format) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
715 case "html" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
716 formatter = @__publish_html_output__; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
717 ofile_ext = ".html"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
718 case {"latex", "pdf"} |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
719 formatter = @__publish_latex_output__; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
720 ofile_ext = ".tex"; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
721 endswitch |
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 ## Use title, or if not given the m-file name |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
724 title_str = doc_struct.title; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
725 if (isempty (title_str)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
726 [~,title_str] = fileparts (doc_struct.m_source_file_name); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
727 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
728 |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
729 content = formatter ("header", title_str, ... |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
730 format_output (doc_struct.intro, formatter, options), ... |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
731 get_toc (doc_struct.body, formatter)); |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
732 content = [content, format_output(doc_struct.body, formatter, options)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
733 content = [content, formatter("footer", strjoin (doc_struct.m_source, "\n"))]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
734 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
735 ## Write file |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
736 [~,ofile] = fileparts (doc_struct.m_source_file_name); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
737 ofile_name = [ofile, ofile_ext]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
738 ofile = [options.outputDir, filesep(), ofile_name]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
739 fid = fopen (ofile, "w"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
740 fputs (fid, content); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
741 fclose (fid); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
742 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
743 ## 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
|
744 if (strcmp (options.format, "pdf")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
745 [status, ~] = system ("pdflatex --version"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
746 if (status == 0) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
747 for i = 1:2 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
748 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
|
749 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
750 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
751 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
752 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
753 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
754 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
755 |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
756 function toc_cstr = get_toc (cstr, formatter) |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
757 ## GET_TOC extracts the table of contents from a cellstring (e.g. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
758 ## doc_struct.body) with each section headline as a cell in a returned |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
759 ## cellstring. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
760 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
761 toc_cstr = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
762 for i = 1:length(cstr) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
763 if (strcmp (cstr{i}.type, "section")) |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
764 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
|
765 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
766 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
767 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
768 |
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 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
771 function str = format_output (cstr, formatter, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
772 ## FORMAT_OUTPUT steps through all blocks (doc_struct.intro or |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
773 ## doc_struct.body) in cstr and produces a single result string |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
774 ## with the source code in the desired output format. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
775 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
776 ## formatter has the only knowlegde how to enforce the target format |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
777 ## 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
|
778 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
779 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
780 str = ""; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
781 for i = 1:length(cstr) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
782 switch (cstr{i}.type) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
783 case "code" |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
784 if (options.showCode) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
785 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
|
786 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
787 if (options.evalCode) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
788 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
|
789 endif |
22384
ac45255ccd2c
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22330
diff
changeset
|
790 case {"text", "section"} |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
791 str = [str, formatter(cstr{i}.type, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
792 format_text (cstr{i}.content, formatter))]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
793 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
|
794 items = cellfun (@(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
|
795 cstr{i}.content, "UniformOutput", false); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
796 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
|
797 otherwise |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
798 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
|
799 endswitch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
800 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
801 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
802 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
803 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
804 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
805 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
|
806 ## 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
|
807 ## 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
|
808 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
809 |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
810 ## Regular expressions for the formats: |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
811 ## |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
812 ## * Links "<http://www.someurl.com>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
813 ## * Links "<octave:Function TEXT>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
814 ## * Links "<http://www.someurl.com TEXT>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
815 ## * inline "$" and block "$$" LaTeX math |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
816 ## |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
817 regexes = {'<\S{3,}[^\s<>]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
818 '<octave:[^\s<>]* *[^<>$]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
819 '<\S{3,}[^\s<>]* *[^<>$]*>', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
820 '\${1,2}.*?\${1,2}', ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
821 '\*[^*]*\*', ... # Bold |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
822 '_[^_]*_', ... # Italic |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
823 '\|[^|]*\|'}; # Monospaced |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
824 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
825 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
826 ## Helper function to escape some special characters for the GNU Octave |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
827 ## manual, see https://www.gnu.org/software/texinfo/manual/texinfo/html_node/HTML-Xref-Node-Name-Expansion.html |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
828 texinfo_esc = @(str) strrep (strrep (str, "-", "_002d"), "_", "_005f"); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
829 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
830 ## Substitute all occurances with placeholders |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
831 placeholder_cstr = {}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
832 plh = 0; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
833 for i = 1:length(regexes) |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
834 [~,~,~,cstr] = regexp (str, regexes{i}); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
835 for j = 1:length(cstr) |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
836 plh = plh + 1; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
837 str = regexprep (str, regexes{i}, ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
838 ["PUBLISHPLACEHOLDER", num2str(plh)], "once"); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
839 switch (i) |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
840 case 1 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
841 # Links "<http://www.someurl.com>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
842 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
843 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
|
844 case 2 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
845 # Links "<octave:Function TEXT>" |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
846 idx = strfind (cstr{j}, " "); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
847 url = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
848 url = ["https://www.gnu.org/software/octave/doc/interpreter/", ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
849 "XREF", texinfo_esc(url(9:idx-1)), ".html"]; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
850 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
851 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
|
852 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
853 case 3 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
854 # Links "<http://www.someurl.com TEXT>" |
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}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
857 url = url(2:idx-1); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
858 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
859 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
|
860 cstr{j} = formatter ("link", url, txt); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
861 case 4 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
862 # inline "$" and block "$$" LaTeX math --> do nothing |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
863 case 5 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
864 # Bold |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
865 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
866 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
|
867 case 6 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
868 # Italic |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
869 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
870 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
|
871 case 7 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
872 # Monospaced |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
873 txt = cstr{j}; |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
874 cstr{j} = formatter ("monospaced", format_text (txt(2:end-1), ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
875 formatter)); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
876 endswitch |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
877 endfor |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
878 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
|
879 endfor |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
880 |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
881 ## Replace special symbols |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
882 str = strrep (str, "(TM)", formatter("TM")); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
883 str = strrep (str, "(R)", formatter("R")); |
22674
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
884 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
885 ## Restore placeholders |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
886 for i = plh:-1:1 |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
887 str = strrep (str, ["PUBLISHPLACEHOLDER", num2str(i)], ... |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
888 placeholder_cstr{i}); |
c024fb103114
minor improvements for publish.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22384
diff
changeset
|
889 endfor |
22113
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
890 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
891 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
892 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
893 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
894 function doc_struct = eval_code (doc_struct, options) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
895 ## EVAL_CODE Thrid level parsing |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
896 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
897 ## 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
|
898 ## figures. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
899 ## |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
900 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
901 ## Neccessary as the code does not run interactively |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
902 page_screen_output (0, "local"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
903 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
904 ## Remember previously opened figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
905 fig_ids = findall (0, "type", "figure"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
906 [~,fig_name] = fileparts (doc_struct.m_source_file_name); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
907 fig_num = 1; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
908 fig_list = struct (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
909 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
910 ## mat-file used as temporary context |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
911 tmp_context = [tempname(), ".mat"]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
912 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
913 ## 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
|
914 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
|
915 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
916 ## 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
|
917 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
|
918 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
919 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
920 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
921 for i = 1:length(doc_struct.body) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
922 if (strcmp (doc_struct.body{i}.type, "code")) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
923 r = doc_struct.body{i}.lines; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
924 code_str = strjoin (doc_struct.m_source(r(1):r(2)), "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
925 if (options.catchError) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
926 try |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
927 doc_struct.body{i}.output = eval_code_helper (tmp_context, code_str); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
928 catch err |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
929 doc_struct.body{i}.output = cellstr (["error: ", err.message, ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
930 "\n\tin:\n\n", code_str]); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
931 end_try_catch |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
932 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
933 doc_struct.body{i}.output = eval_code_helper (tmp_context, code_str); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
934 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
935 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
936 ## 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
|
937 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
|
938 ## ... and save them |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
939 for j = 1:length(fig_ids_new) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
940 drawnow (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
941 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
|
942 continue; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
943 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
944 fname = [fig_name, "-", num2str(fig_num), "."]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
945 if (strncmp (options.imageFormat, "eps", 3)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
946 fname = [fname, "eps"]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
947 else |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
948 fname = [fname, options.imageFormat]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
949 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
950 print_opts = {fig_ids_new(j), ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
951 [options.outputDir, filesep(), fname], ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
952 ["-d", options.imageFormat], "-color"}; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
953 if (! isempty (options.maxWidth) && ! isempty (options.maxHeight)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
954 print_opts{end + 1} = ["-S", num2str(options.maxWidth), ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
955 num2str(options.maxHeight)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
956 elseif (! isempty (options.maxWidth) || ! isempty (options.maxWidth)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
957 warning (["publish: specify both options.maxWidth ", ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
958 "and options.maxWidth"]); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
959 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
960 print (print_opts{:}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
961 fig_num++; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
962 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
|
963 fig_elem = cell (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
964 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
|
965 if (isfield (fig_list, num2str (i))) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
966 fig_elem = [getfield(fig_list, num2str (i)), fig_elem]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
967 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
968 fig_list = setfield (fig_list, num2str (i), fig_elem); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
969 ## 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
|
970 if (isempty (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
|
971 &&! 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
|
972 figure (); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
973 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
974 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
975 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
976 ## Truncate output to desired length |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
977 if (options.maxOutputLines < length (doc_struct.body{i}.output)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
978 doc_struct.body{i}.output = ... |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
979 doc_struct.body{i}.output(1:options.maxOutputLines); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
980 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
981 doc_struct.body{i}.output = strjoin (doc_struct.body{i}.output, "\n"); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
982 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
983 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
984 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
985 ## Close any by publish opened figures |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
986 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
|
987 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
988 ## Remove temporary context |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
989 unlink (tmp_context); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
990 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
991 ## Insert figures to document |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
992 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
|
993 body_offset = 0; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
994 for i = 1:length(fig_code_blocks) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
995 elems = getfield (fig_list, fig_code_blocks{i}); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
996 ## Compute index, where the figure(s) has to be inserterd |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
997 j = str2num (fig_code_blocks{i}) + body_offset; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
998 doc_struct.body = [doc_struct.body(1:j), elems, doc_struct.body(j+1:end)]; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
999 body_offset = body_offset + length (elems); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1000 endfor |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1001 endfunction |
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 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1004 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1005 function ___cstr___ = eval_code_helper (___context___, ___code___); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1006 ## EVAL_CODE_HELPER evaluates a given string with Octave code in an extra |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1007 ## temporary context and returns a cellstring with the eval output |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1008 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1009 ## TODO: potential conflicting variables sourrounded by "___". Maybe there |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1010 ## is a better solution. |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1011 if (isempty (___code___)) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1012 return; |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1013 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1014 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1015 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
|
1016 load (___context___); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1017 endif |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1018 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1019 ___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
|
1020 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1021 clear ___code___ |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1022 save (___context___); |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1023 endfunction |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1024 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1025 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1026 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1027 ## Bad function calls |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1028 |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1029 %!error publish () |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1030 %!error publish (1) |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1031 %!error publish ("non_existing_file.m") |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1032 %!error<Only Octave script files can be published> publish ("publish.m") |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1033 %!error publish ("test_script.m", "format", "html", "showCode") |
b6f482e29afd
New functions publish.m and grabcode.m (patch #9048).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
diff
changeset
|
1034 %!error [str1, str2] = publish ("test_script.m") |