Skip to content

Code

A code field is a monospace editor with syntax highlighting, for snippets, embed codes or small bits of markup that editors paste in. It stores the text as is.

import {Field} from 'alinea'

Field.code('Embed code', {
  help: 'Paste the embed code from your video provider'
})

Options

  • language: the language of the code, such as 'ts' or 'css'. The editor highlights code with a language-agnostic tokenizer and exposes the language as a data-language attribute; use 'text' (or 'plaintext') to turn highlighting off.

  • The common options help, width, inline, initialValue, required, validate, readOnly, hidden and shared.

Value

A string, including line breaks and indentation. It's empty until an editor enters something, unless you set an initialValue.

Alinea doesn't sanitize the value. If you render it as HTML (dangerouslySetInnerHTML), anyone who can edit the entry can add scripts to your site: limit the field to trusted editors with roles, or validate what's allowed.