@jianghuifr/dsh-highlight 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 jianghui
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,75 @@
1
- # Temporary Holding Version
1
+ # @jianghuifr/dsh-highlight
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/jianghuifr/dsh-highlight/actions/workflows/ci.yml/badge.svg)](https://github.com/jianghuifr/dsh-highlight/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@jianghuifr/dsh-highlight.svg)](https://www.npmjs.com/package/@jianghuifr/dsh-highlight)
5
+
6
+ A syntax-highlighted code preview for the shell dotfiles the DeepSeek Harness Web UI would otherwise show as plain text (.bashrc, .gitconfig, …).
7
+
8
+ 属于同一插件拆分出的三个独立包之一:[icons](https://github.com/jianghuifr/dsh-material-icon-theme-icon) · [dotfile highlight](https://github.com/jianghuifr/dsh-highlight) · [UI optimize](https://github.com/jianghuifr/dsh-ui-optimize)。
9
+
10
+ ## 功能
11
+
12
+ 官方预览按文件后缀表决定语言,`.bashrc`、`.zshrc`、`.gitconfig` 这类 dotfile 没有表项,会落到纯文本。本插件以外部优先级(`priority: 'extension'`)认领 **47 个精选后缀**,用官方基线 `CodeBlock` 渲染带行号、复制、换行按钮的代码视图。
13
+
14
+ ![dotfile 代码预览](docs/syntax-preview.png)
15
+
16
+ 语言判定 = 名字表 + 内容探测:`bashrc/zshrc/… → shellscript`、`gitconfig/npmrc/editorconfig → ini`、`latexmkrc → perl`;未命中时探测 shebang、JSON、INI 段头、YAML、`KEY=value`;都不中则无颜色但保留行号与复制(如 `.vimrc`)。
17
+
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ # 发布到 npm 之后
23
+ plugin_manager install_bundle target=@jianghuifr/dsh-highlight
24
+ ```
25
+
26
+ 本地开发也可直接 link 本目录(或在 Plugins → Add plugin 选择本目录):
27
+
28
+ ```bash
29
+ plugin_manager install_bundle target=<本仓库绝对路径>
30
+ ```
31
+
32
+ ## 设置页
33
+
34
+ **Plugins → Installed plugins → 本插件详情 → Components → `dotfile 代码高亮 ›`**
35
+
36
+ ![设置页](docs/settings.png)
37
+
38
+ 开关存在浏览器 `localStorage`,切换立即生效、刷新后保持;会从旧合并版 `dsh-material-icon-theme` 的共享 key 迁移一次。
39
+
40
+ ## 开发
41
+
42
+ ```bash
43
+ npm ci
44
+ npm run verify # check + eslint + node --test
45
+ npm test
46
+ npm run check
47
+ ```
48
+
49
+ 零 npm 运行时依赖(仅 eslint 作为开发依赖),`lib/client.js` 是手写经典脚本、无构建步骤。
50
+
51
+ 仓库结构:
52
+
53
+ ```
54
+ lib/index.js # 宿主半边
55
+ lib/client.js # 客户端半边(经典脚本 bundle)
56
+ locale/ # en/zh 插件页 meta
57
+ test/ # node --test
58
+ scripts/check.mjs # 自检
59
+ .github/workflows/ # CI + Release
60
+ docs/ # README 截图
61
+ ```
62
+
63
+ ## 发版
64
+
65
+ 见 [docs/release.md](docs/release.md):staged publishing + trusted publishing,CI 只暂存,维护者用 2FA 批准后上线。
66
+
67
+ ## 已知边界
68
+
69
+ 1. 无点文件名(`Dockerfile`/`Makefile`/`Jenkinsfile`)无法被预览注册表认领,需要上游改。
70
+ 2. 只认领 47 个精选后缀。
71
+ 3. dotfile 默认被 Files 面板过滤(隐藏文件),需通过 `@` 引用或文件链接打开。
72
+
73
+ ## 许可
74
+
75
+ MIT,见 [LICENSE](LICENSE)。
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-highlight
3
+ name: '@jianghuifr/dsh-highlight'
@@ -0,0 +1,42 @@
1
+ # 发版
2
+
3
+ 发布走 **staged publishing + trusted publishing**:CI 只把版本暂存到 npm 的 stage 队列,
4
+ 维护者用 2FA 批准后才真正上线。全程不需要任何长期 token。
5
+
6
+ ## 一次性准备
7
+
8
+ 1. **npm 账号开启 2FA。** staged publishing 的批准步骤依赖它。
9
+ 2. **包必须先存在于 registry。** `npm stage` 不支持全新包 —— 首次发布只能手工:
10
+
11
+ ```bash
12
+ npm login --registry https://registry.npmjs.org
13
+ npm publish --registry https://registry.npmjs.org --access public
14
+ ```
15
+
16
+ 之后 `release.yml` 才能接管后续版本。
17
+ 3. **配置 trusted publisher。** npmjs.com → 包页面 → Settings → Trusted Publisher:
18
+ 填本仓库(`jianghuifr/dsh-highlight`)、workflow 文件名 `release.yml`,
19
+ 并把权限限制为 **stage-only**。这一步让 CI 用 OIDC 换凭据,无需 `NPM_TOKEN`。
20
+
21
+ ## 每个版本
22
+
23
+ ```bash
24
+ npm version patch # 或 minor / major
25
+ git push --follow-tags
26
+ ```
27
+
28
+ 打上 `v*` 标签触发 `release.yml`:
29
+
30
+ 1. 校验标签与 `package.json` 的版本一致(不一致直接失败);
31
+ 2. 跑 `npm run verify`(bundle 完整性检查 + eslint + node --test);
32
+ 3. 若 registry 上还没有这个版本,`npm stage publish` 把它暂存;
33
+ 4. 建一个 GitHub Release。
34
+
35
+ ## 批准
36
+
37
+ 暂存**不等于发布**,对公众不可见。用 2FA 批准:
38
+
39
+ - 网页:npmjs.com → 账号 → **Staged Packages** → Approve
40
+ - CLI:`npm stage list` 拿 stage id → `npm stage approve <stage-id>`
41
+
42
+ 批准后 `https://www.npmjs.com/package/@jianghuifr/dsh-highlight` 才会更新。
Binary file
Binary file
package/icon.svg ADDED
@@ -0,0 +1,6 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="Dotfile code preview">
2
+ <rect x="10" y="5" width="44" height="54" rx="9" fill="#1e3a5f"/>
3
+ <path d="M27 20l-8 10 8 10" fill="none" stroke="#7fdbca" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M37 20l8 10-8 10" fill="none" stroke="#7fdbca" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <rect x="18" y="47" width="28" height="4" rx="2" fill="#facc15"/>
6
+ </svg>
package/lib/client.js ADDED
@@ -0,0 +1,465 @@
1
+ /**
2
+ * `@jianghuifr/dsh-highlight` — Web client half.
3
+ *
4
+ * The shipped code preview decides its language from a file-extension table, so
5
+ * dotfiles such as `.bashrc` fall through to plain text. This plugin claims a
6
+ * curated set of dotfile suffixes at the external (`extension`) priority and
7
+ * renders them through the shipped CodeBlock baseline, deciding the language
8
+ * from the suffix name plus a small content probe.
9
+ *
10
+ * The `syntaxExtras` switch registers or disposes that preview definition; the
11
+ * body slot stays registered for the plugin's lifetime.
12
+ */
13
+ window.__ModuleLoader__.load({
14
+ id: '@jianghuifr/dsh-highlight',
15
+ factory(require) {
16
+ 'use strict'
17
+
18
+ const React = require('react')
19
+ const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
20
+ const CodeBlock = primitives.CodeBlock
21
+ const h = React.createElement
22
+
23
+ // -----------------------------------------------------------------------
24
+ // Identity and constants
25
+ // -----------------------------------------------------------------------
26
+
27
+ const ROW_ID = 'dsh-highlight'
28
+ const ROW_CONFIG_KEY = '@jianghuifr/dsh-highlight#' + ROW_ID
29
+ const LOCALE_NS = 'dshMaterialIconThemeHighlight'
30
+ const PREVIEW_ID = '@jianghuifr/dsh-highlight/dotfile-code'
31
+ const STORAGE_KEY = '@jianghuifr/dsh-highlight:features'
32
+ /** Keys tried when this package's own key is absent: the previous split name, then the merged plugin. */
33
+ const LEGACY_STORAGE_KEYS = [
34
+ '@jianghuifr/dsh-material-icon-theme-highlight:features',
35
+ 'dsh-material-icon-theme:features',
36
+ ]
37
+ const FEATURE_KEYS = ['syntaxExtras']
38
+
39
+ const DEFAULT_FEATURES = Object.freeze({ syntaxExtras: true })
40
+
41
+ // -----------------------------------------------------------------------
42
+ // Feature store (localStorage, shared by the settings page and runtime)
43
+ // -----------------------------------------------------------------------
44
+
45
+ let features = null
46
+ const featureListeners = new Set()
47
+
48
+ function readOwnFeatures() {
49
+ const next = { ...DEFAULT_FEATURES }
50
+ try {
51
+ const raw = window.localStorage.getItem(STORAGE_KEY)
52
+ if (raw !== null) {
53
+ const parsed = JSON.parse(raw)
54
+ if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
55
+ for (const key of FEATURE_KEYS) {
56
+ if (typeof parsed[key] === 'boolean') next[key] = parsed[key]
57
+ }
58
+ }
59
+ return next
60
+ }
61
+ for (const legacyKey of LEGACY_STORAGE_KEYS) {
62
+ const legacy = window.localStorage.getItem(legacyKey)
63
+ if (legacy === null) continue
64
+ try {
65
+ const parsed = JSON.parse(legacy)
66
+ if (parsed !== null && typeof parsed === 'object' && typeof parsed.syntaxExtras === 'boolean') {
67
+ next.syntaxExtras = parsed.syntaxExtras
68
+ break
69
+ }
70
+ } catch {
71
+ // Skip a corrupt legacy value and try the next key.
72
+ }
73
+ }
74
+ } catch {
75
+ // A corrupt or blocked store falls back to the defaults.
76
+ }
77
+ return next
78
+ }
79
+
80
+ function getFeatures() {
81
+ if (features === null) features = Object.freeze(readOwnFeatures())
82
+ return features
83
+ }
84
+
85
+ function subscribeFeatures(listener) {
86
+ featureListeners.add(listener)
87
+ return () => {
88
+ featureListeners.delete(listener)
89
+ }
90
+ }
91
+
92
+ function setFeature(key, value) {
93
+ if (!FEATURE_KEYS.includes(key) || typeof value !== 'boolean') return
94
+ const current = getFeatures()
95
+ if (current[key] === value) return
96
+ features = Object.freeze({ ...current, [key]: value })
97
+ try {
98
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(features))
99
+ } catch {
100
+ // Persistence may be blocked; the live value still applies.
101
+ }
102
+ for (const listener of [...featureListeners]) {
103
+ try {
104
+ listener()
105
+ } catch (error) {
106
+ console.error('[dsh-highlight] feature listener failed', error)
107
+ }
108
+ }
109
+ }
110
+
111
+ // -----------------------------------------------------------------------
112
+ // Styles for the settings page
113
+ // -----------------------------------------------------------------------
114
+
115
+ const STYLE_NAME = 'dsh-highlight:settings'
116
+
117
+ const SETTINGS_CSS = [
118
+ '.dmi-feature-row{display:flex;align-items:center;justify-content:space-between;gap:20px;padding:14px 0;border-bottom:.5px solid var(--dsw-alias-border-l3)}',
119
+ '.dmi-feature-row:last-child{border-bottom:0}',
120
+ '.dmi-feature-copy{display:flex;flex-direction:column;gap:3px;min-width:0}',
121
+ '.dmi-feature-label{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:18px}',
122
+ '.dmi-feature-description{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:17px}',
123
+ '.dmi-feature-note{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:17px;padding:8px 0;margin:0}',
124
+ '.dmi-switch{box-sizing:border-box;position:relative;flex:0 0 auto;width:36px;height:20px;padding:2px;border:0;border-radius:999px;background:var(--dsw-alias-border-l3);cursor:pointer}',
125
+ '.dmi-switch[aria-checked="true"]{background:var(--dsw-alias-brand-primary)}',
126
+ '.dmi-switch:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:2px}',
127
+ '.dmi-switch-thumb{display:block;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-switch-thumb);transition:transform .12s ease}',
128
+ '.dmi-switch[aria-checked="true"] .dmi-switch-thumb{transform:translate(16px);background:var(--dsw-alias-label-primary-foreground)}',
129
+ '.dmi-settings{display:flex;flex-direction:column;padding:2px 0}',
130
+ ].join('\n')
131
+
132
+ function installStyle() {
133
+ const existing = document.querySelector('style[data-dsh-mi-style="' + STYLE_NAME + '"]')
134
+ if (existing !== null) return existing
135
+ const style = document.createElement('style')
136
+ style.setAttribute('data-dsh-mi-style', STYLE_NAME)
137
+ style.textContent = SETTINGS_CSS
138
+ ;(document.head === null ? document.documentElement : document.head).appendChild(style)
139
+ return style
140
+ }
141
+
142
+ function removeStyle() {
143
+ for (const style of document.querySelectorAll('style[data-dsh-mi-style="' + STYLE_NAME + '"]')) style.remove()
144
+ }
145
+
146
+ // -----------------------------------------------------------------------
147
+ // Dotfile suffixes and language probes
148
+ // -----------------------------------------------------------------------
149
+
150
+ /** 47 suffixes the shipped extension table does not claim. */
151
+ const DOTFILE_SUFFIXES = [
152
+ 'bashrc', 'bash_aliases', 'bash_profile', 'bash_logout', 'bash_login', 'profile',
153
+ 'zshrc', 'zprofile', 'zshenv', 'zlogin', 'zlogout', 'kshrc', 'cshrc', 'tcshrc',
154
+ 'gitconfig', 'gitignore', 'gitattributes', 'gitmodules', 'npmrc', 'yarnrc', 'nvmrc',
155
+ 'node-version', 'python-version', 'ruby-version', 'tool-versions', 'editorconfig',
156
+ 'inputrc', 'vimrc', 'gvimrc', 'screenrc', 'xinitrc', 'xprofile', 'curlrc', 'wgetrc',
157
+ 'netrc', 'pgpass', 'myclirc', 'sqliterc', 'psqlrc', 'hushlogin', 'dockerignore',
158
+ 'envrc', 'latexmkrc', 'eslintrc', 'prettierrc', 'stylelintrc', 'browserslistrc',
159
+ ]
160
+
161
+ const DOTFILE_LANGUAGES = {
162
+ 'bashrc': 'shellscript',
163
+ 'bash_aliases': 'shellscript',
164
+ 'bash_profile': 'shellscript',
165
+ 'bash_logout': 'shellscript',
166
+ 'bash_login': 'shellscript',
167
+ 'profile': 'shellscript',
168
+ 'zshrc': 'shellscript',
169
+ 'zprofile': 'shellscript',
170
+ 'zshenv': 'shellscript',
171
+ 'zlogin': 'shellscript',
172
+ 'zlogout': 'shellscript',
173
+ 'kshrc': 'shellscript',
174
+ 'cshrc': 'shellscript',
175
+ 'tcshrc': 'shellscript',
176
+ 'xinitrc': 'shellscript',
177
+ 'xprofile': 'shellscript',
178
+ 'envrc': 'shellscript',
179
+ 'gitconfig': 'ini',
180
+ 'npmrc': 'ini',
181
+ 'yarnrc': 'ini',
182
+ 'editorconfig': 'ini',
183
+ 'myclirc': 'ini',
184
+ 'latexmkrc': 'perl',
185
+ }
186
+
187
+ const SHEBANG_LANGUAGES = {
188
+ 'bash': 'shellscript',
189
+ 'sh': 'shellscript',
190
+ 'zsh': 'shellscript',
191
+ 'ksh': 'shellscript',
192
+ 'dash': 'shellscript',
193
+ 'python': 'python',
194
+ 'python3': 'python',
195
+ 'perl': 'perl',
196
+ 'ruby': 'ruby',
197
+ 'node': 'javascript',
198
+ }
199
+
200
+ function suffixOf(name) {
201
+ const at = name.lastIndexOf('.')
202
+ return (at === -1 ? name : name.slice(at + 1)).toLowerCase()
203
+ }
204
+
205
+ /** Shebang plus first-byte shape probes; returns undefined rather than guessing. */
206
+ function probeLanguage(source) {
207
+ const text = source.slice(0, 4096)
208
+ if (text.startsWith('#!')) {
209
+ const parts = text.slice(2).trim().split(/\s+/u)
210
+ let command = parts[0] === undefined ? '' : parts[0]
211
+ command = command.slice(command.lastIndexOf('/') + 1)
212
+ if (command === 'env') {
213
+ const next = parts.slice(1).find(part => part !== '' && !part.startsWith('-'))
214
+ command = next === undefined ? '' : next.slice(next.lastIndexOf('/') + 1)
215
+ }
216
+ const language = SHEBANG_LANGUAGES[command]
217
+ if (language !== undefined) return language
218
+ }
219
+ const trimmed = text.trimStart()
220
+ if (trimmed.startsWith('{')) return 'json'
221
+ if (trimmed.startsWith('[')) {
222
+ try {
223
+ JSON.parse(trimmed)
224
+ return 'json'
225
+ } catch {
226
+ // Not JSON; an INI section header starts with '[' too.
227
+ }
228
+ }
229
+ if (/^\[[^\]\r\n]+\]\s*$/mu.test(text)) return 'ini'
230
+ if (/^[A-Za-z_][\w.-]*\s*:\s*\S/mu.test(text)) return 'yaml'
231
+ if (/^[A-Za-z_][\w.-]*\s*=\s*/mu.test(text)) return 'ini'
232
+ return undefined
233
+ }
234
+
235
+ function languageForDotfile(name, source) {
236
+ const mapped = DOTFILE_LANGUAGES[suffixOf(name)]
237
+ if (mapped !== undefined) return mapped
238
+ return probeLanguage(source)
239
+ }
240
+
241
+ function fileNameFromAddress(address) {
242
+ if (typeof address !== 'string' || address === '') return ''
243
+ const segment = address.slice(address.lastIndexOf('/') + 1)
244
+ try {
245
+ return decodeURIComponent(segment)
246
+ } catch {
247
+ return segment
248
+ }
249
+ }
250
+
251
+ // -----------------------------------------------------------------------
252
+ // Document preview body
253
+ // -----------------------------------------------------------------------
254
+
255
+ function SyntaxPreview(props) {
256
+ const { resourceAddress, content, wrap, scrollportRef, t } = props
257
+ if (content === null || content === undefined || content.kind !== 'text') return null
258
+ const name = fileNameFromAddress(resourceAddress)
259
+ const code = content.text
260
+ const lang = languageForDotfile(name, code)
261
+ return h(
262
+ 'div',
263
+ {
264
+ style: {
265
+ display: 'flex',
266
+ flexDirection: 'column',
267
+ width: '100%',
268
+ height: '100%',
269
+ overflow: 'auto',
270
+ background: 'var(--dsw-alias-markdown-code-block)',
271
+ },
272
+ },
273
+ h(CodeBlock, {
274
+ code,
275
+ lang,
276
+ lineNumbers: true,
277
+ wrap,
278
+ streaming: !content.eof,
279
+ contentRef: scrollportRef,
280
+ copyLabel: t('copy'),
281
+ copiedLabel: t('copied'),
282
+ toolbarLabels: {
283
+ codeLabel: t('code'),
284
+ wrapLabel: t('wrap'),
285
+ unwrapLabel: t('unwrap'),
286
+ },
287
+ }),
288
+ )
289
+ }
290
+
291
+ // -----------------------------------------------------------------------
292
+ // Settings page
293
+ // -----------------------------------------------------------------------
294
+
295
+ function Switch({ checked, label, labelId, onChange }) {
296
+ return h(
297
+ 'button',
298
+ {
299
+ type: 'button',
300
+ role: 'switch',
301
+ 'aria-checked': checked,
302
+ 'aria-label': label,
303
+ 'aria-describedby': labelId,
304
+ className: 'dmi-switch',
305
+ onClick: () => onChange(!checked),
306
+ },
307
+ h('span', { className: 'dmi-switch-thumb' }),
308
+ )
309
+ }
310
+
311
+ function SettingsView(props) {
312
+ const t = props.t
313
+ const current = React.useSyncExternalStore(subscribeFeatures, getFeatures, getFeatures)
314
+ if (props.view === 'summary') return t('settings.summary')
315
+ const descriptionId = 'dmi-description-syntaxExtras'
316
+ return h(
317
+ 'div',
318
+ { className: 'dmi-settings' },
319
+ h('p', { className: 'dmi-feature-note' }, t('settings.note.hidden')),
320
+ h(
321
+ 'div',
322
+ { className: 'dmi-feature-row' },
323
+ h(
324
+ 'div',
325
+ { className: 'dmi-feature-copy' },
326
+ h('span', { className: 'dmi-feature-label' }, t('settings.syntaxExtras.label')),
327
+ h('span', { id: descriptionId, className: 'dmi-feature-description' }, t('settings.syntaxExtras.description')),
328
+ ),
329
+ h(Switch, {
330
+ checked: current.syntaxExtras,
331
+ label: t('settings.syntaxExtras.label'),
332
+ labelId: descriptionId,
333
+ onChange: value => setFeature('syntaxExtras', value),
334
+ }),
335
+ ),
336
+ h('p', { className: 'dmi-feature-note' }, t('settings.note.storage')),
337
+ )
338
+ }
339
+
340
+ // -----------------------------------------------------------------------
341
+ // Locale dictionaries (en + zh are required by the locale service)
342
+ // -----------------------------------------------------------------------
343
+
344
+ const zh = {
345
+ 'renderer.title': '代码',
346
+ 'copy': '复制',
347
+ 'copied': '已复制',
348
+ 'code': '代码',
349
+ 'wrap': '自动换行',
350
+ 'unwrap': '不换行',
351
+ 'settings.summary': '为官方漏掉的 dotfile 提供带行号的代码预览;能识别语法的格式会上色。',
352
+ 'settings.note.hidden': 'dotfile 默认被文件树隐藏,可通过 @ 引用或文件链接打开。',
353
+ 'settings.note.storage': '设置保存在当前浏览器,切换立即生效、刷新后保持。',
354
+ 'settings.syntaxExtras.label': 'dotfile 语法高亮',
355
+ 'settings.syntaxExtras.description': '认领 .bashrc、.gitconfig 等 47 个后缀,能识别语法的格式会上色。',
356
+ }
357
+
358
+ const en = {
359
+ 'renderer.title': 'Code',
360
+ 'copy': 'Copy',
361
+ 'copied': 'Copied',
362
+ 'code': 'Code',
363
+ 'wrap': 'Wrap',
364
+ 'unwrap': 'Unwrap',
365
+ 'settings.summary': 'A line-numbered code preview for dotfiles the shipped preview misses; formats with a known grammar are coloured.',
366
+ 'settings.note.hidden': 'Dotfiles are hidden in the Files tree; open them through an @ reference or file link.',
367
+ 'settings.note.storage': 'Settings are stored in this browser and apply immediately; they survive a reload.',
368
+ 'settings.syntaxExtras.label': 'Dotfile highlighting',
369
+ 'settings.syntaxExtras.description': 'Claims 47 suffixes such as .bashrc and .gitconfig; formats with a known grammar are coloured.',
370
+ }
371
+
372
+ // -----------------------------------------------------------------------
373
+ // Runtime: switch application and preview registration
374
+ // -----------------------------------------------------------------------
375
+
376
+ function createRuntime(ctx, t) {
377
+ let disposed = false
378
+ let previewDisposer = null
379
+ let unsubscribeStore = null
380
+
381
+ function applySyntaxExtras(enabled) {
382
+ if (enabled) {
383
+ if (previewDisposer === null) {
384
+ previewDisposer = ctx.documentPreviews.register({
385
+ id: PREVIEW_ID,
386
+ extensions: DOTFILE_SUFFIXES,
387
+ priority: 'extension',
388
+ title: () => t('renderer.title'),
389
+ loading: 'text-pages',
390
+ wrap: true,
391
+ sourceLines: true,
392
+ })
393
+ }
394
+ } else if (previewDisposer !== null) {
395
+ previewDisposer()
396
+ previewDisposer = null
397
+ }
398
+ }
399
+
400
+ function applyFeatures() {
401
+ applySyntaxExtras(getFeatures().syntaxExtras)
402
+ }
403
+
404
+ return {
405
+ start() {
406
+ installStyle()
407
+ applySyntaxExtras(getFeatures().syntaxExtras)
408
+ unsubscribeStore = subscribeFeatures(applyFeatures)
409
+ return () => {
410
+ if (disposed) return
411
+ disposed = true
412
+ if (unsubscribeStore !== null) {
413
+ unsubscribeStore()
414
+ unsubscribeStore = null
415
+ }
416
+ if (previewDisposer !== null) {
417
+ previewDisposer()
418
+ previewDisposer = null
419
+ }
420
+ removeStyle()
421
+ }
422
+ },
423
+ }
424
+ }
425
+
426
+ // -----------------------------------------------------------------------
427
+ // Plugin export
428
+ // -----------------------------------------------------------------------
429
+
430
+ function apply(ctx) {
431
+ ctx.effect(() => ctx.locale.register(LOCALE_NS, { zh, en }), 'dsh-highlight: locale')
432
+ const t = ctx.locale.bind(LOCALE_NS)
433
+
434
+ ctx.effect(
435
+ () => ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
436
+ name: 'plugins.row.config',
437
+ key: ROW_CONFIG_KEY,
438
+ locale: LOCALE_NS,
439
+ }, SettingsView)),
440
+ 'dsh-highlight: settings row',
441
+ )
442
+
443
+ // The body stays registered for the plugin's lifetime; without a live
444
+ // preview definition the owner never dispatches to it.
445
+ ctx.effect(
446
+ () => ctx.slots.inject('sidebar.right.tab.document', () => ctx.slots.register({
447
+ name: 'sidebar.right.tab.document',
448
+ key: PREVIEW_ID,
449
+ locale: LOCALE_NS,
450
+ }, SyntaxPreview)),
451
+ 'dsh-highlight: dotfile preview body',
452
+ )
453
+
454
+ ctx.effect(
455
+ () => createRuntime(ctx, t).start(),
456
+ 'dsh-highlight: preview runtime',
457
+ )
458
+ }
459
+
460
+ return {
461
+ inject: ['slots', 'documentPreviews', 'locale'],
462
+ apply,
463
+ }
464
+ },
465
+ })
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@jianghuifr/dsh-highlight` — host half.
3
+ *
4
+ * The feature is entirely browser-side (a document preview rendered by the
5
+ * shared CodeBlock baseline), so the host half only needs a row the Loader can
6
+ * mount; the client bundle ships the real work.
7
+ */
8
+ export function apply() {}
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Dotfile code highlight",
4
+ "description": "Claims the dotfile suffixes the shipped preview table misses (.bashrc, .zshrc, .gitconfig, …) and renders them with line numbers and syntax colours instead of plain text."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "dotfile 代码高亮",
4
+ "description": "认领官方预览表漏掉的 dotfile 后缀(.bashrc、.zshrc、.gitconfig 等),用带行号和语法着色的代码预览代替纯文本。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@jianghuifr/dsh-highlight",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "A syntax-highlighted code preview for the shell dotfiles the DeepSeek Harness Web UI would otherwise show as plain text (.bashrc, .gitconfig, …).",
5
+ "keywords": [
6
+ "dsh",
7
+ "dsh-plugin",
8
+ "deepseek-harness",
9
+ "syntax-highlight",
10
+ "dotfiles",
11
+ "code-preview"
12
+ ],
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "icon": "icon.svg",
16
+ "exports": {
17
+ ".": "./lib/index.js",
18
+ "./client": "./lib/client.js",
19
+ "./package.json": "./package.json",
20
+ "./locale/*.json": "./locale/*.json",
21
+ "./icon": "./icon.svg"
22
+ },
23
+ "files": [
24
+ "lib/",
25
+ "locale/",
26
+ "docs/",
27
+ "cordis.patch.yml",
28
+ "icon.svg",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "lint": "eslint .",
34
+ "test": "node --test test/*.test.mjs",
35
+ "check": "node scripts/check.mjs",
36
+ "verify": "npm run check && npm run lint && npm test",
37
+ "prepublishOnly": "npm run verify"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/jianghuifr/dsh-highlight.git"
42
+ },
43
+ "homepage": "https://github.com/jianghuifr/dsh-highlight#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/jianghuifr/dsh-highlight/issues"
46
+ },
47
+ "author": "jianghuifr",
48
+ "engines": {
49
+ "node": ">=22.19.0",
50
+ "dsh": ">=0.2.2-rc.1"
51
+ },
52
+ "license": "MIT",
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "dsh": {
58
+ "manifestVersion": 1,
59
+ "bundle": {
60
+ "patch": "./cordis.patch.yml"
61
+ },
62
+ "client": {
63
+ "platform": "web",
64
+ "inject": [],
65
+ "immediately": false
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@eslint/js": "^10.0.1",
70
+ "eslint": "^10.10.0"
71
+ }
72
+ }