@riebeckite/plugin-code-enhance 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -86
- package/README_ja.md +53 -53
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -2
- package/dist/src/remark.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
# @riebeckite/plugin-code-enhance
|
|
2
|
-
|
|
3
|
-
Enhanced code blocks: Shiki highlighting plus a header with copy, wrap, and
|
|
4
|
-
collapse controls.
|
|
5
|
-
|
|
6
|
-
[日本語](./README_ja.md)
|
|
7
|
-
|
|
8
|
-
## Overview
|
|
9
|
-
|
|
10
|
-
`codeEnhance()` wraps [rehype-pretty-code](https://github.com/rehype-pretty-code/rehype-pretty-code)
|
|
11
|
-
(Shiki) and post-processes each figure into `.rr-code` with a header and
|
|
12
|
-
action buttons. The client entry wires up the buttons.
|
|
13
|
-
|
|
14
|
-
## Usage
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
import { defineConfig } from "@riebeckite/core";
|
|
18
|
-
import { codeEnhance } from "@riebeckite/plugin-code-enhance";
|
|
19
|
-
|
|
20
|
-
export default defineConfig({
|
|
21
|
-
// ...
|
|
22
|
-
plugins: [
|
|
23
|
-
codeEnhance({
|
|
24
|
-
theme: { light: "github-light", dark: "github-dark" },
|
|
25
|
-
lineNumbers: true,
|
|
26
|
-
copyButton: true,
|
|
27
|
-
filename: true,
|
|
28
|
-
lineHighlight: true,
|
|
29
|
-
diffHighlight: true,
|
|
30
|
-
wrapToggle: true,
|
|
31
|
-
}),
|
|
32
|
-
],
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Features
|
|
37
|
-
|
|
38
|
-
- Syntax highlighting via Shiki (rehype-pretty-code)
|
|
39
|
-
- Header with the file name (code block title, falling back to the language)
|
|
40
|
-
and action buttons
|
|
41
|
-
- Copy button with "Copied" feedback (client)
|
|
42
|
-
- Wrap toggle (client)
|
|
43
|
-
- Collapse / expand button (opt-in, client)
|
|
44
|
-
- Line numbers (`data-line-number` gutter)
|
|
45
|
-
- Line and character highlighting from pretty-code meta (`{1,3}`, `[/re/]`)
|
|
46
|
-
- Diff coloring for lines starting with `+` / `-`
|
|
47
|
-
- Terminal styling for `bash`, `console`, `sh`, `shell`, `terminal`, `zsh`
|
|
48
|
-
(inverted palette) with a `$` prompt prefix on non-empty lines
|
|
49
|
-
- Focusable `<pre>` (`tabindex="0"`) for keyboard scrolling
|
|
50
|
-
|
|
51
|
-
## Options
|
|
52
|
-
|
|
53
|
-
| Option | Type | Default | Description |
|
|
54
|
-
| ------ | ---- | ------- | ----------- |
|
|
55
|
-
| `theme` | `string \| { light: string; dark: string }` | `{ light: "github-light", dark: "github-dark" }` | Shiki theme |
|
|
56
|
-
| `lineNumbers` | `boolean` | `false` | Show line numbers |
|
|
57
|
-
| `copyButton` | `boolean` | `true` | Show the copy button |
|
|
58
|
-
| `filename` | `boolean` | `true` | Show the file name in the header |
|
|
59
|
-
| `lineHighlight` | `boolean` | `true` | Apply meta-based line/char highlights |
|
|
60
|
-
| `diffHighlight` | `boolean` | `true` | Color `+` / `-` lines |
|
|
61
|
-
| `collapsible` | `boolean` | `false` | Add the collapse button |
|
|
62
|
-
| `terminal` | `boolean` | `true` | Terminal styling for shell languages |
|
|
63
|
-
| `commandPrompt` | `boolean` | `true` | `$` prompt prefix on terminal lines |
|
|
64
|
-
| `wrapToggle` | `boolean` | `true` | Show the wrap toggle button |
|
|
65
|
-
| `defaultCollapsed` | `boolean` | `false` | Start collapsed (requires `collapsible`) |
|
|
66
|
-
|
|
67
|
-
## Client
|
|
68
|
-
|
|
69
|
-
`initCodeEnhance(options?)` installs a document-level click handler for copy,
|
|
70
|
-
wrap, and collapse buttons.
|
|
71
|
-
|
|
72
|
-
| Option | Type | Default | Description |
|
|
73
|
-
| ------ | ---- | ------- | ----------- |
|
|
74
|
-
| `copyLabel` | `string` | `"Copy"` | Copy button label |
|
|
75
|
-
| `copiedLabel` | `string` | `"Copied"` | Label after copying |
|
|
76
|
-
|
|
77
|
-
## Exports
|
|
78
|
-
|
|
79
|
-
- `codeEnhance(options?)` — plugin factory
|
|
80
|
-
- `rehypeCodeEnhance(options?)` — rehype transform
|
|
81
|
-
- `initCodeEnhance(options?)` — client initializer
|
|
82
|
-
- Types: `CodeEnhanceOptions`, `CodeEnhanceClientOptions`, `CodeEnhanceTheme`
|
|
83
|
-
|
|
84
|
-
## See also
|
|
85
|
-
|
|
86
|
-
- [Plugin guide](../../../docs/en/plugin-
|
|
1
|
+
# @riebeckite/plugin-code-enhance
|
|
2
|
+
|
|
3
|
+
Enhanced code blocks: Shiki highlighting plus a header with copy, wrap, and
|
|
4
|
+
collapse controls.
|
|
5
|
+
|
|
6
|
+
[日本語](./README_ja.md)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
`codeEnhance()` wraps [rehype-pretty-code](https://github.com/rehype-pretty-code/rehype-pretty-code)
|
|
11
|
+
(Shiki) and post-processes each figure into `.rr-code` with a header and
|
|
12
|
+
action buttons. The client entry wires up the buttons.
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { defineConfig } from "@riebeckite/core";
|
|
18
|
+
import { codeEnhance } from "@riebeckite/plugin-code-enhance";
|
|
19
|
+
|
|
20
|
+
export default defineConfig({
|
|
21
|
+
// ...
|
|
22
|
+
plugins: [
|
|
23
|
+
codeEnhance({
|
|
24
|
+
theme: { light: "github-light", dark: "github-dark" },
|
|
25
|
+
lineNumbers: true,
|
|
26
|
+
copyButton: true,
|
|
27
|
+
filename: true,
|
|
28
|
+
lineHighlight: true,
|
|
29
|
+
diffHighlight: true,
|
|
30
|
+
wrapToggle: true,
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- Syntax highlighting via Shiki (rehype-pretty-code)
|
|
39
|
+
- Header with the file name (code block title, falling back to the language)
|
|
40
|
+
and action buttons
|
|
41
|
+
- Copy button with "Copied" feedback (client)
|
|
42
|
+
- Wrap toggle (client)
|
|
43
|
+
- Collapse / expand button (opt-in, client)
|
|
44
|
+
- Line numbers (`data-line-number` gutter)
|
|
45
|
+
- Line and character highlighting from pretty-code meta (`{1,3}`, `[/re/]`)
|
|
46
|
+
- Diff coloring for lines starting with `+` / `-`
|
|
47
|
+
- Terminal styling for `bash`, `console`, `sh`, `shell`, `terminal`, `zsh`
|
|
48
|
+
(inverted palette) with a `$` prompt prefix on non-empty lines
|
|
49
|
+
- Focusable `<pre>` (`tabindex="0"`) for keyboard scrolling
|
|
50
|
+
|
|
51
|
+
## Options
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
| ------ | ---- | ------- | ----------- |
|
|
55
|
+
| `theme` | `string \| { light: string; dark: string }` | `{ light: "github-light", dark: "github-dark" }` | Shiki theme |
|
|
56
|
+
| `lineNumbers` | `boolean` | `false` | Show line numbers |
|
|
57
|
+
| `copyButton` | `boolean` | `true` | Show the copy button |
|
|
58
|
+
| `filename` | `boolean` | `true` | Show the file name in the header |
|
|
59
|
+
| `lineHighlight` | `boolean` | `true` | Apply meta-based line/char highlights |
|
|
60
|
+
| `diffHighlight` | `boolean` | `true` | Color `+` / `-` lines |
|
|
61
|
+
| `collapsible` | `boolean` | `false` | Add the collapse button |
|
|
62
|
+
| `terminal` | `boolean` | `true` | Terminal styling for shell languages |
|
|
63
|
+
| `commandPrompt` | `boolean` | `true` | `$` prompt prefix on terminal lines |
|
|
64
|
+
| `wrapToggle` | `boolean` | `true` | Show the wrap toggle button |
|
|
65
|
+
| `defaultCollapsed` | `boolean` | `false` | Start collapsed (requires `collapsible`) |
|
|
66
|
+
|
|
67
|
+
## Client
|
|
68
|
+
|
|
69
|
+
`initCodeEnhance(options?)` installs a document-level click handler for copy,
|
|
70
|
+
wrap, and collapse buttons.
|
|
71
|
+
|
|
72
|
+
| Option | Type | Default | Description |
|
|
73
|
+
| ------ | ---- | ------- | ----------- |
|
|
74
|
+
| `copyLabel` | `string` | `"Copy"` | Copy button label |
|
|
75
|
+
| `copiedLabel` | `string` | `"Copied"` | Label after copying |
|
|
76
|
+
|
|
77
|
+
## Exports
|
|
78
|
+
|
|
79
|
+
- `codeEnhance(options?)` — plugin factory
|
|
80
|
+
- `rehypeCodeEnhance(options?)` — rehype transform
|
|
81
|
+
- `initCodeEnhance(options?)` — client initializer
|
|
82
|
+
- Types: `CodeEnhanceOptions`, `CodeEnhanceClientOptions`, `CodeEnhanceTheme`
|
|
83
|
+
|
|
84
|
+
## See also
|
|
85
|
+
|
|
86
|
+
- [Plugin guide](../../../docs/en/reference/plugin-api.md)
|
package/README_ja.md
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
# @riebeckite/plugin-code-enhance
|
|
2
|
-
|
|
3
|
-
Shiki によるシンタックスハイライトへ、コピー、折り返し、折りたたみなどの操作を加えるプラグインです。
|
|
4
|
-
|
|
5
|
-
[English](./README.md)
|
|
6
|
-
|
|
7
|
-
## 設定
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
import { defineConfig } from "@riebeckite/core";
|
|
11
|
-
import { codeEnhance } from "@riebeckite/plugin-code-enhance";
|
|
12
|
-
|
|
13
|
-
export default defineConfig({
|
|
14
|
-
// ...
|
|
15
|
-
plugins: [codeEnhance({ lineNumbers: true, wrapToggle: true })],
|
|
16
|
-
});
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
`codeEnhance()` は `rehype-pretty-code` を使ってコードブロックを処理し、ファイル名と操作ボタンを持つ `.rr-code` 要素に整えます。ボタンの操作はクライアントエントリーが担当します。
|
|
20
|
-
|
|
21
|
-
## 表示と操作
|
|
22
|
-
|
|
23
|
-
- Shiki のテーマによる色付け、行番号、メタデータによる行・文字の強調
|
|
24
|
-
- `+` と `-` で始まる行の差分表示
|
|
25
|
-
- コピー、折り返し、任意の折りたたみ
|
|
26
|
-
- `bash`、`console`、`sh` などを端末風に表示し、必要に応じて `$` を付ける
|
|
27
|
-
- キーボードで内容を確認できるよう、`<pre>` をフォーカス可能にする
|
|
28
|
-
|
|
29
|
-
## 主なオプション
|
|
30
|
-
|
|
31
|
-
| オプション | 既定値 | 内容 |
|
|
32
|
-
| --- | --- | --- |
|
|
33
|
-
| `theme` | GitHub の明暗テーマ | Shiki テーマ。文字列または `{ light, dark }` |
|
|
34
|
-
| `lineNumbers` | `false` | 行番号を表示するか |
|
|
35
|
-
| `copyButton` | `true` | コピーボタンを表示するか |
|
|
36
|
-
| `filename` | `true` | 見出しにファイル名を表示するか |
|
|
37
|
-
| `lineHighlight` / `diffHighlight` | `true` | 強調表示・差分表示を有効にするか |
|
|
38
|
-
| `collapsible` / `defaultCollapsed` | `false` | 折りたたみと初期状態 |
|
|
39
|
-
| `terminal` / `commandPrompt` | `true` | 端末風表示と `$` の付与 |
|
|
40
|
-
| `wrapToggle` | `true` | 折り返し切替を表示するか |
|
|
41
|
-
|
|
42
|
-
`initCodeEnhance({ copyLabel, copiedLabel })` では、コピー前後のボタン文言を変更できます。
|
|
43
|
-
|
|
44
|
-
## 公開 API
|
|
45
|
-
|
|
46
|
-
- `codeEnhance(options?)` — プラグインファクトリ
|
|
47
|
-
- `rehypeCodeEnhance(options?)` — Rehype 変換
|
|
48
|
-
- `initCodeEnhance(options?)` — ブラウザ初期化関数
|
|
49
|
-
- `CodeEnhanceOptions`、`CodeEnhanceClientOptions`、`CodeEnhanceTheme` — 型
|
|
50
|
-
|
|
51
|
-
## 関連資料
|
|
52
|
-
|
|
53
|
-
- [プラグインシステム](../../../docs/ja/plugin-
|
|
1
|
+
# @riebeckite/plugin-code-enhance
|
|
2
|
+
|
|
3
|
+
Shiki によるシンタックスハイライトへ、コピー、折り返し、折りたたみなどの操作を加えるプラグインです。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 設定
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineConfig } from "@riebeckite/core";
|
|
11
|
+
import { codeEnhance } from "@riebeckite/plugin-code-enhance";
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
// ...
|
|
15
|
+
plugins: [codeEnhance({ lineNumbers: true, wrapToggle: true })],
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`codeEnhance()` は `rehype-pretty-code` を使ってコードブロックを処理し、ファイル名と操作ボタンを持つ `.rr-code` 要素に整えます。ボタンの操作はクライアントエントリーが担当します。
|
|
20
|
+
|
|
21
|
+
## 表示と操作
|
|
22
|
+
|
|
23
|
+
- Shiki のテーマによる色付け、行番号、メタデータによる行・文字の強調
|
|
24
|
+
- `+` と `-` で始まる行の差分表示
|
|
25
|
+
- コピー、折り返し、任意の折りたたみ
|
|
26
|
+
- `bash`、`console`、`sh` などを端末風に表示し、必要に応じて `$` を付ける
|
|
27
|
+
- キーボードで内容を確認できるよう、`<pre>` をフォーカス可能にする
|
|
28
|
+
|
|
29
|
+
## 主なオプション
|
|
30
|
+
|
|
31
|
+
| オプション | 既定値 | 内容 |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| `theme` | GitHub の明暗テーマ | Shiki テーマ。文字列または `{ light, dark }` |
|
|
34
|
+
| `lineNumbers` | `false` | 行番号を表示するか |
|
|
35
|
+
| `copyButton` | `true` | コピーボタンを表示するか |
|
|
36
|
+
| `filename` | `true` | 見出しにファイル名を表示するか |
|
|
37
|
+
| `lineHighlight` / `diffHighlight` | `true` | 強調表示・差分表示を有効にするか |
|
|
38
|
+
| `collapsible` / `defaultCollapsed` | `false` | 折りたたみと初期状態 |
|
|
39
|
+
| `terminal` / `commandPrompt` | `true` | 端末風表示と `$` の付与 |
|
|
40
|
+
| `wrapToggle` | `true` | 折り返し切替を表示するか |
|
|
41
|
+
|
|
42
|
+
`initCodeEnhance({ copyLabel, copiedLabel })` では、コピー前後のボタン文言を変更できます。
|
|
43
|
+
|
|
44
|
+
## 公開 API
|
|
45
|
+
|
|
46
|
+
- `codeEnhance(options?)` — プラグインファクトリ
|
|
47
|
+
- `rehypeCodeEnhance(options?)` — Rehype 変換
|
|
48
|
+
- `initCodeEnhance(options?)` — ブラウザ初期化関数
|
|
49
|
+
- `CodeEnhanceOptions`、`CodeEnhanceClientOptions`、`CodeEnhanceTheme` — 型
|
|
50
|
+
|
|
51
|
+
## 関連資料
|
|
52
|
+
|
|
53
|
+
- [プラグインシステム](../../../docs/ja/reference/plugin-api.md)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CodeEnhanceOptions } from "./src/types.js";
|
|
2
2
|
export { initCodeEnhance } from "./src/init.js";
|
|
3
3
|
export { rehypeCodeEnhance } from "./src/rehype.js";
|
|
4
|
+
export { remarkCodeMeta } from "./src/remark.js";
|
|
4
5
|
export type { CodeEnhanceClientOptions, CodeEnhanceOptions, CodeEnhanceTheme, } from "./src/types.js";
|
|
5
6
|
export declare function codeEnhance(options?: CodeEnhanceOptions): import("@riebeckite/core").RiebeckitePlugin<CodeEnhanceOptions>;
|
package/dist/index.js
CHANGED
|
@@ -119,7 +119,7 @@ function restoreCodeMeta(tree) {
|
|
|
119
119
|
if (!code) return;
|
|
120
120
|
const meta = getCodeMeta(code);
|
|
121
121
|
if (!meta) return;
|
|
122
|
-
|
|
122
|
+
code.data = { ...getRecord(code.data), meta };
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
var LANGUAGE_CLASS_PREFIX = "language-";
|
|
@@ -343,6 +343,27 @@ function isTerminalLanguage(language) {
|
|
|
343
343
|
);
|
|
344
344
|
}
|
|
345
345
|
|
|
346
|
+
// src/remark.ts
|
|
347
|
+
function remarkCodeMeta() {
|
|
348
|
+
return (tree) => {
|
|
349
|
+
visitMdast(tree, (node) => {
|
|
350
|
+
if (node.type !== "code") return;
|
|
351
|
+
if (typeof node.meta !== "string" || node.meta.trim() === "") return;
|
|
352
|
+
node.data = {
|
|
353
|
+
...node.data ?? {},
|
|
354
|
+
hProperties: {
|
|
355
|
+
...node.data?.hProperties,
|
|
356
|
+
"data-meta": node.meta
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function visitMdast(node, visitor) {
|
|
363
|
+
visitor(node);
|
|
364
|
+
for (const child of node.children ?? []) visitMdast(child, visitor);
|
|
365
|
+
}
|
|
366
|
+
|
|
346
367
|
// src/init.ts
|
|
347
368
|
var DEFAULT_COPY_LABEL = "Copy";
|
|
348
369
|
var DEFAULT_COPIED_LABEL = "Copied";
|
|
@@ -402,6 +423,7 @@ function codeEnhance(options = {}) {
|
|
|
402
423
|
return definePlugin({
|
|
403
424
|
name: "code-enhance",
|
|
404
425
|
options,
|
|
426
|
+
remarkPlugins: [remarkCodeMeta],
|
|
405
427
|
extendHtmlPipeline: (pipeline) => {
|
|
406
428
|
pipeline.use(rehypeCodeEnhance, options);
|
|
407
429
|
},
|
|
@@ -412,5 +434,6 @@ function codeEnhance(options = {}) {
|
|
|
412
434
|
export {
|
|
413
435
|
codeEnhance,
|
|
414
436
|
initCodeEnhance,
|
|
415
|
-
rehypeCodeEnhance
|
|
437
|
+
rehypeCodeEnhance,
|
|
438
|
+
remarkCodeMeta
|
|
416
439
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-code-enhance",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"rehype-pretty-code": "^0.14.1",
|
|
25
25
|
"shiki": "^3.13.0",
|
|
26
|
-
"@riebeckite/core": "0.0.
|
|
26
|
+
"@riebeckite/core": "0.0.13"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"tsx": "^4.22.4"
|