← Plugins

Code Input

Syntax highlighted editor for code.

Syntax highlighted editor for code.

{
  name: 'myCode',
  title: 'Code editor (default)',
  description: 'Code editor',
  type: 'code'
}

@sanity/code-input

Code input for Sanity.

Currently only a subset of languages and features are exposed, over time we will implement a richer set of options.

Installation

sanity install @sanity/code-input

Usage

Use it in your schema types:

// [...]
{
  fields: [
    // [...]
    {
      name: 'exampleUsage',
      title: 'Example usage',
      type: 'code'
    }
  ]
}

Note that the above only works if you import and use the all:part:@sanity/base/schema-type part in your schema.

Options

  • language - Default language for this coe field
  • languageAlternatives - Array of languages that should be available
  • theme - Name of the theme to use. Possible values: ['github', 'monokai', 'terminal', 'tomorrow']
// ...fields...
{
  name: 'exampleUsage',
  title: 'Example usage',
  type: 'code',
  options: {
    language: 'js'
  }
}

Data model

{
  _type: 'code',
  language: 'js',
  highlightedLines: [1, 2],
  code: 'const foo = "bar"\nconsole.log(foo.toUpperCase())\n// BAR'
}

License

MIT-licensed. See LICENSE.