docnest 0.1.22 → 0.1.24

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 CHANGED
@@ -84,6 +84,8 @@ export default defineConfig({
84
84
 
85
85
  受限模式只移除 DocNest 提供的页面入口和脚本,不承诺对浏览器开发者工具或系统级截图提供绝对防护。
86
86
 
87
+ 页面水印使用 4% 透明度,保持可辨识而不遮挡正文和图表。Mermaid 代码围栏按独立图表渲染,不继承普通代码块的等宽字体;节点内的 HTML 换行与图表字体测量保持一致。
88
+
87
89
  ### 极简单口令授权
88
90
 
89
91
  需要让文档中心只对知道口令的人开放时,可以启用单口令授权:
@@ -145,6 +147,7 @@ startServer(3000)
145
147
  Markdown 或 HTML 中明确引用的本地附件,不按文件扩展名设置业务白名单;外链、文档链接、隐藏路径、路径穿越和代码块中的伪引用会被忽略,缺失的附件默认会让构建失败。
146
148
  常见凭据文件(如 `.env`、私钥和证书容器)属于公共安全阻断项,即使被误写进文档链接也不会进入静态产物。
147
149
  静态生成 HTML 时,可再调用 `rewriteDocumentAttachmentUrls`,将正文中的附件链接统一改写到 `/doc-asset/` 端点。
150
+ 正文中的附件链接使用浏览器完整导航;独立 HTML 页面保持自己的样式和脚本,不进入 Markdown 局部刷新流程,挂载在子路径时也遵循这一规则。
148
151
 
149
152
  ## 开发
150
153
 
package/dist/server.js CHANGED
@@ -188,10 +188,6 @@ const md = new MarkdownIt({
188
188
  linkify: true,
189
189
  typographer: true,
190
190
  highlight: function (str, lang) {
191
- // 特殊处理 Mermaid 图表
192
- if (lang === 'mermaid') {
193
- return `<div class="mermaid">${str}</div>`;
194
- }
195
191
  // 其他代码块使用 highlight.js
196
192
  if (lang && hljs.getLanguage(lang)) {
197
193
  try {
@@ -202,6 +198,16 @@ const md = new MarkdownIt({
202
198
  return `<pre class="hljs"><code>${md.utils.escapeHtml(str)}</code></pre>`;
203
199
  },
204
200
  });
201
+ // Mermaid is a diagram, not highlighted code. A code/pre ancestor changes
202
+ // the inherited font after Mermaid measures HTML labels, clipping their text.
203
+ const renderCodeFence = md.renderer.rules.fence;
204
+ md.renderer.rules.fence = function (tokens, index, options, env, renderer) {
205
+ const token = tokens[index];
206
+ if (token.info.trim().split(/\s+/)[0] === 'mermaid') {
207
+ return `<div class="mermaid">${md.utils.escapeHtml(token.content)}</div>\n`;
208
+ }
209
+ return renderCodeFence(tokens, index, options, env, renderer);
210
+ };
205
211
  function slugifyHeading(text) {
206
212
  return (text || '')
207
213
  .replace(/`([^`]+)`/g, '$1')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docnest",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "description": "可复用的本地 Markdown 文档中心",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1339,6 +1339,9 @@ body[data-theme="dark"] .not-found-path {
1339
1339
 
1340
1340
  /* Mermaid 图表样式 */
1341
1341
  .markdown-body .mermaid {
1342
+ /* Match Mermaid's measurement fallback when a diagram font is omitted or
1343
+ rejected by its directive sanitizer. Explicit SVG fonts still take priority. */
1344
+ font-family: "trebuchet ms", verdana, arial, sans-serif;
1342
1345
  margin: 24px 0;
1343
1346
  text-align: center;
1344
1347
  background: var(--linear-bg-subtle);
@@ -89,7 +89,7 @@ html.docnest-restricted .markdown-body .mermaid-download-btn {
89
89
  color: var(--linear-text, rgba(15, 23, 42, 0.42));
90
90
  font: 700 clamp(0.75rem, 1.5vw, 1.5rem)/1 var(--doc-font-mono);
91
91
  letter-spacing: 0.08em;
92
- opacity: 0.12;
92
+ opacity: 0.04;
93
93
  transform: rotate(-24deg);
94
94
  white-space: nowrap;
95
95
  }
@@ -294,6 +294,15 @@
294
294
  // 检查是否是文档系统内的链接
295
295
  const href = link.getAttribute('href');
296
296
  if (!href) return;
297
+
298
+ // Assets, including standalone HTML pages, need full browser navigation;
299
+ // they do not contain the Markdown article expected by navigateToDoc.
300
+ try {
301
+ const linkUrl = new URL(href, document.baseURI || window.location.href);
302
+ if (/(^|\/)doc-asset\//.test(linkUrl.pathname)) return;
303
+ } catch (_) {
304
+ return;
305
+ }
297
306
 
298
307
  // 判断是否是文档系统内的链接(排除外部链接、锚点、目录页链接)
299
308
  const isDocLink = (href.startsWith('/doc?') ||