3 Commits

3 changed files with 148 additions and 9 deletions

View File

@@ -18,7 +18,8 @@
- 鼠标移到标题左侧出现折角箭头,点击即可折叠到下一个同级标题(H1–H6);
- `Ctrl+滚轮` 缩放正文,5% 一档、范围 50%–300%,并记住上次的缩放。
- **代码块始终是深色**(Visual Studio Dark 配色),浅色主题下也保持深色,读代码不刺眼;行内代码仍跟随系统主题。
- **渲染齐全**:GFM、表格、任务列表、front matter、GitHub Alerts、`==高亮==`、KaTeX 公式、Mermaid 图。
- **渲染齐全**:GFM、表格、任务列表、脚注、定义列表、front matter、GitHub Alerts、`==高亮==`、KaTeX 公式、Mermaid 图。
- **对 AI 输出友好**:单个换行按换行显示(空行仍然是段落);这是本工具有意采用的方言,和严格 CommonMark 查看器不同。
- **单实例**:再次双击文件会交给已打开的窗口,不会开一堆进程。
## 下载与运行
@@ -55,6 +56,8 @@
| 工具栏 | 移除 Open / Print / Find 按钮,只保留 编辑 / 缩放;快捷键和空状态入口保留 |
| 缩放 | 支持 `Ctrl+滚轮`,步进 5%、范围 50%–300%,并跨重启记住 |
| 代码配色 | GitHub 浅/深主题换成始终深色的 VS Dark,只换 CSS、不引新库 |
| 换行 | 单个换行按换行显示(AI 输出常见),空行仍是段落分隔;有意的方言差异 |
| 脚注/定义列表 | 开启 GFM 脚注与定义列表扩展,并补浅色/深色样式 |
| 标题折叠 | 新增 hover 折角箭头,按标题层级折叠;查找命中会自动展开,打印时全部展开 |
| 只读文件 | 保存失败不再每 700ms 弹窗、不再卡住关闭;关闭时询问是否丢弃修改 |
| 路径处理 | 修复 Windows `\\?\` 前缀污染 Recent / base URL 的问题 |
@@ -70,7 +73,7 @@
- WebView2 Runtime
```powershell
cargo test # 43 个测试
cargo test # 52 个测试
.\agent\scripts\build.ps1 # release 构建 + 校验 + 复制到固定 exe 路径
```
@@ -95,6 +98,7 @@ backup/ 上游源码备份(本地保留,不入 git)
- exe 未签名,首次运行可能被 SmartScreen 拦截。
- 按设计不自动更新,升级方式是手动替换 exe。
- 折叠状态不持久化,每次打开都是全部展开。
- 单换行按换行显示;如果源文件是按固定列硬折行的长段落,预览会保留这些断点,不随窗口宽度重排。
- 只读文件可以看、可以改,但保存会被拒绝(会明确提示,不会卡死)。
## 许可

View File

@@ -1,9 +1,9 @@
# 项目状态(滚动更新)
> 最后更新:2026-10-21 17:41
> 最后更新:2026-10-27 12:05
> 用途:上下文压缩/交接后快速恢复。详细背景见 AGENTS.md、HANDOFF.md、scan-2026-10-21.md、roadmap.md。
>
> **当前:所有已提需求(功能 1–6)完成并部署;短期不再修改。** 下次开工先读第 14 节交接。
> **当前:功能 7(AI 输出方言兼容)已提交 `07ac997`,52 个测试通过;旧实例仍在运行,exe 尚未重建/部署。** 下次开工先读第 14 节交接。
## 1. 仓库
@@ -20,14 +20,15 @@
- `097d2ee` fix: 保存失败不再卡住关闭;正文 padding 48px
- `b01553e` feat: 折叠三角固定尺寸 + 折角箭头(并移除历史截图)
- `7dbd1e8` chore: 截图不入库(.gitignore + AGENTS 规则)
- `07ac997` feat: AI 输出方言兼容(softbreak→`<br>`、脚注、定义列表、BOM)
- 若干 docs 提交(状态/路线图/HANDOFF)
- 忽略:`/target/`、`/MD-Preview-windows-x64.exe`、`/backup/`、`/agent/reports/*.png`
- **不变量**:exe 固定为 `D:\Scripts\md-preview\MD-Preview-windows-x64.exe`,默认 .md 打开方式指向它,不要改名/移动。
## 2. 当前构建/部署状态
- `cargo test`:43 passed / 0 failed。
- 已部署(2026-10-21 17:25 左右):
- `cargo test`:52 passed / 0 failed(2026-10-27,功能 7)。
- 已部署(2026-10-21 17:25 左右,仍是旧版):
- 大小 5,501,440 字节
- SHA256 `F76BC3963BA13BBFC8259BC2B4E3D24468C34E3C9E26491D364D5D364BEDE96C`(快照,不保证可复现)
- 完整性级别 Medium - OK;禁用字符串检查全 0。
@@ -43,6 +44,7 @@
| 4 | 标题 hover 折叠 | 完成并部署 `f74a04b` |
| 5 | 布局微调 + 只读文件保存失败修复 | 完成并部署 `097d2ee` |
| 6 | 折叠三角固定 90% + 折角箭头 | 完成并部署 `b01553e` |
| 7 | AI 输出方言兼容:softbreak→`<br>`、GFM 脚注、定义列表、UTF-8 BOM | 已提交 `07ac997`,52 tests;待构建/部署 |
## 4. 已确认的产品决策
@@ -52,6 +54,8 @@
- 工具栏只剩 编辑 / 缩放;Find 按钮已删,`Ctrl+F` 与查找条保留。
- 标题折叠:三角按钮 hover 才显示;**固定尺寸**(30px 热区、折角箭头 13.5×20,约为原二级标题实心三角的 90%),所有级别一致;点 H2 折到下一个 H2、点 H3 折到下一个 H3(含子级);**不持久化**;不做“全部折叠/展开”UI;查找命中折叠区自动展开;打印强制展开并隐藏按钮。
- 正文/编辑区左右 padding 48px。
- **单换行按换行显示**(softbreak→`<br>`),空行仍是段落分隔;标题内不转换。这是本工具面向 AI 输出的有意方言,和严格 CommonMark 不同;硬折行的长段落会保留断点。
- 开启 GFM 脚注与定义列表;UTF-8 BOM 在渲染前忽略。
- 编辑模式保留 700ms 自动保存 + `Ctrl+S` 立即保存。
## 5. 保存失败(只读文件)处理

View File

@@ -390,6 +390,10 @@ fn md_to_html(md: &str) -> String {
}
fn md_to_html_with_base(md: &str, base_dir: Option<&Path>) -> String {
// A UTF-8 BOM is legal in files but not part of Markdown syntax. Strip it
// before front-matter detection so both `---` metadata and a leading
// heading still parse.
let md = md.strip_prefix('\u{feff}').unwrap_or(md);
let (front_matter, markdown) = split_yaml_front_matter(md)
.map(|(metadata, body)| (Some(metadata), body))
.unwrap_or((None, md));
@@ -398,12 +402,14 @@ fn md_to_html_with_base(md: &str, base_dir: Option<&Path>) -> String {
| Options::ENABLE_TASKLISTS
| Options::ENABLE_HEADING_ATTRIBUTES
| Options::ENABLE_MATH
| Options::ENABLE_GFM;
| Options::ENABLE_GFM
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_DEFINITION_LIST;
let parser = Parser::new_ext(markdown, opts);
let events = embed_local_images(
let events = render_softbreaks_as_hard(embed_local_images(
add_mark_highlights(add_heading_ids(parser.collect())),
base_dir,
);
));
let mut html_out = String::new();
if let Some(metadata) = front_matter {
html_out.push_str(r#"<aside class="front-matter"><pre>"#);
@@ -414,6 +420,29 @@ fn md_to_html_with_base(md: &str, base_dir: Option<&Path>) -> String {
html_out
}
/// AI-generated Markdown often uses a single newline as a visual line break.
/// Treat those soft breaks as hard breaks in normal prose, but keep headings
/// untouched: a multi-line setext heading should stay one visual line.
fn render_softbreaks_as_hard<'a>(events: Vec<MdEvent<'a>>) -> Vec<MdEvent<'a>> {
let mut heading_depth = 0usize;
let mut out = Vec::with_capacity(events.len());
for event in events {
match &event {
MdEvent::Start(Tag::Heading { .. }) => heading_depth += 1,
MdEvent::End(TagEnd::Heading(_)) => {
heading_depth = heading_depth.saturating_sub(1);
}
MdEvent::SoftBreak if heading_depth == 0 => {
out.push(MdEvent::HardBreak);
continue;
}
_ => {}
}
out.push(event);
}
out
}
fn split_yaml_front_matter(md: &str) -> Option<(&str, &str)> {
let mut lines = md.split_inclusive('\n');
let first = lines.next()?;
@@ -1172,6 +1201,18 @@ body.has-tabs {{ --chrome-top: 50px; }}
#preview a:hover {{ text-decoration: underline; }}
#preview ul, #preview ol {{ padding-left: 2em; }}
#preview input[type="checkbox"] {{ margin-right: 6px; }}
#preview dl {{ margin: 1em 0; }}
#preview dt {{ font-weight: 600; }}
#preview dd {{ margin: 0 0 .6em 1.5em; }}
#preview .footnote-reference {{ font-size: .75em; }}
#preview .footnote-definition {{
margin-top: 1.5em;
padding-top: .75em;
border-top: 1px solid #e1e4e8;
color: #59636e;
font-size: .9em;
}}
#preview .footnote-definition-label {{ margin-right: .35em; font-weight: 600; }}
.empty {{ display: flex; flex-direction: column; align-items: center; justify-content: center;
min-height: 60vh; color: #999; font-size: 18px; gap: 12px; text-align: center; }}
.empty.has-recent {{
@@ -1310,6 +1351,7 @@ body.empty .toolbar {{ display: none !important; }}
#preview .front-matter pre {{ background: transparent !important; }}
#preview code:not(pre code) {{ background: #2d2d2d; }}
#preview blockquote {{ border-color: #444; color: #aaa; }}
#preview .footnote-definition {{ border-color: #444; color: #aaa; }}
#preview .markdown-alert-note,
#preview .markdown-alert-tip,
#preview .markdown-alert-important,
@@ -2132,6 +2174,15 @@ mod tests {
assert!(!html.contains("<em>"));
}
#[test]
fn multiline_display_math_is_not_split_by_hard_breaks() {
let html = md_to_html("$$\na + b\n$$");
assert!(html.contains(r#"class="math math-display""#), "{html}");
assert!(html.contains("a + b"), "{html}");
assert!(!html.contains("<br />"), "{html}");
}
#[test]
fn github_alerts_render_as_markdown_alert_blockquotes() {
let html = md_to_html("> [!IMPORTANT]\n> This is an alert");
@@ -2141,6 +2192,86 @@ mod tests {
assert!(!html.contains("[!IMPORTANT]"));
}
#[test]
fn soft_breaks_render_as_hard_breaks_in_paragraphs() {
let html = md_to_html("2.1 默认只读讨论。\n2.2 默认工作流:先读代码。");
assert!(
html.contains("2.1 默认只读讨论。<br />\n2.2 默认工作流"),
"{html}"
);
}
#[test]
fn blank_lines_still_create_paragraphs() {
let html = md_to_html("first line\n\nsecond line");
assert_eq!(html.matches("<p>").count(), 2, "{html}");
assert!(!html.contains("<br />"), "{html}");
}
#[test]
fn soft_breaks_inside_headings_stay_soft() {
let html = md_to_html("First heading line\nsecond heading line\n===");
assert!(html.contains("<h1"), "{html}");
assert!(!html.contains("<br />"), "{html}");
}
#[test]
fn soft_breaks_in_list_items_become_hard_breaks() {
let html = md_to_html("- first line\n second line");
assert!(html.contains("<li>first line<br />"), "{html}");
assert!(html.contains("second line</li>"), "{html}");
}
#[test]
fn code_blocks_keep_newlines_without_br() {
let html = md_to_html("~~~text\nline one\nline two\n~~~");
assert!(!html.contains("<br />"), "{html}");
assert!(html.contains("line one\nline two"), "{html}");
}
#[test]
fn gfm_footnotes_render_reference_and_definition() {
let html = md_to_html("Text with a note[^1].\n\n[^1]: The footnote body.");
assert!(html.contains(r#"class="footnote-reference""#), "{html}");
assert!(html.contains(r#"class="footnote-definition""#), "{html}");
assert!(html.contains("The footnote body."), "{html}");
}
#[test]
fn definition_lists_render_as_dl_dt_dd() {
let html = md_to_html("Term\n: Definition");
assert!(html.contains("<dl>"), "{html}");
assert!(html.contains("<dt>Term</dt>"), "{html}");
assert!(html.contains("<dd>Definition</dd>"), "{html}");
}
#[test]
fn utf8_bom_is_ignored_before_heading_and_front_matter() {
let heading = md_to_html("\u{feff}# BOM heading");
assert!(
heading.contains(r#"<h1 id="bom-heading">BOM heading</h1>"#),
"{heading}"
);
let front_matter = md_to_html("\u{feff}---\ntitle: BOM\n---\n# Body");
assert!(
front_matter.contains(r#"class="front-matter""#),
"{front_matter}"
);
assert!(front_matter.contains("title: BOM"), "{front_matter}");
assert!(
front_matter.contains(r#"<h1 id="body">Body</h1>"#),
"{front_matter}"
);
}
#[test]
fn double_equals_highlight_renders_mark_without_touching_code() {
let html = md_to_html("Use ==highlight & tag== here and `==literal==` there.");