Novelty Polygonal Mathematics
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@sanity/code-input

1.150.1 • Public • Published

@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

npm i @sanity/code-input

DownloadsWeekly Downloads

8,276

Version

1.150.1

License

MIT

Unpacked Size

48 kB

Total Files

15

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar