Code Input

Official(made by Sanity team)

By Bjørge Næss

Syntax highlighted editor for 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 code field
  • languageAlternatives - Array of languages that should be available
  • theme - Name of the theme to use. Possible values: ['github', 'monokai', 'terminal', 'tomorrow']
  • withFilename - Boolean option to display input field for filename
// ...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.

Install command

sanity install @sanity/code-input

Contributor

Other plugins by author

Asset source for Unsplash

Search photos on Unsplash and insert them directly inside of your Sanity Studio.

Go to Asset source for Unsplash

Mux input

Upload videos to Mux directly from the studio.

Go to Mux input

Image URL

Official(made by Sanity team)

Helper library to generate URLs for image transformation

Go to Image URL