Code Editor

Displays a code block with an optional header and output area.

Some JSON

Import the component and piece the parts together.

The Code Block component is made up of six parts: Root, Output, Header, Content, Line Group, and Line. View source

A provider of the code editor context. Passes through the ref to the underlying codemirror editor.

A container for the code editor parts. Based on the div element, implements Flex props.

An optional area to display elements related to the Code Block, like its title, tabs, or current language. This component is based on the div element.

Code contents of the Code Block. This component is based on the div element, and uses codemirror’s EditorView to render the code.

In order to add syntax highlighting, you must pass in the appropriate extensions to the Root component. Codemirror implements many of these, but you may also implement a Lezer grammar for custom languages.

An optional area to display elements related to the Code Block, like diagnostics. This component is based on the div element.

An optional component that displays linting diagnostics. This component is based on the button element. Clicking it will navigate to the next diagnostic in the content.

Syntax highlighting is provided by the extensions prop.

Some JSON

###Syntax Error

Linting can be done using @codemirror/lint, and a linter for a given language. The linter can be an async function, and codemirror will track the position of the error while the code changes until the next linting passes.

Some JSON