Plugins Code blocks

show code @mdsvex/plugin-code-blocks@0.1.0-next.1

Code blocks

Code blocks with a copy button that announces the result, the title and the caption

Install

pnpm add -D @mdsvex/plugin-code-blocks@next

Turn it on

import { code_blocks } from '@mdsvex/plugin-code-blocks';

mdsvex({ plugins: [code_blocks()] });

What it reads

```js title="a.js"

replaces <pre>

An example

You write
```js title="mdsvex.config.js"
export default { heading_ids: true };
```

You get
mdsvex.config.js
export default { heading_ids: true };
Build-time preview.

Replaces pre with a code block that has a copy button, the title of the fence above the code and its caption below. The button is named "Copy code of" and the title, a status region beside it announces "Copied" or "Copy failed", and nocopy in the fence meta leaves it out. It copies the code prop, so live values are copied as the reader sees them. Without JavaScript the stylesheet hides the button. In a code group of tabs the tab shows the title, so the code block hides its own. A pre from a components module or a template replaces it, and the plugin's own is exported as @mdsvex/plugin-code-blocks/Pre.svelte.

Options, from its types 1

css?: boolean
False leaves the default stylesheet out, the markup and its class names stay the same

Components @mdsvex/plugin-code-blocks/Pre.svelte

Stylesheet @mdsvex/plugin-code-blocks/code-blocks.css, or code_blocks({ css: false }) for none

Find another plugin · Write your own

mdsvex, markdown with Svelte in it. MIT licence.