$example ( element -- )
Factor handbook » Developer tools » Help system » Writing documentation » Element types » Block elements

Prev:$curious ( element -- )
Next:$heading ( element -- )


elementa markup element of the form { inputs... output }


Word description
Prints a clickable example with sample output. The markup element must be an array of strings. All but the last string are joined by newlines and taken as the input text, and the last string is the output. The example becomes clickable if the output stream supports it, and clicking it opens a listener window with the input text inserted at the input prompt.

The input text must contain a correct USING: declaration, and output text should be a string of what the input prints when executed, not the final stack contents or anything like that. So the following is an incorrect example:
{ $unchecked-example "2 2 +" "4" } print-element

2 2 +

However the following is right:
{ $example "USING: math prettyprint ;" "2 2 + ." "4" } print-element

USING: math prettyprint ; 2 2 + .

Examples can incorporate a call to .s to show multiple output values; the convention is that you may assume the stack is empty before the example evaluates.

See also