dsh-plugin-zotero 0.1.2 → 0.1.3
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 +58 -11
- package/client/client.js +335 -69
- package/lib/zotero/client.d.ts +6 -1
- package/lib/zotero/client.js +94 -3
- package/lib/zotero/types.d.ts +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
基于 [cordis](https://github.com/deepseek-ai/cordis) 的 DSH 插件,把本机 Zotero 文献库接进 DSH。分两半,职责不重叠、互不依赖:
|
|
4
4
|
|
|
5
|
+
## 截图
|
|
6
|
+
|
|
7
|
+
[](docs/images/zotero-pane.png)
|
|
8
|
+
|
|
9
|
+
<sub>上图为 DSH 会话与右侧「Zotero 文献库」面板:上方正文区展示元数据与全文,下方分区 tab 展示参考文献、笔记与附件,点击图片可查看原图。</sub>
|
|
10
|
+
|
|
11
|
+
面板分三块:
|
|
12
|
+
|
|
13
|
+
- **顶部状态栏**:显示 Zotero 是否已连接、模型工具是否可用,并提供刷新。
|
|
14
|
+
- **左侧分类树**:按 Zotero 分类逐级浏览,支持按标题 / 摘要搜索。
|
|
15
|
+
- **右侧详情**:上方正文区展示条目元数据、可折叠摘要与 PDF 全文;下方分区 tab 切换参考文献、笔记、附件;「添加条目引用」把引用写入当前会话草稿。
|
|
16
|
+
|
|
5
17
|
| 半边 | 能力 | 通道 |
|
|
6
18
|
|---|---|---|
|
|
7
|
-
| **人侧面板** | 在 DSH 右侧栏只读浏览 Zotero 文库(分类树 / 搜索 / 条目详情 / PDF 全文),把条目、摘录或整目录引用写进会话草稿 | 插件在宿主 web server 自注册的 `/dsh-zotero/api/*` 路由 |
|
|
19
|
+
| **人侧面板** | 在 DSH 右侧栏只读浏览 Zotero 文库(分类树 / 搜索 / 条目详情 / 笔记 / PDF 全文),把条目、摘录或整目录引用写进会话草稿 | 插件在宿主 web server 自注册的 `/dsh-zotero/api/*` 路由 |
|
|
8
20
|
| **模型侧** | 检索、精读、按需操作文库 | 插件**自持**连接本机 Zotero 集成 MCP,工具以 `mcp__zotero__*` 注册给模型 |
|
|
9
21
|
|
|
10
22
|
MCP 没起,面板照常可用;Zotero 没开,模型工具自然也不可用。
|
|
@@ -25,9 +37,44 @@ dsh plugin --profile <profile> add dsh-plugin-zotero
|
|
|
25
37
|
|
|
26
38
|
包内是预构建产物(`lib/` + `client/client.js`),安装时**不运行构建脚本**,无需 `allowBuilds` 授权。本地源码开发见[方案一:本地路径安装](docs/插件发布/方案一本地路径安装.zh.md)。
|
|
27
39
|
|
|
40
|
+
## 使用前提
|
|
41
|
+
|
|
42
|
+
使用本插件前,本机 Zotero 需备好两件事:**集成 MCP 插件**与**本地 API**。
|
|
43
|
+
|
|
44
|
+
### 1. 安装 Zotero MCP 插件
|
|
45
|
+
|
|
46
|
+
在 Zotero 的插件市场搜索 `mcp`,安装列表第一行、标签为 `ai` / `integration` 的 **Zotero MCP Plugin**(即 `zotero-integrated-mcp`)。装好后无需额外配置,默认监听 `http://127.0.0.1:23120/mcp`。
|
|
47
|
+
|
|
48
|
+
[](docs/images/zotero-mcp-plugin-market.png)
|
|
49
|
+
|
|
50
|
+
<sub>上图为 Zotero 插件市场,第一行「Zotero MCP Plugin」已安装。</sub>
|
|
51
|
+
|
|
52
|
+
如果装的是**其他** MCP 插件,或它的监听地址 / 端口不是 23120,到 dsh「插件」面板展开 `dsh-plugin-zotero` → 「配置 dsh-plugin-zotero」,把 **MCP 设置 → `mcpUrl`** 改成实际端点(如 `http://127.0.0.1:<端口>/mcp`)并保存,即时生效,无需重启。字段说明见[插件页配置项](#插件页配置项)。
|
|
53
|
+
|
|
54
|
+
> 没装 MCP 插件不影响右侧面板使用,只是模型侧 `mcp__zotero__*` 工具不可用。
|
|
55
|
+
|
|
56
|
+
### 2. 开启 Zotero 本地 API
|
|
57
|
+
|
|
58
|
+
Zotero → 设置 → 高级 → 勾选 **「允许此计算机上的其他应用程序与 Zotero 通信」**(默认端口 23119,仅监听回环)。
|
|
59
|
+
|
|
60
|
+
[](docs/images/zotero-allow-communication.png)
|
|
61
|
+
|
|
62
|
+
<sub>上图为 Zotero「设置 → 高级」中开启本地 API 的开关。</sub>
|
|
63
|
+
|
|
64
|
+
验证:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
curl http://127.0.0.1:23119/api/ # 期望输出:Zotero is running
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
未勾选时读端点返回 403,面板显示「Zotero 未连接」并提示启用步骤。
|
|
71
|
+
|
|
28
72
|
## 特性
|
|
29
73
|
|
|
30
74
|
- **右侧栏面板「Zotero 文献库」**:顶部状态栏(Zotero / 模型工具探活)+ 左侧分类树(按需拉取、标题摘要搜索)+ 右侧条目详情或分类概要。
|
|
75
|
+
- **详情区上下分区**:上方正文区展示标题、元数据、摘要与 PDF 全文;下方用 tab 切换「参考文献 / 笔记 / 附件」。两个区域之间的分隔条可拖动,正文占比默认 85% 并按会话记住;没有次级内容的条目正文独占整栏。
|
|
76
|
+
- **摘要默认折叠**:标题行右侧的箭头按钮展开 / 收起摘要,默认把空间留给正文与全文。
|
|
77
|
+
- **笔记可读**:笔记以折叠列表呈现(默认收起,点击标题展开),正文保留 Zotero 的引用块、标注高亮、表格与外链图片;Host 侧已清洗脚本与事件属性,避免注入。
|
|
31
78
|
- **三种插入方式**:单条目引用、全文划词摘录、整目录引用,均只写进会话草稿(不自动发送、不抢焦点),文本携带 `itemKey` / `collectionKey` 供模型接续操作。
|
|
32
79
|
- **面板严格只读**:不提供任何新建 / 改名 / 删除分类的按钮。
|
|
33
80
|
- **模型侧工具可逐个开关**:插件自持连接集成 MCP,把工具以 `mcp__zotero__*` 注册进 dsh,可在插件页按工具启用 / 禁用。
|
|
@@ -81,6 +128,7 @@ MCP 组下方是 **「MCP 工具」** 区:现场列出集成 MCP 的全部工
|
|
|
81
128
|
- Host 路由为 `GET /dsh-zotero/api/<action>`,action 有 `health` / `tree` / `items` / `item` / `collection-bib` / `mcp-tools`。
|
|
82
129
|
- Host 侧带信任栅栏:仅接受 GET,拒绝 `sec-fetch-site: cross-site`,且 `Host` 必须是回环地址(防 DNS rebinding)。
|
|
83
130
|
- 响应统一信封 `{ok:true,data}` / `{ok:false,error:{code,message}}`,错误码见 [src/zotero/types.ts](src/zotero/types.ts)。
|
|
131
|
+
- 条目详情里的笔记由 Host 侧从 `itemType: "note"` 子条目提取并清洗 HTML(剥离脚本、事件属性与冗余 `data-*`,图片限宽),Client 只负责折叠展示。
|
|
84
132
|
- 面板正文会被每个会话各挂一份,因此分类树 / 搜索词 / 选中项等状态放在 [src/client/paneStore.ts](src/client/paneStore.ts) 的模块级单例里,各会话看到的是同一块面板;右侧栏的展开状态与 tab 则**按会话**持久。
|
|
85
133
|
- 无会话时面板仍可通过右侧栏的 guide 入口(「Zotero 文献库」)打开。
|
|
86
134
|
|
|
@@ -93,7 +141,7 @@ src/ # 插件源码(主包,ESM / NodeNext / strict)
|
|
|
93
141
|
│ ├── router.ts # 只读 HTTP 路由 GET /dsh-zotero/api/<action>
|
|
94
142
|
│ └── mcp-bridge.ts # 自持集成 MCP 连接 + 按开关过滤注册模型工具
|
|
95
143
|
├── zotero/
|
|
96
|
-
│ ├── client.ts # Zotero 本地 API 客户端(只读)+ 集成 MCP JSON-RPC
|
|
144
|
+
│ ├── client.ts # Zotero 本地 API 客户端(只读)+ 笔记提取清洗 + 集成 MCP JSON-RPC
|
|
97
145
|
│ ├── config.ts # 端点 / 超时 / 截断阈值 + 运行时设置读取器
|
|
98
146
|
│ └── types.ts # Host ↔ Client 数据契约
|
|
99
147
|
└── client/ # Client 半(浏览器)
|
|
@@ -101,6 +149,9 @@ src/ # 插件源码(主包,ESM / NodeNext / strict)
|
|
|
101
149
|
├── ZoteroCard.tsx # 插件页配置卡(API 设置 / MCP 设置 / 工具开关)
|
|
102
150
|
├── ZoteroPane.tsx # 面板容器:状态栏 + 分类树 + 详情
|
|
103
151
|
├── CollectionTree.tsx / ItemDetail.tsx
|
|
152
|
+
├── DetailTabs.tsx # 详情底部分区 tab(参考文献 / 笔记 / 附件)
|
|
153
|
+
├── NoteList.tsx # 笔记折叠列表与正文渲染
|
|
154
|
+
├── styles.ts # 分区小标题 / 展开按钮等共用样式
|
|
104
155
|
├── paneStore.ts # 跨会话共享的面板状态
|
|
105
156
|
├── inline.ts # 往会话草稿插入文本
|
|
106
157
|
├── compose.ts # 插入文本模板
|
|
@@ -122,8 +173,8 @@ plugin_helloword/ # 官方插件示例(学习用,勿放正式代码
|
|
|
122
173
|
|
|
123
174
|
- Node + **pnpm**(主包与 `tstest/` 统一用 pnpm,勿与 npm / yarn 混用)。
|
|
124
175
|
- **TypeScript ^5.9**:`tsdown@0.22.0` 的 peer 依赖不支持 TypeScript 7.x。
|
|
125
|
-
- Zotero 桌面版已运行,且已开启本地 API
|
|
126
|
-
-
|
|
176
|
+
- Zotero 桌面版已运行,且已开启本地 API(见[使用前提](#使用前提))。
|
|
177
|
+
- **模型侧必需**:Zotero 已安装集成 MCP 插件(插件市场中的 **Zotero MCP Plugin** / `zotero-integrated-mcp`),监听 23120——若用其他 MCP 插件或端口不同,需在插件配置卡改 `mcpUrl`;并在 MCP 插件设置中**开启「允许写操作」**。只装插件不开写操作时,模型侧读类工具照常,但让模型新建 / 修改分类会直接报错(插件返回「写操作已禁用」)。详见[模型侧 MCP 与权限边界](#模型侧-mcp-与权限边界)。
|
|
127
178
|
- `dsh` CLI 可用。
|
|
128
179
|
|
|
129
180
|
## 构建
|
|
@@ -163,18 +214,14 @@ dsh --profile demo # 启动
|
|
|
163
214
|
|
|
164
215
|
### 开启 Zotero 本地 API
|
|
165
216
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
```sh
|
|
169
|
-
curl http://127.0.0.1:23119/api/ # 期望输出:Zotero is running
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
未勾选时读端点返回 403,面板显示「Zotero 未连接」并提示启用步骤。
|
|
217
|
+
见[使用前提 → 开启 Zotero 本地 API](#2-开启-zotero-本地-api)。未勾选时读端点返回 403,面板显示「Zotero 未连接」并提示启用步骤。
|
|
173
218
|
|
|
174
219
|
### 模型侧 MCP 与权限边界
|
|
175
220
|
|
|
176
221
|
模型侧工具由**插件自己**桥接:[src/host/mcp-bridge.ts](src/host/mcp-bridge.ts) 直连本机 Zotero 集成 MCP(本机实测 `zotero-integrated-mcp v1.1.0`,暴露 20 个工具),按配置里的 `disabledMcpTools` 过滤后以 `mcp__zotero__*` 注册给模型。[cordis.patch.yml](cordis.patch.yml) **不再**插入 `@deepseek-ai/dsh-mcp-client` —— 它不支持按工具开关,且同 `serverName` 会与自注册工具重名冲突。
|
|
177
222
|
|
|
223
|
+
⚠️ 前提是 [Zotero 里已装好集成 MCP 插件](#1-安装-zotero-mcp-插件)(或改用其他 MCP 插件并在配置卡填对 `mcpUrl`),并且开启了「允许写操作」。插件未安装或服务未起时,模型侧工具全部不可用;插件装了但没开写操作时,读类工具正常,`create_collection` 等写工具会被插件拒绝(返回「写操作已禁用」),表现为让模型帮忙新建分类直接报错——此时到 MCP 插件设置里打开写操作并重试即可,无需重启 dsh。
|
|
224
|
+
|
|
178
225
|
⚠️ 面板只读,**但模型侧工具不是**:20 个工具中含 5 个改变文库结构的写工具(`create_collection` / `update_collection` / `delete_collection` / `add_items_to_collection` / `remove_items_from_collection`)。想收紧为纯只读,直接在插件页配置卡的「MCP 工具」里关掉它们并保存即可;面板功能不受影响。
|
|
179
226
|
|
|
180
227
|
## 相关文档
|
package/client/client.js
CHANGED
|
@@ -48,8 +48,12 @@ const dicts = {
|
|
|
48
48
|
"detail.doi": "DOI",
|
|
49
49
|
"detail.url": "链接",
|
|
50
50
|
"detail.abstract": "摘要",
|
|
51
|
+
"detail.abstractExpand": "展开摘要",
|
|
52
|
+
"detail.abstractCollapse": "收起摘要",
|
|
51
53
|
"detail.tags": "标签",
|
|
52
54
|
"detail.attachments": "附件",
|
|
55
|
+
"detail.notes": "笔记",
|
|
56
|
+
"detail.noteTruncated": "(已按长度截断)",
|
|
53
57
|
"detail.fulltext": "全文",
|
|
54
58
|
"detail.noFulltext": "该附件没有可用的全文索引",
|
|
55
59
|
"detail.fulltextTruncated": "(已按长度截断)",
|
|
@@ -136,8 +140,12 @@ const dicts = {
|
|
|
136
140
|
"detail.doi": "DOI",
|
|
137
141
|
"detail.url": "URL",
|
|
138
142
|
"detail.abstract": "Abstract",
|
|
143
|
+
"detail.abstractExpand": "Expand abstract",
|
|
144
|
+
"detail.abstractCollapse": "Collapse abstract",
|
|
139
145
|
"detail.tags": "Tags",
|
|
140
146
|
"detail.attachments": "Attachments",
|
|
147
|
+
"detail.notes": "Notes",
|
|
148
|
+
"detail.noteTruncated": "(truncated by length)",
|
|
141
149
|
"detail.fulltext": "Full text",
|
|
142
150
|
"detail.noFulltext": "No full-text index available for this attachment",
|
|
143
151
|
"detail.fulltextTruncated": "(truncated by length)",
|
|
@@ -1229,25 +1237,260 @@ async function insertBuilt(actions, build) {
|
|
|
1229
1237
|
return actions.insertText(text, span) ? "inserted" : "draft-changed";
|
|
1230
1238
|
}
|
|
1231
1239
|
//#endregion
|
|
1240
|
+
//#region src/client/styles.ts
|
|
1241
|
+
/**
|
|
1242
|
+
* 右栏共用样式。
|
|
1243
|
+
*
|
|
1244
|
+
* 小标题(摘要 / 全文 / 参考文献 / 附件 / 笔记)统一用 {@link sectionTitleStyle}:
|
|
1245
|
+
* 蓝色、加粗、字号略大,方便在密集的元数据里一眼识别分区。
|
|
1246
|
+
*/
|
|
1247
|
+
/** 蓝色高亮色(与分隔条 hover 蓝一致)。 */
|
|
1248
|
+
const ACCENT = "#508cff";
|
|
1249
|
+
/** 分区小标题。 */
|
|
1250
|
+
const sectionTitleStyle = {
|
|
1251
|
+
margin: "0 0 6px",
|
|
1252
|
+
fontSize: 13,
|
|
1253
|
+
fontWeight: 700,
|
|
1254
|
+
color: ACCENT,
|
|
1255
|
+
letterSpacing: .2
|
|
1256
|
+
};
|
|
1257
|
+
/** 可点击的小标题行(带展开/收起箭头)。 */
|
|
1258
|
+
const sectionToggleRowStyle = {
|
|
1259
|
+
display: "flex",
|
|
1260
|
+
alignItems: "center",
|
|
1261
|
+
gap: 6,
|
|
1262
|
+
margin: "0 0 6px"
|
|
1263
|
+
};
|
|
1264
|
+
/** 展开/收起箭头按钮。 */
|
|
1265
|
+
const sectionToggleButtonStyle = {
|
|
1266
|
+
display: "inline-flex",
|
|
1267
|
+
alignItems: "center",
|
|
1268
|
+
justifyContent: "center",
|
|
1269
|
+
width: 20,
|
|
1270
|
+
height: 20,
|
|
1271
|
+
padding: 0,
|
|
1272
|
+
fontSize: 11,
|
|
1273
|
+
lineHeight: 1,
|
|
1274
|
+
color: ACCENT,
|
|
1275
|
+
background: "transparent",
|
|
1276
|
+
border: "1px solid rgba(80,140,255,0.4)",
|
|
1277
|
+
borderRadius: 5,
|
|
1278
|
+
cursor: "pointer"
|
|
1279
|
+
};
|
|
1280
|
+
//#endregion
|
|
1281
|
+
//#region src/client/DetailTabs.tsx
|
|
1282
|
+
/**
|
|
1283
|
+
* 右栏底部:可切换的分区面板(tab 页)。
|
|
1284
|
+
*
|
|
1285
|
+
* 用于承载「参考文献 / 笔记 / 附件」这类次级内容:它们与正文区(标题、元数据、
|
|
1286
|
+
* 摘要、全文)分开,用 tab 切换,避免正文区被撑散、也方便后续往这里加新的分区。
|
|
1287
|
+
*
|
|
1288
|
+
* 传入的 tabs 里没有内容的分区不会被渲染成 tab;默认选中第一个有内容的分区。
|
|
1289
|
+
*/
|
|
1290
|
+
function DetailTabs({ tabs }) {
|
|
1291
|
+
const [activeId, setActiveId] = (0, react.useState)("");
|
|
1292
|
+
if (tabs.length === 0) return null;
|
|
1293
|
+
const active = tabs.find((tab) => tab.id === activeId) ?? tabs[0];
|
|
1294
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1295
|
+
style: {
|
|
1296
|
+
display: "flex",
|
|
1297
|
+
flexDirection: "column",
|
|
1298
|
+
minHeight: 0,
|
|
1299
|
+
height: "100%"
|
|
1300
|
+
},
|
|
1301
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1302
|
+
role: "tablist",
|
|
1303
|
+
style: tabBarStyle,
|
|
1304
|
+
children: tabs.map((tab) => {
|
|
1305
|
+
const selected = tab.id === active.id;
|
|
1306
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1307
|
+
type: "button",
|
|
1308
|
+
role: "tab",
|
|
1309
|
+
"aria-selected": selected,
|
|
1310
|
+
onClick: () => setActiveId(tab.id),
|
|
1311
|
+
style: tabButtonStyle(selected),
|
|
1312
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: tab.label }), tab.hint !== void 0 && tab.hint !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1313
|
+
style: {
|
|
1314
|
+
opacity: .55,
|
|
1315
|
+
fontWeight: 400,
|
|
1316
|
+
fontSize: 11
|
|
1317
|
+
},
|
|
1318
|
+
children: tab.hint
|
|
1319
|
+
})]
|
|
1320
|
+
}, tab.id);
|
|
1321
|
+
})
|
|
1322
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1323
|
+
role: "tabpanel",
|
|
1324
|
+
style: {
|
|
1325
|
+
flex: 1,
|
|
1326
|
+
minHeight: 0,
|
|
1327
|
+
overflow: "auto",
|
|
1328
|
+
padding: "10px 14px 12px"
|
|
1329
|
+
},
|
|
1330
|
+
children: active.content
|
|
1331
|
+
})]
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
const tabBarStyle = {
|
|
1335
|
+
display: "flex",
|
|
1336
|
+
alignItems: "stretch",
|
|
1337
|
+
gap: 4,
|
|
1338
|
+
flexShrink: 0,
|
|
1339
|
+
padding: "0 10px",
|
|
1340
|
+
borderBottom: "1px solid rgba(127,127,127,0.22)"
|
|
1341
|
+
};
|
|
1342
|
+
function tabButtonStyle(selected) {
|
|
1343
|
+
return {
|
|
1344
|
+
display: "inline-flex",
|
|
1345
|
+
alignItems: "center",
|
|
1346
|
+
gap: 5,
|
|
1347
|
+
padding: "8px 10px 7px",
|
|
1348
|
+
marginBottom: -1,
|
|
1349
|
+
fontSize: 13,
|
|
1350
|
+
fontWeight: 700,
|
|
1351
|
+
letterSpacing: .2,
|
|
1352
|
+
color: ACCENT,
|
|
1353
|
+
opacity: selected ? 1 : .55,
|
|
1354
|
+
background: "transparent",
|
|
1355
|
+
border: "none",
|
|
1356
|
+
borderBottom: `2px solid ${selected ? ACCENT : "transparent"}`,
|
|
1357
|
+
cursor: "pointer"
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
//#endregion
|
|
1361
|
+
//#region src/client/NoteList.tsx
|
|
1362
|
+
/**
|
|
1363
|
+
* 右栏:条目详情「笔记」tab 里的笔记列表。
|
|
1364
|
+
*
|
|
1365
|
+
* 笔记是 Zotero 的子条目(`itemType: "note"`),正文在 `data.note` 字段里,
|
|
1366
|
+
* 是带排版标签的 HTML(段落、引用、标注高亮、外链图片)。
|
|
1367
|
+
* Host 侧已完成清洗(剥离 `data-*` 冗余属性、脚本与事件属性、图片限宽),
|
|
1368
|
+
* 这里直接以 `dangerouslySetInnerHTML` 渲染。
|
|
1369
|
+
*
|
|
1370
|
+
* 每条笔记默认折叠成一行标题(正文首段摘要),点击标题展开正文。
|
|
1371
|
+
*/
|
|
1372
|
+
function NoteList({ t, notes }) {
|
|
1373
|
+
const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
|
|
1374
|
+
if (notes.length === 0) return null;
|
|
1375
|
+
function toggle(key) {
|
|
1376
|
+
setExpanded((prev) => {
|
|
1377
|
+
const next = new Set(prev);
|
|
1378
|
+
if (next.has(key)) next.delete(key);
|
|
1379
|
+
else next.add(key);
|
|
1380
|
+
return next;
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: NOTE_CSS }), notes.map((note) => {
|
|
1384
|
+
const open = expanded.has(note.key);
|
|
1385
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1386
|
+
style: { marginBottom: 10 },
|
|
1387
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1388
|
+
type: "button",
|
|
1389
|
+
onClick: () => toggle(note.key),
|
|
1390
|
+
style: noteHeaderStyle,
|
|
1391
|
+
children: [
|
|
1392
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1393
|
+
style: {
|
|
1394
|
+
flexShrink: 0,
|
|
1395
|
+
opacity: .55
|
|
1396
|
+
},
|
|
1397
|
+
children: open ? "▾" : "▸"
|
|
1398
|
+
}),
|
|
1399
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1400
|
+
style: {
|
|
1401
|
+
flex: 1,
|
|
1402
|
+
textAlign: "left",
|
|
1403
|
+
wordBreak: "break-word"
|
|
1404
|
+
},
|
|
1405
|
+
children: note.title
|
|
1406
|
+
}),
|
|
1407
|
+
note.truncated && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1408
|
+
style: {
|
|
1409
|
+
opacity: .55,
|
|
1410
|
+
flexShrink: 0
|
|
1411
|
+
},
|
|
1412
|
+
children: t("detail.noteTruncated")
|
|
1413
|
+
})
|
|
1414
|
+
]
|
|
1415
|
+
}), open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1416
|
+
className: "dsh-zotero-note",
|
|
1417
|
+
dangerouslySetInnerHTML: { __html: note.html },
|
|
1418
|
+
style: noteBodyStyle
|
|
1419
|
+
})]
|
|
1420
|
+
}, note.key);
|
|
1421
|
+
})] });
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* 笔记正文里的样式。
|
|
1425
|
+
*
|
|
1426
|
+
* 笔记 HTML 由 Zotero 生成,段落/引用/高亮标记都是默认样式,这里补一套
|
|
1427
|
+
* 贴合右栏密度的排版(引用块、标注高亮、图片、表格)。
|
|
1428
|
+
*/
|
|
1429
|
+
const NOTE_CSS = `
|
|
1430
|
+
.dsh-zotero-note p { margin: 0 0 6px; }
|
|
1431
|
+
.dsh-zotero-note p:last-child { margin-bottom: 0; }
|
|
1432
|
+
.dsh-zotero-note blockquote {
|
|
1433
|
+
margin: 6px 0;
|
|
1434
|
+
padding-left: 8px;
|
|
1435
|
+
border-left: 3px solid rgba(127,127,127,0.3);
|
|
1436
|
+
opacity: 0.85;
|
|
1437
|
+
}
|
|
1438
|
+
.dsh-zotero-note .highlight {
|
|
1439
|
+
background: rgba(255, 213, 79, 0.28);
|
|
1440
|
+
border-radius: 2px;
|
|
1441
|
+
}
|
|
1442
|
+
.dsh-zotero-note .citation { opacity: 0.75; font-style: italic; }
|
|
1443
|
+
.dsh-zotero-note img { max-width: 100%; height: auto; border-radius: 4px; }
|
|
1444
|
+
.dsh-zotero-note figure { margin: 6px 0; }
|
|
1445
|
+
.dsh-zotero-note table { border-collapse: collapse; max-width: 100%; }
|
|
1446
|
+
.dsh-zotero-note td, .dsh-zotero-note th { border: 1px solid rgba(127,127,127,0.25); padding: 3px 6px; }
|
|
1447
|
+
`;
|
|
1448
|
+
const noteHeaderStyle = {
|
|
1449
|
+
display: "flex",
|
|
1450
|
+
gap: 6,
|
|
1451
|
+
alignItems: "baseline",
|
|
1452
|
+
width: "100%",
|
|
1453
|
+
padding: "4px 2px",
|
|
1454
|
+
fontSize: 12.5,
|
|
1455
|
+
lineHeight: 1.6,
|
|
1456
|
+
background: "transparent",
|
|
1457
|
+
border: "none",
|
|
1458
|
+
borderBottom: "1px solid rgba(127,127,127,0.18)",
|
|
1459
|
+
color: "inherit",
|
|
1460
|
+
cursor: "pointer"
|
|
1461
|
+
};
|
|
1462
|
+
const noteBodyStyle = {
|
|
1463
|
+
marginTop: 6,
|
|
1464
|
+
padding: "6px 8px",
|
|
1465
|
+
border: "1px solid rgba(127,127,127,0.25)",
|
|
1466
|
+
borderRadius: 6,
|
|
1467
|
+
fontSize: 12.5,
|
|
1468
|
+
lineHeight: 1.75,
|
|
1469
|
+
opacity: .9,
|
|
1470
|
+
overflowWrap: "break-word"
|
|
1471
|
+
};
|
|
1472
|
+
//#endregion
|
|
1232
1473
|
//#region src/client/ItemDetail.tsx
|
|
1233
1474
|
/**
|
|
1234
1475
|
* 右栏:单条条目详情。
|
|
1235
1476
|
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1238
|
-
*
|
|
1477
|
+
* 版面分上下两区:上方「正文区」(标题 / 元数据 / 摘要 / 全文块),下方「分区面板区」
|
|
1478
|
+
* (参考文献 / 笔记 / 附件,用 tab 切换)。两区之间是可拖动的横向分隔条,默认正文占
|
|
1479
|
+
* 85%,占比存 localStorage 跨会话记住;底部没有任何分区时不分区,正文独占整栏。
|
|
1480
|
+
*
|
|
1481
|
+
* 正文区内部再分两块:头部信息(标题 / 元数据 / 摘要,过高时自己滚动)与全文块
|
|
1482
|
+
* (撑满剩余高度、自己滚动),所以拖高正文区时全文文本跟着变高。
|
|
1239
1483
|
*
|
|
1240
|
-
*
|
|
1241
|
-
* 全文块(撑满剩余高度、自己滚动),所以拖高正文区时全文文本跟着变高。
|
|
1484
|
+
* 摘要默认折叠,标题行右侧的箭头按钮展开 / 收起。
|
|
1242
1485
|
*
|
|
1243
1486
|
* 「添加到会话」两处入口:头部按钮(整条目元数据)、全文块里的选区浮出按钮
|
|
1244
1487
|
* (摘录)。全文块内用鼠标选中文本后浮出小按钮,位置取选区 rect。
|
|
1245
1488
|
*/
|
|
1246
1489
|
/** 正文区占比的存储键与取值范围(%)。 */
|
|
1247
1490
|
const BODY_PERCENT_KEY = "dsh-plugin-zotero.detailBodyPercent";
|
|
1248
|
-
const BODY_PERCENT_DEFAULT =
|
|
1491
|
+
const BODY_PERCENT_DEFAULT = 85;
|
|
1249
1492
|
const BODY_PERCENT_MIN = 30;
|
|
1250
|
-
const BODY_PERCENT_MAX =
|
|
1493
|
+
const BODY_PERCENT_MAX = 95;
|
|
1251
1494
|
function readBodyPercent() {
|
|
1252
1495
|
try {
|
|
1253
1496
|
const value = Number.parseInt(window.localStorage.getItem(BODY_PERCENT_KEY) ?? "", 10);
|
|
@@ -1287,11 +1530,61 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1287
1530
|
const [selection, setSelection] = (0, react.useState)(null);
|
|
1288
1531
|
const [bodyPercent, setBodyPercent] = (0, react.useState)(readBodyPercent);
|
|
1289
1532
|
const [splitHover, setSplitHover] = (0, react.useState)(false);
|
|
1533
|
+
const [abstractOpen, setAbstractOpen] = (0, react.useState)(false);
|
|
1290
1534
|
const boxRef = (0, react.useRef)(null);
|
|
1291
1535
|
const rootRef = (0, react.useRef)(null);
|
|
1292
1536
|
const dragRef = (0, react.useRef)(null);
|
|
1293
1537
|
const bib = detail.bib;
|
|
1294
1538
|
const fulltext = detail.fulltext;
|
|
1539
|
+
const tabs = [];
|
|
1540
|
+
if (bib !== null) tabs.push({
|
|
1541
|
+
id: "bib",
|
|
1542
|
+
label: t("detail.bibTitle"),
|
|
1543
|
+
content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1544
|
+
style: {
|
|
1545
|
+
margin: 0,
|
|
1546
|
+
opacity: .85,
|
|
1547
|
+
fontSize: 12.5,
|
|
1548
|
+
lineHeight: 1.7,
|
|
1549
|
+
whiteSpace: "pre-wrap"
|
|
1550
|
+
},
|
|
1551
|
+
children: stripTags$1(bib)
|
|
1552
|
+
})
|
|
1553
|
+
});
|
|
1554
|
+
if (detail.notes.length > 0) tabs.push({
|
|
1555
|
+
id: "notes",
|
|
1556
|
+
label: t("detail.notes"),
|
|
1557
|
+
hint: String(detail.notes.length),
|
|
1558
|
+
content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NoteList, {
|
|
1559
|
+
t,
|
|
1560
|
+
notes: detail.notes
|
|
1561
|
+
})
|
|
1562
|
+
});
|
|
1563
|
+
if (detail.attachments.length > 0) tabs.push({
|
|
1564
|
+
id: "attachments",
|
|
1565
|
+
label: t("detail.attachments"),
|
|
1566
|
+
hint: String(detail.attachments.length),
|
|
1567
|
+
content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: detail.attachments.map((attachment) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1568
|
+
type: "button",
|
|
1569
|
+
onClick: () => onOpenItem(attachment.key),
|
|
1570
|
+
style: linkRowStyle,
|
|
1571
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1572
|
+
style: {
|
|
1573
|
+
flex: 1,
|
|
1574
|
+
textAlign: "left",
|
|
1575
|
+
wordBreak: "break-word"
|
|
1576
|
+
},
|
|
1577
|
+
children: attachment.title
|
|
1578
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1579
|
+
style: {
|
|
1580
|
+
opacity: .55,
|
|
1581
|
+
flexShrink: 0
|
|
1582
|
+
},
|
|
1583
|
+
children: [attachment.contentType, attachment.size > 0 ? ` · ${Math.round(attachment.size / 1024)} KB` : ""]
|
|
1584
|
+
})]
|
|
1585
|
+
}, attachment.key)) })
|
|
1586
|
+
});
|
|
1587
|
+
const hasBottom = tabs.length > 0;
|
|
1295
1588
|
function clampBodyPercent(next) {
|
|
1296
1589
|
return Math.min(Math.max(next, BODY_PERCENT_MIN), BODY_PERCENT_MAX);
|
|
1297
1590
|
}
|
|
@@ -1349,7 +1642,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1349
1642
|
children: [
|
|
1350
1643
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1351
1644
|
style: {
|
|
1352
|
-
flex:
|
|
1645
|
+
flex: hasBottom ? `0 0 ${bodyPercent}%` : "1 1 auto",
|
|
1353
1646
|
minHeight: 0,
|
|
1354
1647
|
display: "flex",
|
|
1355
1648
|
flexDirection: "column",
|
|
@@ -1411,45 +1704,37 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1411
1704
|
children: detail.tags.join("、")
|
|
1412
1705
|
}),
|
|
1413
1706
|
detail.abstract !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1414
|
-
style: {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1707
|
+
style: {
|
|
1708
|
+
marginTop: 12,
|
|
1709
|
+
paddingBottom: 12
|
|
1710
|
+
},
|
|
1711
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1712
|
+
style: sectionToggleRowStyle,
|
|
1713
|
+
children: [
|
|
1714
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1715
|
+
style: {
|
|
1716
|
+
...sectionTitleStyle,
|
|
1717
|
+
margin: 0
|
|
1718
|
+
},
|
|
1719
|
+
children: t("detail.abstract")
|
|
1720
|
+
}),
|
|
1721
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { flex: 1 } }),
|
|
1722
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1723
|
+
type: "button",
|
|
1724
|
+
onClick: () => setAbstractOpen((open) => !open),
|
|
1725
|
+
"aria-expanded": abstractOpen,
|
|
1726
|
+
"aria-label": abstractOpen ? t("detail.abstractCollapse") : t("detail.abstractExpand"),
|
|
1727
|
+
style: sectionToggleButtonStyle,
|
|
1728
|
+
children: abstractOpen ? "▴" : "▾"
|
|
1729
|
+
})
|
|
1730
|
+
]
|
|
1731
|
+
}), abstractOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1419
1732
|
style: {
|
|
1420
|
-
margin: 0,
|
|
1733
|
+
margin: "4px 0 0",
|
|
1421
1734
|
opacity: .85
|
|
1422
1735
|
},
|
|
1423
1736
|
children: detail.abstract
|
|
1424
1737
|
})]
|
|
1425
|
-
}),
|
|
1426
|
-
detail.attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1427
|
-
style: {
|
|
1428
|
-
marginTop: 14,
|
|
1429
|
-
paddingBottom: 14
|
|
1430
|
-
},
|
|
1431
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1432
|
-
style: sectionTitle,
|
|
1433
|
-
children: t("detail.attachments")
|
|
1434
|
-
}), detail.attachments.map((attachment) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1435
|
-
type: "button",
|
|
1436
|
-
onClick: () => onOpenItem(attachment.key),
|
|
1437
|
-
style: linkRowStyle,
|
|
1438
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1439
|
-
style: {
|
|
1440
|
-
flex: 1,
|
|
1441
|
-
textAlign: "left",
|
|
1442
|
-
wordBreak: "break-word"
|
|
1443
|
-
},
|
|
1444
|
-
children: attachment.title
|
|
1445
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1446
|
-
style: {
|
|
1447
|
-
opacity: .55,
|
|
1448
|
-
flexShrink: 0
|
|
1449
|
-
},
|
|
1450
|
-
children: [attachment.contentType, attachment.size > 0 ? ` · ${Math.round(attachment.size / 1024)} KB` : ""]
|
|
1451
|
-
})]
|
|
1452
|
-
}, attachment.key))]
|
|
1453
1738
|
})
|
|
1454
1739
|
]
|
|
1455
1740
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
@@ -1461,7 +1746,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1461
1746
|
padding: "2px 14px 14px"
|
|
1462
1747
|
},
|
|
1463
1748
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h3", {
|
|
1464
|
-
style:
|
|
1749
|
+
style: sectionTitleStyle,
|
|
1465
1750
|
children: [t("detail.fulltext"), fulltext !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1466
1751
|
style: {
|
|
1467
1752
|
opacity: .55,
|
|
@@ -1529,7 +1814,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1529
1814
|
})]
|
|
1530
1815
|
})]
|
|
1531
1816
|
}),
|
|
1532
|
-
|
|
1817
|
+
hasBottom && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1533
1818
|
role: "separator",
|
|
1534
1819
|
"aria-orientation": "horizontal",
|
|
1535
1820
|
onPointerDown: onSplitterDown,
|
|
@@ -1553,35 +1838,18 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onOpenItem }) {
|
|
|
1553
1838
|
background: splitHover || dragRef.current !== null ? "rgba(80,140,255,0.75)" : "rgba(127,127,127,0.2)"
|
|
1554
1839
|
} })
|
|
1555
1840
|
}),
|
|
1556
|
-
|
|
1841
|
+
hasBottom && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1557
1842
|
style: {
|
|
1558
1843
|
flex: 1,
|
|
1559
1844
|
minHeight: 0,
|
|
1560
|
-
|
|
1561
|
-
|
|
1845
|
+
display: "flex",
|
|
1846
|
+
flexDirection: "column"
|
|
1562
1847
|
},
|
|
1563
|
-
children:
|
|
1564
|
-
style: sectionTitle,
|
|
1565
|
-
children: t("detail.bibTitle")
|
|
1566
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1567
|
-
style: {
|
|
1568
|
-
margin: 0,
|
|
1569
|
-
opacity: .85,
|
|
1570
|
-
fontSize: 12.5,
|
|
1571
|
-
whiteSpace: "pre-wrap"
|
|
1572
|
-
},
|
|
1573
|
-
children: stripTags$1(bib)
|
|
1574
|
-
})]
|
|
1848
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DetailTabs, { tabs })
|
|
1575
1849
|
})
|
|
1576
1850
|
]
|
|
1577
1851
|
});
|
|
1578
1852
|
}
|
|
1579
|
-
const sectionTitle = {
|
|
1580
|
-
margin: "0 0 6px",
|
|
1581
|
-
fontSize: 12.5,
|
|
1582
|
-
fontWeight: 600,
|
|
1583
|
-
opacity: .75
|
|
1584
|
-
};
|
|
1585
1853
|
const linkRowStyle = {
|
|
1586
1854
|
display: "flex",
|
|
1587
1855
|
gap: 8,
|
|
@@ -1892,10 +2160,8 @@ function ZoteroPane({ t, inputActions }) {
|
|
|
1892
2160
|
}),
|
|
1893
2161
|
selectedCollection.scope === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
1894
2162
|
style: {
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
fontWeight: 600,
|
|
1898
|
-
opacity: .75
|
|
2163
|
+
...sectionTitleStyle,
|
|
2164
|
+
margin: "16px 0 6px"
|
|
1899
2165
|
},
|
|
1900
2166
|
children: t("detail.bibTitle")
|
|
1901
2167
|
}), collectionBib === null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
package/lib/zotero/client.d.ts
CHANGED
|
@@ -40,6 +40,9 @@ interface RawItemData {
|
|
|
40
40
|
collections?: string[];
|
|
41
41
|
contentType?: string;
|
|
42
42
|
filename?: string;
|
|
43
|
+
/** 笔记正文(HTML),仅 `itemType === 'note'` 有。 */
|
|
44
|
+
note?: string;
|
|
45
|
+
dateModified?: string;
|
|
43
46
|
}
|
|
44
47
|
interface RawEnclosure {
|
|
45
48
|
href?: string;
|
|
@@ -61,6 +64,8 @@ interface RawItem {
|
|
|
61
64
|
};
|
|
62
65
|
data?: RawItemData;
|
|
63
66
|
}
|
|
67
|
+
/** 清洗笔记正文 HTML。 */
|
|
68
|
+
export declare function sanitizeNoteHtml(html: string): string;
|
|
64
69
|
/** 探活 Zotero 本地 API,返回版本信息;不可达时 running=false。 */
|
|
65
70
|
export declare function probe(): Promise<ZoteroHealth['zotero']>;
|
|
66
71
|
/** 用 TCP 连接探活 Zotero 集成 MCP 端口(轻量、不建会话)。 */
|
|
@@ -104,7 +109,7 @@ export declare function getItemChildren(key: string): Promise<RawItem[]>;
|
|
|
104
109
|
export declare function getItemFulltext(attachmentKey: string): Promise<ZoteroFulltext | null>;
|
|
105
110
|
/** 单条条目的 CSL HTML(`format=bib`);失败返回 null。 */
|
|
106
111
|
export declare function getItemBib(key: string, style: string): Promise<string | null>;
|
|
107
|
-
/** 条目详情:元数据 + 附件 + 首个可读附件全文 + CSL。 */
|
|
112
|
+
/** 条目详情:元数据 + 附件 + 笔记 + 首个可读附件全文 + CSL。 */
|
|
108
113
|
export declare function getItemDetail(key: string, style: string): Promise<ZoteroItemDetail>;
|
|
109
114
|
/**
|
|
110
115
|
* 整目录参考文献列表。
|
package/lib/zotero/client.js
CHANGED
|
@@ -90,6 +90,88 @@ function toAttachment(raw) {
|
|
|
90
90
|
size: raw.links?.enclosure?.length ?? 0,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
+
// ---- 笔记正文清洗 ------------------------------------------------------------
|
|
94
|
+
/**
|
|
95
|
+
* 笔记正文清洗。
|
|
96
|
+
*
|
|
97
|
+
* Zotero 的笔记 HTML 里塞了大量冗余标记,必须处理后再交给前端渲染:
|
|
98
|
+
* - `data-citation-items`:整份被引条目的 JSON(URL 编码),单条笔记能占几 KB;
|
|
99
|
+
* - `data-pid` / `data-first-child` 等 ProseMirror 内部标记;
|
|
100
|
+
* - `data-original-token` / `data-rawwidth` 等图片内部属性。
|
|
101
|
+
*
|
|
102
|
+
* 同时去掉脚本类标签与事件属性,避免正文里的原始 HTML 被直接注入 DOM。
|
|
103
|
+
* 图片的 `src` 保留(外链图),并去掉 `data-original-token` 等冗余属性。
|
|
104
|
+
*/
|
|
105
|
+
const NOTE_BLOCKED_TAGS = /<(script|style|noscript|iframe|object|embed)\b[\s\S]*?<\/\1\s*>/giu;
|
|
106
|
+
/** 无闭合标签的阻塞元素(base / link / meta 等)。 */
|
|
107
|
+
const NOTE_BLOCKED_VOID = /<\/?(?:base|link|meta)\b[^>]*>/giu;
|
|
108
|
+
const NOTE_EVENT_ATTR = /\s+on[a-z]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/giu;
|
|
109
|
+
const NOTE_DATA_ATTR = /\s+data-[a-z-]+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/giu;
|
|
110
|
+
const NOTE_JS_URL = /\s+(?:href|src)\s*=\s*(?:"javascript:[^"]*"|'javascript:[^']*'|javascript:[^\s>]+)/giu;
|
|
111
|
+
/** 笔记正文最大字节数,超出截断。 */
|
|
112
|
+
const NOTE_MAX_BYTES = 200 * 1024;
|
|
113
|
+
/** HTML 实体解码表(用字符码拼装,避免源码里直接写实体被二次解码)。 */
|
|
114
|
+
const NAMED_ENTITIES = {
|
|
115
|
+
nbsp: ' ',
|
|
116
|
+
amp: String.fromCharCode(38),
|
|
117
|
+
lt: String.fromCharCode(60),
|
|
118
|
+
gt: String.fromCharCode(62),
|
|
119
|
+
quot: String.fromCharCode(34),
|
|
120
|
+
apos: String.fromCharCode(39),
|
|
121
|
+
};
|
|
122
|
+
/** 解码 HTML 实体(命名实体 + 数字实体)。 */
|
|
123
|
+
function decodeEntities(text) {
|
|
124
|
+
return text.replace(/&(#x[0-9a-f]+|#[0-9]+|[a-z]+);/giu, (match, body) => {
|
|
125
|
+
if (body.startsWith('#x') || body.startsWith('#X')) {
|
|
126
|
+
const code = Number.parseInt(body.slice(2), 16);
|
|
127
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
128
|
+
}
|
|
129
|
+
if (body.startsWith('#')) {
|
|
130
|
+
const code = Number.parseInt(body.slice(1), 10);
|
|
131
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : match;
|
|
132
|
+
}
|
|
133
|
+
return NAMED_ENTITIES[body.toLowerCase()] ?? match;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/** 去标签后取纯文本(用于笔记标题摘要)。 */
|
|
137
|
+
function toPlainText(html) {
|
|
138
|
+
return decodeEntities(html
|
|
139
|
+
.replace(/<[^>]*>/gu, ' ')
|
|
140
|
+
.replace(/ /giu, ' '))
|
|
141
|
+
.replace(/\s+/gu, ' ')
|
|
142
|
+
.trim();
|
|
143
|
+
}
|
|
144
|
+
/** 清洗笔记正文 HTML。 */
|
|
145
|
+
export function sanitizeNoteHtml(html) {
|
|
146
|
+
return html
|
|
147
|
+
.replace(NOTE_BLOCKED_TAGS, '')
|
|
148
|
+
.replace(NOTE_BLOCKED_VOID, '')
|
|
149
|
+
.replace(NOTE_EVENT_ATTR, '')
|
|
150
|
+
.replace(NOTE_JS_URL, '')
|
|
151
|
+
.replace(NOTE_DATA_ATTR, '')
|
|
152
|
+
// 笔记里的图是外链图,限宽避免撑破右栏。
|
|
153
|
+
.replace(/<img\b([^>]*)>/giu, (match, attrs) => attrs.includes('style=') ? match : `<img${attrs} style="max-width:100%;height:auto">`)
|
|
154
|
+
.trim();
|
|
155
|
+
}
|
|
156
|
+
/** 笔记标题:正文纯文本的前 60 个字符(笔记条目本身没有 title 字段)。 */
|
|
157
|
+
function noteTitle(html) {
|
|
158
|
+
const text = toPlainText(html);
|
|
159
|
+
if (text === '')
|
|
160
|
+
return '(空笔记)';
|
|
161
|
+
return text.length > 60 ? `${text.slice(0, 60)}…` : text;
|
|
162
|
+
}
|
|
163
|
+
function toNote(raw) {
|
|
164
|
+
const html = sanitizeNoteHtml(raw.data?.note ?? '');
|
|
165
|
+
const maxBytes = NOTE_MAX_BYTES;
|
|
166
|
+
const truncated = html.length > maxBytes;
|
|
167
|
+
return {
|
|
168
|
+
key: raw.key,
|
|
169
|
+
title: noteTitle(html),
|
|
170
|
+
html: truncated ? html.slice(0, maxBytes) : html,
|
|
171
|
+
dateModified: raw.data?.dateModified ?? '',
|
|
172
|
+
truncated,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
93
175
|
function toSummary(raw) {
|
|
94
176
|
const data = raw.data ?? {};
|
|
95
177
|
const itemType = data.itemType ?? '';
|
|
@@ -98,9 +180,14 @@ function toSummary(raw) {
|
|
|
98
180
|
: itemType === 'note'
|
|
99
181
|
? false
|
|
100
182
|
: (raw.meta?.numChildren ?? 0) > 0;
|
|
183
|
+
// 笔记没有 title 字段,用正文首段摘要当标题。
|
|
184
|
+
const title = data.title
|
|
185
|
+
|| data.filename
|
|
186
|
+
|| (itemType === 'note' ? noteTitle(data.note ?? '') : '')
|
|
187
|
+
|| '(无标题)';
|
|
101
188
|
return {
|
|
102
189
|
key: raw.key,
|
|
103
|
-
title
|
|
190
|
+
title,
|
|
104
191
|
creators: raw.meta?.creatorSummary ?? '',
|
|
105
192
|
year: yearOf(raw.meta, data),
|
|
106
193
|
itemType,
|
|
@@ -322,7 +409,7 @@ export async function getItemBib(key, style) {
|
|
|
322
409
|
return null;
|
|
323
410
|
}
|
|
324
411
|
}
|
|
325
|
-
/** 条目详情:元数据 + 附件 + 首个可读附件全文 + CSL。 */
|
|
412
|
+
/** 条目详情:元数据 + 附件 + 笔记 + 首个可读附件全文 + CSL。 */
|
|
326
413
|
export async function getItemDetail(key, style) {
|
|
327
414
|
const { body: raw } = await requestJson(`${libraryBase()}/items/${encode(key)}`);
|
|
328
415
|
const data = raw.data ?? {};
|
|
@@ -331,6 +418,9 @@ export async function getItemDetail(key, style) {
|
|
|
331
418
|
const children = itemType === 'attachment' ? [] : await getItemChildren(key);
|
|
332
419
|
const childAttachments = children.filter((c) => c.data?.itemType === 'attachment');
|
|
333
420
|
const attachments = itemType === 'attachment' ? [toAttachment(raw), ...childAttachments.map(toAttachment)] : childAttachments.map(toAttachment);
|
|
421
|
+
// 笔记是子条目(itemType=note);条目本身就是笔记时(独立笔记),正文即自身。
|
|
422
|
+
const childNotes = children.filter((c) => c.data?.itemType === 'note');
|
|
423
|
+
const notes = (itemType === 'note' ? [raw] : childNotes).map(toNote);
|
|
334
424
|
const readable = itemType === 'attachment'
|
|
335
425
|
? raw
|
|
336
426
|
: childAttachments.find((c) => c.data?.contentType === 'application/pdf') ?? childAttachments[0];
|
|
@@ -339,7 +429,7 @@ export async function getItemDetail(key, style) {
|
|
|
339
429
|
return {
|
|
340
430
|
key: raw.key,
|
|
341
431
|
itemType,
|
|
342
|
-
title: data.title || data.filename || '(无标题)',
|
|
432
|
+
title: data.title || data.filename || (itemType === 'note' ? notes[0]?.title ?? '(无标题)' : '(无标题)'),
|
|
343
433
|
creators: (data.creators ?? []).map(creatorName).filter((n) => n !== ''),
|
|
344
434
|
year: yearOf(raw.meta, data),
|
|
345
435
|
publicationTitle: data.publicationTitle ?? '',
|
|
@@ -349,6 +439,7 @@ export async function getItemDetail(key, style) {
|
|
|
349
439
|
tags: (data.tags ?? []).map((tag) => tag.tag ?? '').filter((tag) => tag !== ''),
|
|
350
440
|
collections: data.collections ?? [],
|
|
351
441
|
attachments,
|
|
442
|
+
notes,
|
|
352
443
|
fulltext,
|
|
353
444
|
bib,
|
|
354
445
|
};
|
package/lib/zotero/types.d.ts
CHANGED
|
@@ -39,6 +39,17 @@ export interface ZoteroAttachment {
|
|
|
39
39
|
contentType: string;
|
|
40
40
|
size: number;
|
|
41
41
|
}
|
|
42
|
+
/** 条目下的一条笔记(子条目 `itemType: "note"`)。 */
|
|
43
|
+
export interface ZoteroNote {
|
|
44
|
+
key: string;
|
|
45
|
+
/** 笔记标题:取正文首段纯文本摘要(笔记本身无标题字段)。 */
|
|
46
|
+
title: string;
|
|
47
|
+
/** 清洗后的正文 HTML(已剥离引用数据属性等,仅保留排版与图片)。 */
|
|
48
|
+
html: string;
|
|
49
|
+
dateModified: string;
|
|
50
|
+
/** 正文超长被截断时为 true。 */
|
|
51
|
+
truncated: boolean;
|
|
52
|
+
}
|
|
42
53
|
/** 详情页数据。 */
|
|
43
54
|
export interface ZoteroItemDetail {
|
|
44
55
|
key: string;
|
|
@@ -54,6 +65,8 @@ export interface ZoteroItemDetail {
|
|
|
54
65
|
/** 所属分类 key 列表。 */
|
|
55
66
|
collections: string[];
|
|
56
67
|
attachments: ZoteroAttachment[];
|
|
68
|
+
/** 该条目下的笔记(子条目 `itemType: "note"`)。 */
|
|
69
|
+
notes: ZoteroNote[];
|
|
57
70
|
fulltext: ZoteroFulltext | null;
|
|
58
71
|
bib: string | null;
|
|
59
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-zotero",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Bring your local Zotero library into DeepSeek Harness: a read-only sidebar panel for browsing, searching and inserting citations into conversation drafts, plus a self-hosted integration-MCP bridge that registers Zotero tools to the model with per-tool toggles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|