build_DEMOS
pkg-octave-doc: html = build_DEMOS (fcnname)
pkg-octave-doc: html = build_DEMOS (fcnname, collapsed)
pkg-octave-doc: html = build_DEMOS (…, Name, Value)
Build notebook-style HTML for the DEMO blocks of a function or class member.
build_DEMOS collects every %!demo block of fcnname and
returns html, a char string with the generated HTML for all of them.
fcnname is a char string with the name of a function or, for a class
member, a "class/method" path. Each demo is wrapped in the
demos_template.html card, titled Example: N and given the HTML
anchor fcnname-exampleN (with every non-alphanumeric character of
fcnname, such as the . of a "Class.method" name, mapped
to _ so the id is safe in a CSS selector). A docstring can therefore
link to one of its own demos with the
short form @url{#exampleN}: the HTML converter expands the bare
#exampleN fragment to this fully-qualified anchor, which keeps the
reference readable in the command-line help while staying unique on a
page that carries several members’ demos.
The optional collapsed is a logical scalar. When true, each
example card renders collapsed by default (used for lumped classdef members to
keep the page short); a viewer expands it with the card header, and a
#exampleN link opens it automatically. When omitted or false,
the card renders expanded. When fcnname has no demos, html is
returned empty.
Optional Name/Value pairs
| Name | Value |
|---|---|
'figformat' | The file format the demo figures are printed
in, either 'png' (default) or 'svg'. 'png' is
printed at twice the nominal size so it stays sharp on a high-density
display. 'svg' keeps the figures resolution independent, at the cost
of very large files for figures rich in filled areas. |
Source Code: build_DEMOS
Notebook layout
Each demo is rendered as an interleaved notebook instead of a single code block trailed by its aggregated output. The demo is split into cells and laid out as a vertical stack of boxes:
disp,
printf, and the like.
assets/ folder of the
working directory, shown right after the code that drew them. They are named
after their owner as its HTML page is, so the figures of
prob.NormalDistribution.pdf are prob.NormalDistribution.pdf-N
beside prob.NormalDistribution.pdf.html. The figure number is
separated with a -, since _ already stands for the file
separator of an old-style "@class/method" name and a function name
may itself contain one.
Markdown in comments
Comment text uses a small subset of Markdown, not texinfo, so
that the same demo stays readable in the terminal when it is run with the
demo command. The supported constructs are:
`code` rendered as <code>;
**text** and italic *text* emphasis;
[text](url);
- or *
marker, and ordered lists, whose items start with a 1. marker.
All comment text is HTML-escaped before the markup is applied. The following
are deliberately not supported: any texinfo markup; underscore
emphasis _text_, which would mangle identifier names such as
a_b_c; and # headings, which would clash with the Octave
comment marker.
See also: find_DEMOS, function_texi2html, classdef_texi2html
Source Code: build_DEMOS