# Code Sample

> Editor42 Code Sample plugin: insert and edit syntax-highlighted code snippets, kept as pre elements with a language class and highlighted by Prism.js.

Source: https://editor42.com/plugins/codesample  
Every page of editor42.com has a Markdown copy at its URL + `.md` (`index.md` after a URL that ends in `/`); all of them are in one file: https://editor42.com/llms-full.txt

Plugin alias: `codesample`

```js
editor42.init({
  plugins: 'codesample'
});
```

Enables inserting and editing syntax-highlighted code snippets in the editor content. Code blocks are rendered as `<pre>` elements with a `language-*` class and highlighted using Prism.js (either bundled or a global instance). Code samples are non-editable in the editor; double-click to open the edit dialog.

## Options

| Option | Type | Default | Description |
|---|---|---|---|
| `codesample_languages` | object[] | HTML/XML, JavaScript, CSS, PHP, Ruby, Python, Java, C, C#, C++ | Array of `{ text, value }` objects defining available languages. |
| `codesample_global_prismjs` | boolean | `false` | Use a globally loaded Prism.js instance instead of the bundled one. |

## Commands

| Command | Description |
|---|---|
| `codesample` | Opens insert/edit dialog when cursor is in a code sample or selection is collapsed; toggles inline `code` format otherwise. |

## Toolbar buttons

| Name | Type | Description |
|---|---|---|
| `codesample` | Toggle button | Active when cursor is in a code sample. |

## Menu items

| Name | Description |
|---|---|
| `codesample` | Code sample. |
