<codeEditor>
<codeEditor> renders an embedded text editor pre-populated with
DoenetML source. The viewer can edit the source and, when showResults is
set, see the live preview rendered alongside.
Use <codeEditor> for tutorials and demos where the learner is expected
to modify DoenetML, not just read it. For documentation-style read-only
displays of source text, use <displayDoenetML> inside
a <pre> instead.
The implicit value of a <codeEditor> is its current source text. The
bindValueTo attribute creates a two-way binding to a referenced text-valued
component.
Attributes and Properties
Attributes for <codeEditor>
Other (11)
text. Two-way binding target for the input's value.
componentSize. Default value: {"size":400,"isAbsolute":true}. Editor height (e.g. "500px").
text. Initial code shown in the editor before the user types.
boolean. Default value: false. Whether the editor is read-only.
renderedNametext. Name to assign to the dynamically-rendered DoenetML output.
keyword. Position of the results panel relative to the editor.
| Value | Description |
|---|---|
bottom (default) | Place the results panel below the editor. |
left | Place the results panel to the left of the editor. |
right | Place the results panel to the right of the editor. |
showFormatterboolean. Default value: false. Whether to show a code formatter button.
boolean. Default value: false. Whether to render the results panel alongside the editor.
staticNametext. Name to assign to the static DoenetML source.
viewerRationumber. Fraction of the editor area allotted to the live viewer.
componentSize. Default value: {"size":"100","isAbsolute":false}. Editor width (e.g. "100%" or "600px").
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <codeEditor name="c">
Other (16)
$c.disabledboolean. Whether this component is disabled and cannot be interacted with.
$c.fixedboolean. Whether this component's value is fixed and cannot be modified.
$c.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$c.heightcomponentSize. Editor height (e.g. "500px").
$c.immediateValuetext. The current code in the editor (live, before saving).
$c.immediateValueChangedboolean. Whether the live (immediate) value has been changed from its initial state.
$c.prefilltext. Initial code shown in the editor before the user types.
$c.readOnlyboolean. Whether the editor is read-only.
$c.resultsLocationtext. Position of the results panel relative to the editor.
$c.showFormatterboolean. Whether to show a code formatter button.
$c.showResultsboolean. Whether to render the results panel alongside the editor.
$c.texttext. The current code as a plain text string.
$c.valuetext. The most recently saved code value.
$c.valueChangedboolean. Whether the saved value has been changed from its initial state.
$c.widthcomponentSize. Editor width (e.g. "100%" or "600px").
Common to all components (4)
$c.doenetMLtext. The DoenetML source code that produced this component.
$c.hideboolean. Whether to hide this component from the rendered output.
$c.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$c.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: Editor with live preview
The children of <codeEditor> provide the initial source. With
showResults set, the viewer renders that source live in a results panel
attached to the editor. Click the Source tab above to see the DoenetML
that produced this example.
Attribute Examples
Attribute Example: prefill
The prefill attribute supplies the editor’s initial text as a string. Use
this when the starting source is short enough to live inline; for longer
starting documents, use children instead.
Attribute Example: showResults, resultsLocation
showResults toggles the live preview panel; resultsLocation places it
relative to the editor (bottom, right, or left). The default is bottom.
Attribute Example: readOnly
When readOnly is set, the viewer can see the source and run the preview but
cannot modify the source text.
Attribute Example: width, height
width and height accept CSS-style sizes. The defaults are full available
width and a moderate fixed height.
Attribute Example: bindValueTo
bindValueTo two-way binds the editor’s text to a referenced text-valued
component. Edits made in either input update the other. The label on the
<textInput> makes the field accessible — its peer
<codeEditor> reflects whatever is typed there.