Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Code

Code editor field stored as a plain text string. Renders a CodeMirror 6 editor in the admin UI with syntax highlighting and language-aware features.

SQLite Storage

TEXT column containing the raw code string.

Definition

crap.fields.code({
    name = "metadata",
    admin = {
        language = "json", -- "json", "javascript", "html", "css", "python", or "plain"
    },
})

Admin Options

PropertyTypeDefaultDescription
admin.languagestring"json"Language mode for syntax highlighting.

Supported Languages

ValueLanguage
jsonJSON
javascript or jsJavaScript
htmlHTML
cssCSS
python or pyPython
plainNo syntax highlighting

Admin Rendering

Renders as a CodeMirror 6 editor with line numbers, bracket matching, code folding, auto-completion, and search. Falls back to a plain <textarea> if the CodeMirror bundle is not loaded.

Notes

  • Content is stored as a raw string (not parsed or validated for syntax)
  • Supports min_length and max_length validation (applied to the raw string)
  • The CodeMirror bundle (static/codemirror.js) is loaded via <script defer> in the admin layout
  • To rebuild the bundle: bash scripts/bundle-codemirror.sh