# Accordion

> Editor42 Accordion plugin: collapsible sections built on the details and summary elements, which users insert, open, close and remove in the editor.

Source: https://editor42.com/plugins/accordion  
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: `accordion`

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

Provides collapsible accordion sections in the editor content using HTML `<details>`/`<summary>` elements. Users can insert new accordions, toggle their open/closed state, and remove them. The plugin manages keyboard behavior (Enter in summary toggles instead of creating a newline), content normalization, and browser-specific quirks.

## Commands

| Command | Description |
|---|---|
| `InsertAccordion` | Inserts a new accordion at the current cursor position. Uses selected text as the summary if any, otherwise defaults to placeholder text. |
| `ToggleAccordion` | Toggles the open/closed state of the accordion at the current selection. Accepts an optional boolean value to force a specific state. |
| `ToggleAllAccordions` | Toggles all accordions in the editor body. Accepts an optional boolean to force all open or all closed. |
| `RemoveAccordion` | Removes the accordion surrounding the current selection. |

## Toolbar buttons

| Name | Type | Description |
|---|---|---|
| `accordion` | Button | Insert accordion |
| `accordiontoggle` | Toggle button | Toggle accordion open/closed |
| `accordionremove` | Toggle button | Delete accordion |

A context toolbar with `accordiontoggle` and `accordionremove` appears automatically when the cursor is inside a `<details>` element.

## Menu items

| Name | Description |
|---|---|
| `accordion` | Insert accordion |

## Events

| Event | Description |
|---|---|
| `ToggledAccordion` | Fired after a single accordion is toggled. Payload: `{ element, state }` |
| `ToggledAllAccordions` | Fired after all accordions are toggled. Payload: `{ elements, state }` |
