Function Reference: build_DEMOS

pkg-octave-doc: html = build_DEMOS (fcnname)

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 layout and titled Example: N. When fcnname has no demos, html is returned empty.

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:

  • Comment lines become prose (see the Markdown subset below).
  • Code statements become input boxes. Consecutive statements that print nothing are merged into a single box, so muted setup code reads as one block.
  • Output produced by a statement is shown in an output box directly beneath it, rather than at the end of the demo. A statement prints when it is left unterminated by a semicolon or when it calls disp, printf, and the like.
  • Figures are saved as PNG images under the assets/ folder of the working directory, shown right after the code that drew them.

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:

  • inline code `code` rendered as <code>;
  • bold **text** and italic *text* emphasis;
  • links [text](url);
  • paragraphs, separated by a blank comment line;
  • unordered lists, whose items start with a - 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