dsh-text-rinse 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +56 -2
- package/cordis.patch.yml +4 -0
- package/lib/index.js +164 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lianglushuang
|
|
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,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 洗净 / Text Rinse
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A small native plugin for **DSH Go**: clean text copied from web pages, PDFs and chat logs.
|
|
4
|
+
|
|
5
|
+
DSH Go 手机 App 的原生小插件:把从网页、PDF、聊天记录里复制来的脏文本洗干净。
|
|
6
|
+
|
|
7
|
+
## 它洗什么 / What it cleans
|
|
8
|
+
|
|
9
|
+
| 规则 | 说明 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| 零宽字符 | U+00AD 软连字符、U+200B–U+200D、U+2060、U+FEFF |
|
|
12
|
+
| 空白 | 行尾空格、制表符、全角空格 U+3000 |
|
|
13
|
+
| 空行 | 三个以上连续换行压成一个 |
|
|
14
|
+
| 中文空格 | 汉字之间的多余空格、中文标点前后的空格 |
|
|
15
|
+
| 换行符 | CRLF / CR 统一成 LF |
|
|
16
|
+
|
|
17
|
+
## 怎么用 / Usage
|
|
18
|
+
|
|
19
|
+
1. 复制一段脏文字。
|
|
20
|
+
2. 点输入框上方的 **洗净剪贴板**。
|
|
21
|
+
3. 洗好的结果自动放回剪贴板,直接粘贴。
|
|
22
|
+
|
|
23
|
+
面板在「对话详情 › 插件」和「全部功能」里,说明它具体做什么。
|
|
24
|
+
|
|
25
|
+
## 数据 / Privacy
|
|
26
|
+
|
|
27
|
+
- 只在你点按的那一下读一次剪贴板,读完即用,不保存。
|
|
28
|
+
- 不联网,不写文件,不起子进程。
|
|
29
|
+
- 超过 8000 字只放回前 8000 字(桥接协议的上限)。
|
|
30
|
+
|
|
31
|
+
## 安装 / Install
|
|
32
|
+
|
|
33
|
+
从 App 的「设置 › 插件 › 插件市场」搜索 **洗净 / dsh-text-rinse** 安装。
|
|
34
|
+
|
|
35
|
+
或者命令行:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
dsh plugin --profile web add dsh-text-rinse
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
装了即生效;改代码后要在「引擎」页重启引擎。
|
|
42
|
+
|
|
43
|
+
## 卸载 / Uninstall
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
dsh plugin --profile web remove dsh-text-rinse
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## 兼容 / Compatibility
|
|
50
|
+
|
|
51
|
+
- Node.js 22.19 或更新
|
|
52
|
+
- DSH `>=0.2.1-rc.2 <0.3.0-0`
|
|
53
|
+
- 原生界面需要主机带 dsh-go 桥接(本机引擎自带;远程主机没有桥接时插件照常加载,只是不显示胶囊和面板)
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT
|
package/cordis.patch.yml
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// 洗净 —— 把从网页、PDF、聊天记录里复制来的脏文本洗干净。
|
|
2
|
+
// 只在用户点按时读剪贴板,结果复制回剪贴板;不联网、不写文件、不起子进程。
|
|
3
|
+
|
|
4
|
+
export const name = 'dsh-text-rinse'
|
|
5
|
+
|
|
6
|
+
// ── 清理规则 ──
|
|
7
|
+
// 顺序有讲究:先做不改变可见字符的(零宽、空白),再做排版级的(合并空行、拼回中文)。
|
|
8
|
+
|
|
9
|
+
const ZERO_WIDTH = /[\u00AD\u200B-\u200D\u2060\uFEFF]/g
|
|
10
|
+
const FULLWIDTH_SPACE = /\u3000/g
|
|
11
|
+
const TRAILING_SPACE = /[ \t]+$/gm
|
|
12
|
+
const LEADING_SPACE = /^[ \t]+/gm
|
|
13
|
+
// 中文(含全角标点)之间的空格:PDF 和网页复制最常见。
|
|
14
|
+
const CJK = '\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\u3000-\u303F\uFF00-\uFFEF'
|
|
15
|
+
const CJK_GAP = new RegExp(`([${CJK}])[ \\t]+([${CJK}])`, 'g')
|
|
16
|
+
// 中文紧挨着半角标点/数字时,前面的全角空格已处理过,这里只处理中文之间。
|
|
17
|
+
const SPACE_BEFORE_PUNCT = /[ \t]+([,。、;:?!)》」』】”’])/g
|
|
18
|
+
const SPACE_AFTER_PUNCT = /([(《「『【“‘])[ \t]+/g
|
|
19
|
+
// 三个以上连续换行压成两个(保留段落)。
|
|
20
|
+
const MANY_BLANK_LINES = /\n{3,}/g
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 洗一段文本。
|
|
24
|
+
* @param {string} input
|
|
25
|
+
* @returns {{ text: string, report: string[], changed: number }}
|
|
26
|
+
*/
|
|
27
|
+
export function rinse(input) {
|
|
28
|
+
const original = String(input ?? '')
|
|
29
|
+
if (original.trim() === '') return { text: '', report: [], changed: 0 }
|
|
30
|
+
|
|
31
|
+
let text = original
|
|
32
|
+
let changed = 0
|
|
33
|
+
|
|
34
|
+
// 1. 统一换行符
|
|
35
|
+
const unified = text.replace(/\r\n?/g, '\n')
|
|
36
|
+
if (unified !== text) { changed += 1; text = unified }
|
|
37
|
+
|
|
38
|
+
// 2. 零宽字符与软连字符
|
|
39
|
+
let zeroWidth = 0
|
|
40
|
+
text = text.replace(ZERO_WIDTH, () => { zeroWidth += 1; return '' })
|
|
41
|
+
if (zeroWidth > 0) changed += 1
|
|
42
|
+
|
|
43
|
+
// 3. 全角空格 → 半角
|
|
44
|
+
let fullSpace = 0
|
|
45
|
+
text = text.replace(FULLWIDTH_SPACE, () => { fullSpace += 1; return ' ' })
|
|
46
|
+
if (fullSpace > 0) changed += 1
|
|
47
|
+
|
|
48
|
+
// 4. 行尾、行首空白
|
|
49
|
+
const beforeTrim = text
|
|
50
|
+
text = text.replace(TRAILING_SPACE, '').replace(LEADING_SPACE, '')
|
|
51
|
+
if (text !== beforeTrim) changed += 1
|
|
52
|
+
|
|
53
|
+
// 5. 中文之间的多余空格(中文换行不需要空格,这句只管同一行内)
|
|
54
|
+
let cjkGaps = 0
|
|
55
|
+
let prev = ''
|
|
56
|
+
while (prev !== text) {
|
|
57
|
+
prev = text
|
|
58
|
+
text = text.replace(CJK_GAP, (m, a, b) => { cjkGaps += 1; return a + b })
|
|
59
|
+
}
|
|
60
|
+
if (cjkGaps > 0) changed += 1
|
|
61
|
+
|
|
62
|
+
// 6. 标点前后的空格
|
|
63
|
+
const beforePunct = text
|
|
64
|
+
text = text.replace(SPACE_BEFORE_PUNCT, '$1').replace(SPACE_AFTER_PUNCT, '$1')
|
|
65
|
+
if (text !== beforePunct) changed += 1
|
|
66
|
+
|
|
67
|
+
// 7. 连续空行
|
|
68
|
+
let blankRuns = 0
|
|
69
|
+
prev = ''
|
|
70
|
+
while (prev !== text) {
|
|
71
|
+
prev = text
|
|
72
|
+
text = text.replace(MANY_BLANK_LINES, () => { blankRuns += 1; return '\n\n' })
|
|
73
|
+
}
|
|
74
|
+
if (blankRuns > 0) changed += 1
|
|
75
|
+
|
|
76
|
+
// 8. 首尾空白
|
|
77
|
+
text = text.trim()
|
|
78
|
+
|
|
79
|
+
// 收拾报告:只报真正发生的
|
|
80
|
+
const report = []
|
|
81
|
+
if (zeroWidth > 0) report.push(zh(`零宽字符 ×${zeroWidth}`))
|
|
82
|
+
if (fullSpace > 0) report.push(zh(`全角空格 ×${fullSpace}`))
|
|
83
|
+
if (blankRuns > 0) report.push(zh(`空行 ×${blankRuns}`))
|
|
84
|
+
if (cjkGaps > 0) report.push(zh(`中文空格 ×${cjkGaps}`))
|
|
85
|
+
|
|
86
|
+
return { text, report, changed }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function zh(s) { return s }
|
|
90
|
+
|
|
91
|
+
function bytes(s) { return Buffer.byteLength(s, 'utf8') }
|
|
92
|
+
|
|
93
|
+
export function apply(ctx) {
|
|
94
|
+
ctx.inject(['dshGo'], (ctx) => {
|
|
95
|
+
// 输入框上方的胶囊:洗剪贴板,洗完放回剪贴板,不碰输入框
|
|
96
|
+
ctx.dshGo.on('rinse-clip', (scope, event) => {
|
|
97
|
+
const en = String(event?.locale ?? '').startsWith('en')
|
|
98
|
+
const raw = String(scope?.clipboard ?? '')
|
|
99
|
+
if (raw.trim() === '') {
|
|
100
|
+
return { toast: en ? 'The clipboard is empty' : '剪贴板里没字,洗什么' }
|
|
101
|
+
}
|
|
102
|
+
const { text, report } = rinse(raw)
|
|
103
|
+
if (text === raw) {
|
|
104
|
+
return { toast: en ? 'Already clean' : '本来就干净,没动' }
|
|
105
|
+
}
|
|
106
|
+
if (text === '') {
|
|
107
|
+
return { toast: en ? 'Only whitespace left; nothing copied' : '洗完什么都不剩,没复制' }
|
|
108
|
+
}
|
|
109
|
+
const clipped = text.slice(0, 8000)
|
|
110
|
+
const head = en ? 'Rinsed' : '洗好了'
|
|
111
|
+
const tail = report.length
|
|
112
|
+
? (en ? ': ' + report.join(', ') : ':' + report.join('、'))
|
|
113
|
+
: ''
|
|
114
|
+
return { copy: clipped, toast: (head + tail).slice(0, 40) }
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// 面板:说明它洗什么、留多长
|
|
118
|
+
ctx.dshGo.panel('rinse', {
|
|
119
|
+
view: (scope, caps) => {
|
|
120
|
+
const en = String(caps?.locale ?? '').startsWith('en')
|
|
121
|
+
return {
|
|
122
|
+
type: 'stack',
|
|
123
|
+
title: en ? 'Text Rinse' : '洗净',
|
|
124
|
+
children: [
|
|
125
|
+
{
|
|
126
|
+
type: 'text',
|
|
127
|
+
tone: 'muted',
|
|
128
|
+
text: en
|
|
129
|
+
? 'Copy text from a web page, a PDF or a chat log, then tap “Rinse clip”. It cleans the copy and puts the result back on the clipboard.'
|
|
130
|
+
: '从网页、PDF、聊天记录里复制一段文字,点输入框上方的「洗净剪贴板」。洗好的结果会放回剪贴板,你直接粘贴就行。',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: 'list',
|
|
134
|
+
items: en
|
|
135
|
+
? [
|
|
136
|
+
{ title: 'Zero-width marks', subtitle: 'U+200B…U+200D, U+FEFF, soft hyphens' },
|
|
137
|
+
{ title: 'Whitespace', subtitle: 'Trailing spaces, tabs, full-width spaces' },
|
|
138
|
+
{ title: 'Blank lines', subtitle: 'Three or more collapse to one' },
|
|
139
|
+
{ title: 'Chinese spacing', subtitle: 'Spaces between Chinese characters and around CJK punctuation' },
|
|
140
|
+
]
|
|
141
|
+
: [
|
|
142
|
+
{ title: '零宽字符', subtitle: 'U+200B…U+200D、U+FEFF、软连字符' },
|
|
143
|
+
{ title: '空白', subtitle: '行尾空格、制表符、全角空格' },
|
|
144
|
+
{ title: '空行', subtitle: '三个以上压成一个' },
|
|
145
|
+
{ title: '中文空格', subtitle: '汉字之间、中文标点前后的多余空格' },
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
type: 'callout',
|
|
150
|
+
tone: 'info',
|
|
151
|
+
text: en
|
|
152
|
+
? 'It never sends the text anywhere and never writes a file. Only the first 8000 characters are copied back.'
|
|
153
|
+
: '不联网、不存文件,只在点按时读一次剪贴板。超过 8000 字只放回前 8000 字。',
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
data: (scope, emit) => {
|
|
159
|
+
emit({})
|
|
160
|
+
return () => {}
|
|
161
|
+
},
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-text-rinse",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Clean text copied from web pages, PDFs and chat logs: zero-width marks, edge whitespace, redundant blank lines and hard line breaks inside Chinese.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./lib/index.js",
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
"./cordis.patch.yml": "./cordis.patch.yml"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib",
|
|
14
|
+
"cordis.patch.yml",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.19",
|
|
21
|
+
"dsh": ">=0.2.1-rc.2 <0.3.0-0"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"dsh-plugin",
|
|
25
|
+
"dsh-bundle",
|
|
26
|
+
"dsh-go",
|
|
27
|
+
"clipboard",
|
|
28
|
+
"text",
|
|
29
|
+
"cleanup"
|
|
30
|
+
],
|
|
31
|
+
"dsh": {
|
|
32
|
+
"bundle": {
|
|
33
|
+
"patch": "./cordis.patch.yml"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"dshGo": {
|
|
37
|
+
"v": 1,
|
|
38
|
+
"title": {
|
|
39
|
+
"zh": "洗净",
|
|
40
|
+
"en": "Text Rinse"
|
|
41
|
+
},
|
|
42
|
+
"icon": "sparkle",
|
|
43
|
+
"wants": [
|
|
44
|
+
"clipboard"
|
|
45
|
+
],
|
|
46
|
+
"contributes": {
|
|
47
|
+
"composer.actions": [
|
|
48
|
+
{
|
|
49
|
+
"id": "rinse-clip",
|
|
50
|
+
"label": {
|
|
51
|
+
"zh": "洗净剪贴板",
|
|
52
|
+
"en": "Rinse clip"
|
|
53
|
+
},
|
|
54
|
+
"icon": "sparkle"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"panels": [
|
|
58
|
+
{
|
|
59
|
+
"id": "rinse",
|
|
60
|
+
"title": {
|
|
61
|
+
"zh": "洗净",
|
|
62
|
+
"en": "Text Rinse"
|
|
63
|
+
},
|
|
64
|
+
"icon": "sparkle",
|
|
65
|
+
"placement": [
|
|
66
|
+
"session.tab",
|
|
67
|
+
"features"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|