Color mode

Code Enhance

Enhanced code blocks: Shiki highlighting plus a header with copy, wrap, and collapse controls.

日本語

Overview

codeEnhance() wraps rehype-pretty-code (Shiki) and post-processes each figure into .rr-code with a header and action buttons. The client entry wires up the buttons.

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { codeEnhance } from "@riebeckite/plugin-code-enhance";
 
export default defineConfig({
  // ...
  plugins: [
    codeEnhance({
      theme: { light: "github-light", dark: "github-dark" },
      lineNumbers: true,
      copyButton: true,
      filename: true,
      lineHighlight: true,
      diffHighlight: true,
      wrapToggle: true,
    }),
  ],
});

Features

  • Syntax highlighting via Shiki (rehype-pretty-code)
  • Header with the file name (code block title, falling back to the language) and action buttons
  • Copy button with "Copied" feedback (client)
  • Wrap toggle (client)
  • Collapse / expand button (opt-in, client)
  • Line numbers (data-line-number gutter)
  • Line and character highlighting from pretty-code meta ({1,3}, [/re/])
  • Diff coloring for lines starting with + / -
  • Terminal styling for bash, console, sh, shell, terminal, zsh (inverted palette) with a $ prompt prefix on non-empty lines
  • Focusable <pre> (tabindex="0") for keyboard scrolling

Options

Option Type Default Description
theme string | { light: string; dark: string } { light: "github-light", dark: "github-dark" } Shiki theme
lineNumbers boolean false Show line numbers
copyButton boolean true Show the copy button
filename boolean true Show the file name in the header
lineHighlight boolean true Apply meta-based line/char highlights
diffHighlight boolean true Color + / - lines
collapsible boolean false Add the collapse button
terminal boolean true Terminal styling for shell languages
commandPrompt boolean true $ prompt prefix on terminal lines
wrapToggle boolean true Show the wrap toggle button
defaultCollapsed boolean false Start collapsed (requires collapsible)
copyLabel string "Copy" Copy button label forwarded to the client
copiedLabel string "Copied" Label after copying, forwarded to the client

Client

codeEnhance() forwards copyLabel / copiedLabel to the client entry. initCodeEnhance(options?) installs a document-level click handler for copy, wrap, and collapse buttons.

Option Type Default Description
copyLabel string "Copy" Copy button label
copiedLabel string "Copied" Label after copying

Exports

  • codeEnhance(options?) — plugin factory
  • rehypeCodeEnhance(options?) — rehype transform
  • initCodeEnhance(options?) — client initializer
  • DEFAULT_COPY_LABEL, DEFAULT_COPIED_LABEL — default copy labels
  • Types: CodeEnhanceOptions, CodeEnhanceClientOptions, CodeEnhanceTheme

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/code-enhance/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Code Enhance
4 +
5 + Enhanced code blocks: Shiki highlighting plus a header with copy, wrap, and
6 + collapse controls.
7 +
8 + [日本語](./code-enhance.md)
9 +
10 + ## Overview
11 +
12 + `codeEnhance()` wraps [rehype-pretty-code](https://github.com/rehype-pretty-code/rehype-pretty-code)
13 + (Shiki) and post-processes each figure into `.rr-code` with a header and
14 + action buttons. The client entry wires up the buttons.
15 +
16 + ## Usage
17 +
18 + ```ts
19 + import { defineConfig } from "@riebeckite/core";
20 + import { codeEnhance } from "@riebeckite/plugin-code-enhance";
21 +
22 + export default defineConfig({
23 + // ...
24 + plugins: [
25 + codeEnhance({
26 + theme: { light: "github-light", dark: "github-dark" },
27 + lineNumbers: true,
28 + copyButton: true,
29 + filename: true,
30 + lineHighlight: true,
31 + diffHighlight: true,
32 + wrapToggle: true,
33 + }),
34 + ],
35 + });
36 + ```
37 +
38 + ## Features
39 +
40 + - Syntax highlighting via Shiki (rehype-pretty-code)
41 + - Header with the file name (code block title, falling back to the language)
42 + and action buttons
43 + - Copy button with "Copied" feedback (client)
44 + - Wrap toggle (client)
45 + - Collapse / expand button (opt-in, client)
46 + - Line numbers (`data-line-number` gutter)
47 + - Line and character highlighting from pretty-code meta (`{1,3}`, `[/re/]`)
48 + - Diff coloring for lines starting with `+` / `-`
49 + - Terminal styling for `bash`, `console`, `sh`, `shell`, `terminal`, `zsh`
50 + (inverted palette) with a `$` prompt prefix on non-empty lines
51 + - Focusable `<pre>` (`tabindex="0"`) for keyboard scrolling
52 +
53 + ## Options
54 +
55 + | Option | Type | Default | Description |
56 + | ------ | ---- | ------- | ----------- |
57 + | `theme` | `string \| { light: string; dark: string }` | `{ light: "github-light", dark: "github-dark" }` | Shiki theme |
58 + | `lineNumbers` | `boolean` | `false` | Show line numbers |
59 + | `copyButton` | `boolean` | `true` | Show the copy button |
60 + | `filename` | `boolean` | `true` | Show the file name in the header |
61 + | `lineHighlight` | `boolean` | `true` | Apply meta-based line/char highlights |
62 + | `diffHighlight` | `boolean` | `true` | Color `+` / `-` lines |
63 + | `collapsible` | `boolean` | `false` | Add the collapse button |
64 + | `terminal` | `boolean` | `true` | Terminal styling for shell languages |
65 + | `commandPrompt` | `boolean` | `true` | `$` prompt prefix on terminal lines |
66 + | `wrapToggle` | `boolean` | `true` | Show the wrap toggle button |
67 + | `defaultCollapsed` | `boolean` | `false` | Start collapsed (requires `collapsible`) |
68 + | `copyLabel` | `string` | `"Copy"` | Copy button label forwarded to the client |
69 + | `copiedLabel` | `string` | `"Copied"` | Label after copying, forwarded to the client |
70 +
71 + ## Client
72 +
73 + `codeEnhance()` forwards `copyLabel` / `copiedLabel` to the client entry.
74 + `initCodeEnhance(options?)` installs a document-level click handler for copy,
75 + wrap, and collapse buttons.
76 +
77 + | Option | Type | Default | Description |
78 + | ------ | ---- | ------- | ----------- |
79 + | `copyLabel` | `string` | `"Copy"` | Copy button label |
80 + | `copiedLabel` | `string` | `"Copied"` | Label after copying |
81 +
82 + ## Exports
83 +
84 + - `codeEnhance(options?)` — plugin factory
85 + - `rehypeCodeEnhance(options?)` — rehype transform
86 + - `initCodeEnhance(options?)` — client initializer
87 + - `DEFAULT_COPY_LABEL`, `DEFAULT_COPIED_LABEL` — default copy labels
88 + - Types: `CodeEnhanceOptions`, `CodeEnhanceClientOptions`, `CodeEnhanceTheme`
89 +
90 + ## See also
91 +
92 + - [Plugin guide](../reference/plugin-api.en.md)
93 +