Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ SVG 只能当文本看,PDF 只能交给外部应用。
- **SVG 跟随编辑**。SVG 文件按 Markdown 的方式打开:源码与图片两栏,标签栏末尾切换源码 / 两者 / 仅图片。
编辑后最多每 150 毫秒把文本交给页面一次,地址带上编辑版本号,避免引擎画出缓存的旧图;更新时保持用户的
缩放和滚动位置。改成画不出来的内容时保留上一张图,只有从未画成功过才显示失败提示。超过 4 MiB 不绘制。
- **Markdown 目录画在页面里**。web 页的目录是页面右上角的浮动大纲(`assets/markdown.js`):页面从渲染结果的
标题建树,按层级缩进,可以折叠,当前章节随页面滚动高亮,选中标题时像用户滚动页面一样回报 `scrolled`,
宿主照常把源码带到那一行。标签栏的“目录”按钮只发 `outline{open}` 打开或关闭;用户在页面里按 Escape 关闭时,
页面回报 `outline{open:false}`,宿主更新按钮状态,不再回发。大纲按固定行高只创建视口附近的行,长文档也不会
一次生成上千个节点;折叠状态按“父级、层级、标题文字、同名序号”保存,重新渲染后保留。原生页仍用 Viva 的
弹出列表,选中后关闭。
- **页面生命周期**。文档或标签打开期间页面一直存在;没有被这一帧声明的页面隐藏起来,保留滚动位置和排版,
切回来时原样显示。隐藏的页面最多保留 6 个,超出时关闭隐藏最久的那个,标签再次显示时重新打开。
窗口的 web host 还没准备好、系统没有 web 引擎、或者某个页面打开失败后,编辑区改用原生预览。
Expand All @@ -64,6 +70,9 @@ SVG 只能当文本看,PDF 只能交给外部应用。
- **用 `file://` 或把项目目录映射成虚拟主机**:页面能读到任意文件,拒绝,原因见上面的反例。
- **所有平台都用 Go 解码图片、用 Go 库栅格化 SVG**:Go 标准库不支持 WebP、TIFF、HEIC,现有的 Go SVG
栅格化库不支持文字、滤镜和大部分 CSS,显示结果和浏览器不一致,拒绝。Go 画布只保留给 Linux。
- **web 页的目录也用 Viva 弹出列表画在页面上方**:弹层选中一个标题就关闭,不能一边看目录一边跳转;
要高亮当前章节,宿主还得逐帧接收页面滚动位置再重画。页面本来就知道自己的滚动位置和标题位置,
所以改为页面自己画,宿主只发开关。
- **隐藏的页面立即关闭,或者全部常驻**:立即关闭会在每次切标签时丢掉滚动位置并重新排版;全部常驻会让每个
打开过的预览都占一个 web 进程的内存。折中为最多保留 6 个隐藏页面。

Expand All @@ -79,6 +88,8 @@ SVG 和 PDF 可以在编辑区直接查看;页面能读到什么完全由宿
`THIRD_PARTY_NOTICES.md` 和许可证文件。
- 图片的缩放规则在 JS 和 Go 中各有一份。它们属于视图布局,需要逐帧响应滚轮和拖动,不进 Core;
修改时两边一起改,并分别由 `TestImageFitScaleKeepsThePaddingAndNeverEnlarges` 和页面脚本覆盖。
- Markdown 目录有两种外观:web 页是可折叠、跟随当前章节的大纲,Linux 原生页是按级别缩进的弹出列表。
标题树和折叠只存在于页面脚本,属于视图呈现,不进 Core;两边的标题都来自同一份渲染结果或源码标题。
- Linux 仍然看不到 HTML 和富内容,SVG 只能看源码,PDF 只能交给外部应用。
- Windows 上 WebView2 能否解码 TIFF、HEIC,以及自定义协议下的 PDF 查看器是否可用,还没有真机验证;
解码失败时会落到“无法显示”和“用外部应用打开”。
Expand All @@ -90,13 +101,17 @@ SVG 和 PDF 可以在编辑区直接查看;页面能读到什么完全由宿
渲染与双向滚动、隐藏页面上限、web view 打不开时回落原生、图片查看器的工具栏与缩放、PDF 查看器、
SVG 跟随编辑与失败保留,以及没有 web 引擎时的 Go 画布。
- `scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认打开预览不会改写发行目录。
- 平台功能矩阵 `embedded-viewers`、`markdown-rendering`、`markdown-images-links` 记录了待真机验收的步骤。
- `TestMarkdownWebPageRendersCoreHTMLAndScrollsWithTheSource` 覆盖目录按钮与页面之间的 `outline` 消息,
`TestMarkdownContentsIndentsHeadingsByLevel` 覆盖原生弹出列表按级别缩进且行不重叠。
- 平台功能矩阵 `embedded-viewers`、`markdown-rendering`、`markdown-images-links`、`markdown-preview-outline`
记录了待真机验收的步骤。

## 适用范围

- `desktop/internal/webpreview/`
- `desktop/internal/workbench/preview_pages.go`
- `desktop/internal/workbench/markdown_web.go`
- `desktop/internal/workbench/markdown_preview.go`
- `desktop/internal/workbench/viewer_web.go`
- `desktop/internal/workbench/viewer_image.go`
- `desktop/internal/workbench/svg_preview.go`
Expand Down
89 changes: 89 additions & 0 deletions desktop/internal/webpreview/assets/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,95 @@ audio { width: min(100%, 520px); }
.diagram-error { margin: 0 0 0.75em; color: var(--alert-caution); font-size: 0.84em; }
.diagram-source-fallback { margin-top: 0.75em; }

/* The outline floats at the page's top right, over the margin where the window is wide enough.
Its rows are a fixed height: the script lays out only those in view (markdown.js). */
.outline {
position: fixed;
z-index: 50;
top: 10px;
right: 12px;
display: flex;
flex-direction: column;
width: min(280px, calc(100vw - 24px));
max-height: calc(100vh - 20px);
border: 1px solid var(--border);
border-radius: 8px;
background: var(--page);
color: var(--text);
box-shadow: 0 8px 28px rgba(15, 18, 24, 0.14), 0 1px 3px rgba(15, 18, 24, 0.08);
font-size: 13px;
line-height: 1.3;
}

:root[data-theme="dark"] .outline {
background: color-mix(in srgb, var(--lithe-foreground, #dfe1e5) 3%, var(--page));
box-shadow: 0 10px 32px rgba(0, 0, 0, 0.42), 0 1px 3px rgba(0, 0, 0, 0.3);
}

.outline[hidden] { display: none; }

.outline-title {
flex: none;
margin: 0 14px;
padding: 11px 2px 9px;
border-bottom: 1px solid var(--border);
font-size: 15px;
font-weight: 600;
user-select: none;
}

.outline-tree {
flex: 0 1 auto;
min-height: 0;
overflow-x: hidden;
overflow-y: auto;
padding: 6px;
outline: none;
overscroll-behavior: contain;
}

.outline-rows { position: relative; }

.outline-item {
position: absolute;
left: 0;
right: 0;
display: flex;
align-items: center;
height: 28px;
padding-right: 8px;
border-radius: 5px;
color: var(--text);
cursor: pointer;
user-select: none;
white-space: nowrap;
}

.outline-item:hover { background: var(--surface); }
.outline-item.active { background: var(--accent-soft); color: var(--accent); }
.outline-tree:focus-visible .outline-item.focused { box-shadow: inset 0 0 0 1.5px var(--accent); }

.outline-toggle {
display: grid;
flex: none;
place-items: center;
width: 18px;
height: 18px;
margin-right: 2px;
border-radius: 4px;
color: var(--muted);
}

.outline-toggle:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.outline-toggle svg { width: 10px; height: 10px; transition: transform 0.12s ease; }
.outline-item[aria-expanded="true"] .outline-toggle svg { transform: rotate(90deg); }

.outline-text {
overflow: hidden;
min-width: 0;
text-overflow: ellipsis;
}

.image-viewer {
position: fixed;
z-index: 100;
Expand Down
6 changes: 6 additions & 0 deletions desktop/internal/webpreview/assets/markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
</head>
<body>
<main id="content" class="markdown-body"></main>
<aside id="outline" class="outline" aria-labelledby="outline-title" hidden>
<div id="outline-title" class="outline-title"></div>
<div id="outline-tree" class="outline-tree" role="tree" tabindex="0" aria-labelledby="outline-title">
<div id="outline-rows" class="outline-rows" role="none"></div>
</div>
</aside>
<div id="image-viewer" class="image-viewer" role="dialog" aria-modal="true" hidden>
<button id="image-close" class="image-close" type="button">×</button>
<img id="image-full" alt="">
Expand Down
Loading
Loading