dsh-paste-code-block 0.2.5 → 0.2.7

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 dsh-paste-code-block contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-paste-code-block contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,118 +1,118 @@
1
- <div align="center">
2
-
3
- # dsh-paste-code-block
4
-
5
- **Cherry Studio‑style text/code block pasting for DeepSeek Harness Web**
6
-
7
- Paste long code or text into the DSH Web composer → it lands as a **bordered, collapsible, language‑tagged card** instead of a wall of text. Names follow the DSH interface language (中文 / English). On send, the original content is restored as a fenced code block — and in the conversation it **stays folded** into click‑to‑expand cards, so your bubbles never become text walls again.
8
-
9
- [![npm version](https://img.shields.io/npm/v/dsh-paste-code-block?logo=npm)](https://www.npmjs.com/package/dsh-paste-code-block)
10
- [![License: MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
11
- [![platform: web](https://img.shields.io/badge/platform-DSH%20Web-blueviolet)](https://github.com/deepseek-ai/deepseek-harness)
12
-
13
- **English | [简体中文](./README.zh-CN.md)**
14
-
15
- </div>
16
-
17
- ![Preview — pasted blocks become tidy cards](./docs/images/hero.png)
18
-
19
- ## Why
20
-
21
- Copying a 200‑line stack trace, an API response, or a long log into a chat input turns the composer into an unreadable blob. This plugin folds any qualifying paste into a **chip** (built on DSH's own hidden‑reference mechanism, the same one file uploads use) plus an **editing detail card** — the draft stays clean, and the content stays fully editable and restorable.
22
-
23
- ## Features
24
-
25
- - 🧩 **Auto block detection** — pasted text with ``` fences, newlines, heavy indentation, or length ≥ 96 becomes a card; ordinary short prose pastes through untouched.
26
- - 🏷️ **Language tags** — auto-detects Python / JS / JSON / YAML / SQL / bash / HTML·XML / C++ / Go / Ruby (incl. shebangs); plain-text blocks are tagged `text`.
27
- - ✏️ **In-card editing** — edit the content right in the detail card; the edited text is exactly what gets sent. Plus copy, collapse/expand, and hide.
28
- - 🈯 **Localized names** — chips are named in the current DSH language: `代码块 1` / `Code #1`, `文本块 N` / `Text #N`. A leading glyph and tint tells the two apart at a glance — `</>` blue for code, `Aa` gray for text. Switching **Settings → Language** live-retitles every chip.
29
- - × **One-click remove** — every chip carries its own `×` delete button (the detail card has one too); a removed number is recycled immediately.
30
- - 📤 **Fenced restore on send** — each card expands back into a ```` ```lang … ``` ```` block when you send; a failed send automatically refills the input.
31
- - 📦 **Folded after send** — sent blocks keep folding in the transcript: every fenced block inside your own messages renders as a collapsed card (`python · 128 行` / `python · 128 lines`). Click the header to expand, again to collapse; the card's copy button grabs the original fenced text verbatim. Bare ```` ``` ```` fences fold as code (only an explicit ```` ```text ```` folds as a text block).
32
- - 💾 **Mid-draft safe** — DSH persists a composer draft as plain text, so pasted blocks are automatically re-attached when the composer is rebuilt (workspace switch on the new-session page, page reload); hand-deleted blocks are never "resurrected".
33
- - 🔢 **Smart numbering** — code and text count apart; the smallest free number is always reused.
34
- - 📱 **Every surface** — pure client plugin; works on desktop & mobile web, follows light/dark themes.
35
-
36
- ## How it works
37
-
38
- ![Four steps: copy · paste · tidy · send](./docs/images/workflow.png)
39
-
40
- ## Localization
41
-
42
- Chip labels, tooltips, line counts, and the send-time error notice all render through the official DSH locale service: the plugin registers a `paste-code-block` dictionary namespace with complete **zh / en** key sets, and its composer dock declares that namespace, so everything re-renders on every language switch.
43
-
44
- ![Block names follow the UI language](./docs/images/languages.png)
45
-
46
- - **New pastes** are named in whatever language is active at paste time.
47
- - **Existing chips** are re-titled live when you flip 设置 → 语言 / Settings → Language — no reload needed.
48
- - Clicks and deletes match chips **across languages**: a `代码块 2` chip still resolves to its block after switching to English (where it now reads `Code #2`), and vice versa.
49
-
50
- ## Install
51
-
52
- Requires DSH `0.1.x` (developer preview — APIs may change). Published on **npm** — install by name:
53
-
54
- ```sh
55
- dsh plugin --profile web add dsh-paste-code-block
56
- ```
57
-
58
- Or from this repository / a local checkout:
59
-
60
- ```sh
61
- dsh plugin --profile web add github:cjm-m/dsh-paste-code-block # from GitHub
62
- dsh plugin --profile web add file:/path/to/dsh-paste-code-block # from a local folder
63
- ```
64
-
65
- **Restart `dsh web`** after installing.
66
-
67
- ## Usage
68
-
69
- 1. Copy any code or multi-line text from anywhere.
70
- 2. Paste into the DSH input → it collapses into a chip such as `代码块 1` / `Code #1`.
71
- 3. Click the chip to open the card: read, edit inline, copy, collapse. Click the chip's (or the card's) `×` to delete that block.
72
- 4. Send — the full original text goes out as a proper fenced code block.
73
- 5. In the conversation it stays folded: each block sits in the bubble as a collapsed card — click the header to expand and read, click again to collapse.
74
-
75
- Detection threshold: **contains a newline / ≥ 2 lines / length ≥ 96 / indented & brace-dense / fenced** — any one turns the paste into a block.
76
-
77
- ## Notes & boundaries
78
-
79
- - Blocks are **appended at the end of the draft** (reusing DSH's hidden-reference semantics), which keeps cursor/undo stable.
80
- - Plain-text blocks are sent wrapped in ```` ```text ``` ```` so they never smear into one line.
81
- - Removing a chip any other way (e.g. `Backspace`) also frees its number — plugin state is reconciled against the editor continuously.
82
- - Deleting one block never touches the others, and removal is an ordinary editor edit — `Ctrl+Z` brings it back.
83
- - Creating a block leaves **no stray space**: DSH appends a separating space after a freshly inserted chip, and the plugin removes exactly that one character, so text typed after a block does not start with a space and pasting several blocks never piles spaces into the message. Spaces you typed yourself are never touched by pasting or deleting.
84
- - Post-send folding is **display-only**: it restyles your own message bubbles (and steering rows / the send echo) in the DOM. Stored messages are never modified, the bubble's own copy / edit / delete bar keeps working on the original text, and assistant messages are left alone.
85
- - Draft-rebuild recovery keeps a small localStorage mirror (block payloads plus a draft fingerprint; written while you edit, cleared when you send, expired after two weeks). If the browser blocks local storage (private mode), blocks still survive a same-tab workspace switch from memory — just not a full page reload.
86
-
87
- ## Project layout
88
-
89
- ```
90
- dsh-paste-code-block/
91
- ├── src/
92
- │ ├── client.js # Web (browser) half — paste capture, chips, detail card, × delete, sent-message fold, draft-rebuild recovery
93
- │ ├── index.js # Host (node) half — intentionally empty (pure UI plugin)
94
- │ ├── parse.js # Pure block-detection + fence-splitting logic (canonical, unit-tested)
95
- │ └── i18n.js # Locale dictionaries, label & fold-title builders (canonical, unit-tested)
96
- ├── tests/
97
- │ ├── parse.test.js # node:test unit tests for src/parse.js
98
- │ ├── i18n.test.js # node:test unit tests for src/i18n.js
99
- │ └── fold-smoke.test.js # end-to-end fold scan against a DOM shim (runs the real client bundle)
100
- ├── docs/
101
- │ ├── design.md # Design rationale (numbering, anchors, codec, i18n, chip ×, sent-message fold, draft-rebuild recovery)
102
- │ └── images/ # README mockups (PNG + editable SVG sources)
103
- ├── cordis.patch.yml # DSH bundle patch declaring the host plugin
104
- ├── package.json # Package + DSH plugin manifest
105
- ├── README.md # English
106
- └── README.zh-CN.md # 简体中文
107
- ```
108
-
109
- ## Development
110
-
111
- ```sh
112
- npm run check # syntax-check the JS halves
113
- npm test # run unit tests (node:test, 61 tests)
114
- ```
115
-
116
- ## License
117
-
118
- MIT — see [LICENSE](./LICENSE).
1
+ <div align="center">
2
+
3
+ # dsh-paste-code-block
4
+
5
+ **Cherry Studio‑style text/code block pasting for DeepSeek Harness Web**
6
+
7
+ Paste long code or text into the DSH Web composer → it lands as a **bordered, collapsible, language‑tagged card** instead of a wall of text. Names follow the DSH interface language (中文 / English). On send, the original content is restored as a fenced code block — and in the conversation it **stays folded** into click‑to‑expand cards, so your bubbles never become text walls again.
8
+
9
+ [![npm version](https://img.shields.io/npm/v/dsh-paste-code-block?logo=npm)](https://www.npmjs.com/package/dsh-paste-code-block)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
11
+ [![platform: web](https://img.shields.io/badge/platform-DSH%20Web-blueviolet)](https://github.com/deepseek-ai/deepseek-harness)
12
+
13
+ **English | [简体中文](./README.zh-CN.md)**
14
+
15
+ </div>
16
+
17
+ ![Preview — pasted blocks become tidy cards](./docs/images/hero.png)
18
+
19
+ ## Why
20
+
21
+ Copying a 200‑line stack trace, an API response, or a long log into a chat input turns the composer into an unreadable blob. This plugin folds any qualifying paste into a **chip** (built on DSH's own hidden‑reference mechanism, the same one file uploads use) plus an **editing detail card** — the draft stays clean, and the content stays fully editable and restorable.
22
+
23
+ ## Features
24
+
25
+ - 🧩 **Auto block detection** — pasted text with ``` fences, newlines, heavy indentation, or length ≥ 96 becomes a card; ordinary short prose pastes through untouched.
26
+ - 🏷️ **Language tags** — auto-detects Python / JS / JSON / YAML / SQL / bash / HTML·XML / C++ / Go / Ruby (incl. shebangs); plain-text blocks are tagged `text`.
27
+ - ✏️ **In-card editing** — edit the content right in the detail card; the edited text is exactly what gets sent. Plus copy, collapse/expand, and hide.
28
+ - 🈯 **Localized names** — chips are named in the current DSH language: `代码块 1` / `Code #1`, `文本块 N` / `Text #N`. A leading glyph and tint tells the two apart at a glance — `</>` blue for code, `Aa` gray for text. Switching **Settings → Language** live-retitles every chip.
29
+ - × **One-click remove** — every chip carries its own `×` delete button (the detail card has one too); a removed number is recycled immediately.
30
+ - 📤 **Fenced restore on send** — each card expands back into a ```` ```lang … ``` ```` block when you send; a failed send automatically refills the input.
31
+ - 📦 **Folded after send** — sent blocks keep folding in the transcript: every fenced block inside your own messages renders as a collapsed card (`python · 128 行` / `python · 128 lines`). Click the header to expand, again to collapse; the card's copy button grabs the original fenced text verbatim. Bare ```` ``` ```` fences fold as code (only an explicit ```` ```text ```` folds as a text block).
32
+ - 💾 **Mid-draft safe** — DSH persists a composer draft as plain text, so pasted blocks are automatically re-attached when the composer is rebuilt (workspace switch on the new-session page, page reload); hand-deleted blocks are never "resurrected".
33
+ - 🔢 **Smart numbering** — code and text count apart; the smallest free number is always reused.
34
+ - 📱 **Every surface** — pure client plugin; works on desktop & mobile web, follows light/dark themes.
35
+
36
+ ## How it works
37
+
38
+ ![Four steps: copy · paste · tidy · send](./docs/images/workflow.png)
39
+
40
+ ## Localization
41
+
42
+ Chip labels, tooltips, line counts, and the send-time error notice all render through the official DSH locale service: the plugin registers a `paste-code-block` dictionary namespace with complete **zh / en** key sets, and its composer dock declares that namespace, so everything re-renders on every language switch.
43
+
44
+ ![Block names follow the UI language](./docs/images/languages.png)
45
+
46
+ - **New pastes** are named in whatever language is active at paste time.
47
+ - **Existing chips** are re-titled live when you flip 设置 → 语言 / Settings → Language — no reload needed.
48
+ - Clicks and deletes match chips **across languages**: a `代码块 2` chip still resolves to its block after switching to English (where it now reads `Code #2`), and vice versa.
49
+
50
+ ## Install
51
+
52
+ Requires DSH `0.1.x` (developer preview — APIs may change). Published on **npm** — install by name:
53
+
54
+ ```sh
55
+ dsh plugin --profile web add dsh-paste-code-block
56
+ ```
57
+
58
+ Or from this repository / a local checkout:
59
+
60
+ ```sh
61
+ dsh plugin --profile web add github:cjm-m/dsh-paste-code-block # from GitHub
62
+ dsh plugin --profile web add file:/path/to/dsh-paste-code-block # from a local folder
63
+ ```
64
+
65
+ **Restart `dsh web`** after installing.
66
+
67
+ ## Usage
68
+
69
+ 1. Copy any code or multi-line text from anywhere.
70
+ 2. Paste into the DSH input → it collapses into a chip such as `代码块 1` / `Code #1`.
71
+ 3. Click the chip to open the card: read, edit inline, copy, collapse. Click the chip's (or the card's) `×` to delete that block.
72
+ 4. Send — the full original text goes out as a proper fenced code block.
73
+ 5. In the conversation it stays folded: each block sits in the bubble as a collapsed card — click the header to expand and read, click again to collapse.
74
+
75
+ Detection threshold: **contains a newline / ≥ 2 lines / length ≥ 96 / indented & brace-dense / fenced** — any one turns the paste into a block.
76
+
77
+ ## Notes & boundaries
78
+
79
+ - Blocks are **appended at the end of the draft** (reusing DSH's hidden-reference semantics), which keeps cursor/undo stable.
80
+ - Plain-text blocks are sent wrapped in ```` ```text ``` ```` so they never smear into one line.
81
+ - Removing a chip any other way (e.g. `Backspace`) also frees its number — plugin state is reconciled against the editor continuously.
82
+ - Deleting one block never touches the others, and removal is an ordinary editor edit — `Ctrl+Z` brings it back.
83
+ - Creating a block leaves **no stray space**: DSH appends a separating space after a freshly inserted chip, and the plugin removes exactly that one character, so text typed after a block does not start with a space and pasting several blocks never piles spaces into the message. Spaces you typed yourself are never touched by pasting or deleting.
84
+ - Post-send folding is **display-only**: it restyles your own message bubbles (and steering rows / the send echo) in the DOM. Stored messages are never modified, the bubble's own copy / edit / delete bar keeps working on the original text, and assistant messages are left alone.
85
+ - Draft-rebuild recovery keeps a small localStorage mirror (block payloads plus a draft fingerprint; written while you edit, cleared when you send, expired after two weeks). If the browser blocks local storage (private mode), blocks still survive a same-tab workspace switch from memory — just not a full page reload.
86
+
87
+ ## Project layout
88
+
89
+ ```
90
+ dsh-paste-code-block/
91
+ ├── src/
92
+ │ ├── client.js # Web (browser) half — paste capture, chips, detail card, × delete, sent-message fold, draft-rebuild recovery
93
+ │ ├── index.js # Host (node) half — intentionally empty (pure UI plugin)
94
+ │ ├── parse.js # Pure block-detection + fence-splitting logic (canonical, unit-tested)
95
+ │ └── i18n.js # Locale dictionaries, label & fold-title builders (canonical, unit-tested)
96
+ ├── tests/
97
+ │ ├── parse.test.js # node:test unit tests for src/parse.js
98
+ │ ├── i18n.test.js # node:test unit tests for src/i18n.js
99
+ │ └── fold-smoke.test.js # end-to-end fold scan against a DOM shim (runs the real client bundle)
100
+ ├── docs/
101
+ │ ├── design.md # Design rationale (numbering, anchors, codec, i18n, chip ×, sent-message fold, draft-rebuild recovery)
102
+ │ └── images/ # README mockups (PNG + editable SVG sources)
103
+ ├── cordis.patch.yml # DSH bundle patch declaring the host plugin
104
+ ├── package.json # Package + DSH plugin manifest
105
+ ├── README.md # English
106
+ └── README.zh-CN.md # 简体中文
107
+ ```
108
+
109
+ ## Development
110
+
111
+ ```sh
112
+ npm run check # syntax-check the JS halves
113
+ npm test # run unit tests (node:test, 61 tests)
114
+ ```
115
+
116
+ ## License
117
+
118
+ MIT — see [LICENSE](./LICENSE).
package/README.zh-CN.md CHANGED
@@ -1,118 +1,118 @@
1
- <div align="center">
2
-
3
- # dsh-paste-code-block
4
-
5
- **Cherry Studio 式的文本块/代码块粘贴效果(DeepSeek Harness Web)**
6
-
7
- 把复制的**长代码 / 长文本**粘到 DSH Web 输入框时,不再糊成一长串普通文字,而是收成一张**带边框、可折叠、带语言标签的卡片**;块名称自动跟随 DSH 界面语言(中文 / English);发送时自动还原成真正的 ```` ```lang … ``` ```` 围栏代码块——**发送后在对话里也保持折叠**,点击即可展开阅读。
8
-
9
- [![npm version](https://img.shields.io/npm/v/dsh-paste-code-block?logo=npm)](https://www.npmjs.com/package/dsh-paste-code-block)
10
- [![License: MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
11
- [![platform: web](https://img.shields.io/badge/platform-DSH%20Web-blueviolet)](https://github.com/deepseek-ai/deepseek-harness)
12
-
13
- **[English](./README.md) | 中文**
14
-
15
- </div>
16
-
17
- ![预览:粘贴的块自动收成整洁卡片](./docs/images/hero.png)
18
-
19
- ## 为什么需要它
20
-
21
- 往聊天输入框里粘贴 200 行报错栈、API 返回、长日志,输入框立刻变成一坨无法阅读的文字墙。本插件把符合特征的粘贴折叠成 **芯片(chip)**(复用 DSH 自带的隐藏引用机制,与文件上传同源)外加一张**可编辑详情卡**——草稿保持整洁,内容随时可读、可改、可还原。
22
-
23
- ## 功能
24
-
25
- - 🧩 **智能识别**:粘贴内容带 ``` 围栏、含换行、明显缩进、或长度 ≥ 96 → 收成卡片;普通短文本照常粘贴,绝不打扰。
26
- - 🏷️ **语言标签**:自动识别 Python / JS / JSON / YAML / SQL / bash / HTML·XML / C++ / Go / Ruby 等(可识别 shebang);纯文本块标为 `text`。
27
- - ✏️ **卡片内编辑**:详情卡里直接修改内容,发送的正是编辑后的文本;另有复制、折叠/展开、收起。
28
- - 🈯 **名称本地化**:芯片按当前 DSH 界面语言命名——`代码块 1` / `Code #1`、`文本块 N` / `Text #N`;前缀图标与配色一眼区分两类块(代码 `</>` 蓝色、文本 `Aa` 灰色);在「设置 → 语言」切换后所有芯片即时改名。
29
- - × **一键删除**:每个芯片自带 `×` 删除按钮(详情卡上也有);删掉的块编号立刻回收复用。
30
- - 📤 **发送还原**:发送时每个卡片展开还原为 ```` ```lang … ``` ```` 围栏代码块;发送失败自动回填输入框。
31
- - 📦 **发送后仍折叠**:发出去的消息在对话里继续折叠成卡片(如 `python · 128 行`),气泡不再变成文字墙;点标题展开、再点收起,卡片上的复制按钮原样复制带围栏的完整代码块。裸 ```` ``` ```` 围栏按代码块折叠(只有显式 ```` ```text ```` 才折叠为文本块)。
32
- - 💾 **草稿中途不丢**:DSH 只把输入框草稿按纯文本持久化,输入框被重建时(新会话页切换工作区、刷新页面)已粘贴的块会自动重新挂回草稿;手动删掉的块绝不会被“复活”。
33
- - 🔢 **智能编号**:代码与文本分开计数,永远分配最小可用号。
34
- - 📱 **全端适配**:纯客户端插件,PC 与手机 Web 通用,实时跟随深浅主题。
35
-
36
- ## 工作流
37
-
38
- ![四步:复制 · 粘贴 · 整理 · 发送](./docs/images/workflow.png)
39
-
40
- ## 名称本地化
41
-
42
- 芯片名称、按钮提示、行数、发送失效提示全部走 DSH 官方 locale 服务:插件注册自己的 `paste-code-block` 词典命名空间(zh / en 键集完全一致),输入坞声明该命名空间,因此切换语言时所有文案自动重渲染。
43
-
44
- ![块名称跟随界面语言](./docs/images/languages.png)
45
-
46
- - **新粘贴**的块按粘贴时的界面语言命名。
47
- - **已插入的芯片**在 设置 → 语言 切换后原地改名,无需刷新页面。
48
- - 点击与删除**跨语言匹配**:切到英文后,原来叫 `代码块 2` 的芯片(此时显示 `Code #2`)依然指向同一个块,反之亦然。
49
-
50
- ## 安装
51
-
52
- 需要 DSH `0.1.x`(开发者预览版,接口可能变化)。已发布到 **npm**,直接按包名安装:
53
-
54
- ```sh
55
- dsh plugin --profile web add dsh-paste-code-block
56
- ```
57
-
58
- 也可以从本仓库或本地目录安装:
59
-
60
- ```sh
61
- dsh plugin --profile web add github:cjm-m/dsh-paste-code-block # 从 GitHub
62
- dsh plugin --profile web add file:/path/to/dsh-paste-code-block # 从本地目录
63
- ```
64
-
65
- 安装后**重启 `dsh web`** 生效。
66
-
67
- ## 使用
68
-
69
- 1. 在任意地方复制一段代码 / 一段多行文本。
70
- 2. 在 DSH 输入框粘贴 → 折叠成 `代码块 1` 这样的芯片。
71
- 3. 点芯片打开详情卡:阅读、就地编辑、复制、折叠;点芯片(或卡片)上的 `×` 删除该块。
72
- 4. 发送——完整原文以围栏代码块形式发出。
73
- 5. 发送后对话里仍保持折叠:每个块在气泡中显示为一张卡片,点标题展开阅读、再点收起。
74
-
75
- 识别阈值:**含换行 / 行数 ≥ 2 / 长度 ≥ 96 / 缩进且符号密集 / 带围栏**,任一命中即成块。
76
-
77
- ## 说明与边界
78
-
79
- - 块一律**追加在草稿末尾**(复用 DSH 隐藏引用语义),光标与撤销保持稳定。
80
- - 纯文本块发送时用 ```` ```text ``` ```` 围栏包裹,不会在对话里糊成一行。
81
- - 用其他方式删除芯片(如 `Backspace`)同样会释放编号——插件状态与编辑器持续对账。
82
- - 删除单个块绝不影响其它块;删除是一次普通的编辑器编辑,可用 `Ctrl+Z` 撤销找回。
83
- - 创建块**不会残留空格**:DSH 会在新插入的芯片后自动补一个分隔空格,插件只把这一个字符删掉——因此块后面接着输入的文字不会顶着一个前导空格,连续粘贴多个块也不会在正文里堆出多余空格;你自己敲的空格在粘贴/删除时都不会被动到。
84
- - 发送后折叠**只是显示层**的改动:它只重排你自己消息(含插话与发送回显)气泡的 DOM,**不改任何存储的消息数据**;气泡自带的复制/编辑/删除操作照常作用于原文;助手消息完全不受影响。
85
- - 草稿恢复依赖一个小型 localStorage 镜像(只存块内容与草稿指纹;编辑时写入、发送即清、两周过期)。浏览器禁用本地存储(如隐身模式)时,同一页面内的工作区切换仍可从内存恢复,但整页刷新不能。
86
-
87
- ## 目录结构
88
-
89
- ```
90
- dsh-paste-code-block/
91
- ├── src/
92
- │ ├── client.js # Web(浏览器侧)—— 粘贴拦截、芯片、详情卡片、× 删除、发送后折叠、草稿恢复
93
- │ ├── index.js # Host(Node 侧)—— 有意为空(纯 UI 插件)
94
- │ ├── parse.js # 纯块识别 + 围栏切分逻辑(规范版,含单元测试)
95
- │ └── i18n.js # 词典、块名称与折叠卡标题(规范版,含单元测试)
96
- ├── tests/
97
- │ ├── parse.test.js # node:test 单元测试(src/parse.js)
98
- │ ├── i18n.test.js # node:test 单元测试(src/i18n.js)
99
- │ └── fold-smoke.test.js # 用 DOM 垫片端到端跑真实 client.js:折叠扫描 + 草稿恢复
100
- ├── docs/
101
- │ ├── design.md # 设计说明(编号复用、锚点稳定、codec、i18n、芯片 ×、发送后折叠)
102
- │ └── images/ # README 示意图(PNG + 可编辑 SVG 源)
103
- ├── cordis.patch.yml # DSH bundle patch,声明宿主插件
104
- ├── package.json # 包与 DSH 插件清单
105
- ├── README.md # English
106
- └── README.zh-CN.md # 简体中文
107
- ```
108
-
109
- ## 开发
110
-
111
- ```sh
112
- npm run check # 语法检查 JS 半端
113
- npm test # 运行单元测试(node:test,61 项)
114
- ```
115
-
116
- ## License
117
-
118
- MIT — 见 [LICENSE](./LICENSE)。
1
+ <div align="center">
2
+
3
+ # dsh-paste-code-block
4
+
5
+ **Cherry Studio 式的文本块/代码块粘贴效果(DeepSeek Harness Web)**
6
+
7
+ 把复制的**长代码 / 长文本**粘到 DSH Web 输入框时,不再糊成一长串普通文字,而是收成一张**带边框、可折叠、带语言标签的卡片**;块名称自动跟随 DSH 界面语言(中文 / English);发送时自动还原成真正的 ```` ```lang … ``` ```` 围栏代码块——**发送后在对话里也保持折叠**,点击即可展开阅读。
8
+
9
+ [![npm version](https://img.shields.io/npm/v/dsh-paste-code-block?logo=npm)](https://www.npmjs.com/package/dsh-paste-code-block)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](./LICENSE)
11
+ [![platform: web](https://img.shields.io/badge/platform-DSH%20Web-blueviolet)](https://github.com/deepseek-ai/deepseek-harness)
12
+
13
+ **[English](./README.md) | 中文**
14
+
15
+ </div>
16
+
17
+ ![预览:粘贴的块自动收成整洁卡片](./docs/images/hero.png)
18
+
19
+ ## 为什么需要它
20
+
21
+ 往聊天输入框里粘贴 200 行报错栈、API 返回、长日志,输入框立刻变成一坨无法阅读的文字墙。本插件把符合特征的粘贴折叠成 **芯片(chip)**(复用 DSH 自带的隐藏引用机制,与文件上传同源)外加一张**可编辑详情卡**——草稿保持整洁,内容随时可读、可改、可还原。
22
+
23
+ ## 功能
24
+
25
+ - 🧩 **智能识别**:粘贴内容带 ``` 围栏、含换行、明显缩进、或长度 ≥ 96 → 收成卡片;普通短文本照常粘贴,绝不打扰。
26
+ - 🏷️ **语言标签**:自动识别 Python / JS / JSON / YAML / SQL / bash / HTML·XML / C++ / Go / Ruby 等(可识别 shebang);纯文本块标为 `text`。
27
+ - ✏️ **卡片内编辑**:详情卡里直接修改内容,发送的正是编辑后的文本;另有复制、折叠/展开、收起。
28
+ - 🈯 **名称本地化**:芯片按当前 DSH 界面语言命名——`代码块 1` / `Code #1`、`文本块 N` / `Text #N`;前缀图标与配色一眼区分两类块(代码 `</>` 蓝色、文本 `Aa` 灰色);在「设置 → 语言」切换后所有芯片即时改名。
29
+ - × **一键删除**:每个芯片自带 `×` 删除按钮(详情卡上也有);删掉的块编号立刻回收复用。
30
+ - 📤 **发送还原**:发送时每个卡片展开还原为 ```` ```lang … ``` ```` 围栏代码块;发送失败自动回填输入框。
31
+ - 📦 **发送后仍折叠**:发出去的消息在对话里继续折叠成卡片(如 `python · 128 行`),气泡不再变成文字墙;点标题展开、再点收起,卡片上的复制按钮原样复制带围栏的完整代码块。裸 ```` ``` ```` 围栏按代码块折叠(只有显式 ```` ```text ```` 才折叠为文本块)。
32
+ - 💾 **草稿中途不丢**:DSH 只把输入框草稿按纯文本持久化,输入框被重建时(新会话页切换工作区、刷新页面)已粘贴的块会自动重新挂回草稿;手动删掉的块绝不会被“复活”。
33
+ - 🔢 **智能编号**:代码与文本分开计数,永远分配最小可用号。
34
+ - 📱 **全端适配**:纯客户端插件,PC 与手机 Web 通用,实时跟随深浅主题。
35
+
36
+ ## 工作流
37
+
38
+ ![四步:复制 · 粘贴 · 整理 · 发送](./docs/images/workflow.png)
39
+
40
+ ## 名称本地化
41
+
42
+ 芯片名称、按钮提示、行数、发送失效提示全部走 DSH 官方 locale 服务:插件注册自己的 `paste-code-block` 词典命名空间(zh / en 键集完全一致),输入坞声明该命名空间,因此切换语言时所有文案自动重渲染。
43
+
44
+ ![块名称跟随界面语言](./docs/images/languages.png)
45
+
46
+ - **新粘贴**的块按粘贴时的界面语言命名。
47
+ - **已插入的芯片**在 设置 → 语言 切换后原地改名,无需刷新页面。
48
+ - 点击与删除**跨语言匹配**:切到英文后,原来叫 `代码块 2` 的芯片(此时显示 `Code #2`)依然指向同一个块,反之亦然。
49
+
50
+ ## 安装
51
+
52
+ 需要 DSH `0.1.x`(开发者预览版,接口可能变化)。已发布到 **npm**,直接按包名安装:
53
+
54
+ ```sh
55
+ dsh plugin --profile web add dsh-paste-code-block
56
+ ```
57
+
58
+ 也可以从本仓库或本地目录安装:
59
+
60
+ ```sh
61
+ dsh plugin --profile web add github:cjm-m/dsh-paste-code-block # 从 GitHub
62
+ dsh plugin --profile web add file:/path/to/dsh-paste-code-block # 从本地目录
63
+ ```
64
+
65
+ 安装后**重启 `dsh web`** 生效。
66
+
67
+ ## 使用
68
+
69
+ 1. 在任意地方复制一段代码 / 一段多行文本。
70
+ 2. 在 DSH 输入框粘贴 → 折叠成 `代码块 1` 这样的芯片。
71
+ 3. 点芯片打开详情卡:阅读、就地编辑、复制、折叠;点芯片(或卡片)上的 `×` 删除该块。
72
+ 4. 发送——完整原文以围栏代码块形式发出。
73
+ 5. 发送后对话里仍保持折叠:每个块在气泡中显示为一张卡片,点标题展开阅读、再点收起。
74
+
75
+ 识别阈值:**含换行 / 行数 ≥ 2 / 长度 ≥ 96 / 缩进且符号密集 / 带围栏**,任一命中即成块。
76
+
77
+ ## 说明与边界
78
+
79
+ - 块一律**追加在草稿末尾**(复用 DSH 隐藏引用语义),光标与撤销保持稳定。
80
+ - 纯文本块发送时用 ```` ```text ``` ```` 围栏包裹,不会在对话里糊成一行。
81
+ - 用其他方式删除芯片(如 `Backspace`)同样会释放编号——插件状态与编辑器持续对账。
82
+ - 删除单个块绝不影响其它块;删除是一次普通的编辑器编辑,可用 `Ctrl+Z` 撤销找回。
83
+ - 创建块**不会残留空格**:DSH 会在新插入的芯片后自动补一个分隔空格,插件只把这一个字符删掉——因此块后面接着输入的文字不会顶着一个前导空格,连续粘贴多个块也不会在正文里堆出多余空格;你自己敲的空格在粘贴/删除时都不会被动到。
84
+ - 发送后折叠**只是显示层**的改动:它只重排你自己消息(含插话与发送回显)气泡的 DOM,**不改任何存储的消息数据**;气泡自带的复制/编辑/删除操作照常作用于原文;助手消息完全不受影响。
85
+ - 草稿恢复依赖一个小型 localStorage 镜像(只存块内容与草稿指纹;编辑时写入、发送即清、两周过期)。浏览器禁用本地存储(如隐身模式)时,同一页面内的工作区切换仍可从内存恢复,但整页刷新不能。
86
+
87
+ ## 目录结构
88
+
89
+ ```
90
+ dsh-paste-code-block/
91
+ ├── src/
92
+ │ ├── client.js # Web(浏览器侧)—— 粘贴拦截、芯片、详情卡片、× 删除、发送后折叠、草稿恢复
93
+ │ ├── index.js # Host(Node 侧)—— 有意为空(纯 UI 插件)
94
+ │ ├── parse.js # 纯块识别 + 围栏切分逻辑(规范版,含单元测试)
95
+ │ └── i18n.js # 词典、块名称与折叠卡标题(规范版,含单元测试)
96
+ ├── tests/
97
+ │ ├── parse.test.js # node:test 单元测试(src/parse.js)
98
+ │ ├── i18n.test.js # node:test 单元测试(src/i18n.js)
99
+ │ └── fold-smoke.test.js # 用 DOM 垫片端到端跑真实 client.js:折叠扫描 + 草稿恢复
100
+ ├── docs/
101
+ │ ├── design.md # 设计说明(编号复用、锚点稳定、codec、i18n、芯片 ×、发送后折叠)
102
+ │ └── images/ # README 示意图(PNG + 可编辑 SVG 源)
103
+ ├── cordis.patch.yml # DSH bundle patch,声明宿主插件
104
+ ├── package.json # 包与 DSH 插件清单
105
+ ├── README.md # English
106
+ └── README.zh-CN.md # 简体中文
107
+ ```
108
+
109
+ ## 开发
110
+
111
+ ```sh
112
+ npm run check # 语法检查 JS 半端
113
+ npm test # 运行单元测试(node:test,61 项)
114
+ ```
115
+
116
+ ## License
117
+
118
+ MIT — 见 [LICENSE](./LICENSE)。
package/cordis.patch.yml CHANGED
@@ -1,4 +1,4 @@
1
- # Install the Host half and expose the same package's dsh.client Web half.
2
- - insert:
3
- - id: dsh-paste-code-block
4
- name: dsh-paste-code-block
1
+ # Install the Host half and expose the same package's dsh.client Web half.
2
+ - insert:
3
+ - id: dsh-paste-code-block
4
+ name: dsh-paste-code-block