release: 发布 v0.5.0
新增共享 Preview Engine,统一 Web 连续预览、快速分页、Playwright PDF 与 Electron PDF;实现稳定前缀复用和修改位置后的增量分页,保留媒体块按文档顺序串行回填与单次重排。 完善跨端链接与桌面文档工作流:Web 受控处理锚点和 HTTP/HTTPS 外链;Desktop 支持本地路径、file URI、系统协议、多窗口、同文件单例、Markdown 当前或新窗口打开,以及聚焦时外部文件变化提示。 统一四套内置主题名称并默认使用 Typora Github;修复连续预览双滚动条、ECharts 尺寸、PDF 本地链接、围栏代码块 Typora DOM 与重复行内样式;桌面发行链强制完整重建内嵌 Web,避免安装包携带陈旧资源。 发布 Web/Compose 与 Windows NSIS/ZIP:镜像 yixiong/md-to-pdf:v0.5.0 已健康部署;NSIS SHA-256 为 60992D1FDCA513F46346C78478537EB4159D8C0E76B41ECF3CDC25BE77707D92,ZIP SHA-256 为 D74F82293FB67126E583546CBA894569EFC9A0B1B6343FAC648CCC95F1D188D8,本机安装版已升级至 v0.5.0。 验证:全项目 238 项测试通过,类型检查、生产构建和 git diff --check 通过;Web 快速/连续/精确预览、Compose、Desktop 多窗口、窗口状态、文件关联、链接与代码块均完成真实环境验收。
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveDesktopDocumentLinkAction } from "../src/desktop-document-link.js";
|
||||
|
||||
describe("桌面文档链接动作", () => {
|
||||
const markdownPath = path.resolve("D:/文档/章节/当前.md");
|
||||
|
||||
it("保留锚点并把网络和自定义协议交给系统", () => {
|
||||
expect(resolveDesktopDocumentLinkAction("#标题")).toEqual({
|
||||
type: "anchor",
|
||||
href: "#标题"
|
||||
});
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction("//example.com/path")
|
||||
).toEqual({
|
||||
type: "external",
|
||||
href: "https://example.com/path"
|
||||
});
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction("mailto:user@example.com")
|
||||
).toEqual({
|
||||
type: "external",
|
||||
href: "mailto:user@example.com"
|
||||
});
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction("obsidian://open?vault=docs")
|
||||
).toEqual({
|
||||
type: "external",
|
||||
href: "obsidian://open?vault=docs"
|
||||
});
|
||||
});
|
||||
|
||||
it("允许相对路径越过 Markdown 目录", () => {
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction(
|
||||
"../../共享/说明.pdf#page=2",
|
||||
markdownPath
|
||||
)
|
||||
).toEqual({
|
||||
type: "local",
|
||||
filePath: path.resolve(
|
||||
path.dirname(markdownPath),
|
||||
"../../共享/说明.pdf"
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
it("解析绝对路径、file URI 和 URL 编码", () => {
|
||||
const absolutePath = path.resolve("C:/资料/项目说明.md");
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction(absolutePath, markdownPath)
|
||||
).toEqual({
|
||||
type: "local",
|
||||
filePath: path.normalize(absolutePath)
|
||||
});
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction(
|
||||
pathToFileURL(absolutePath).href,
|
||||
markdownPath
|
||||
)
|
||||
).toEqual({
|
||||
type: "local",
|
||||
filePath: path.normalize(absolutePath)
|
||||
});
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction(
|
||||
"../%E5%85%B1%E4%BA%AB/%E8%AF%B4%E6%98%8E.pdf",
|
||||
markdownPath
|
||||
)
|
||||
).toEqual({
|
||||
type: "local",
|
||||
filePath: path.resolve(
|
||||
path.dirname(markdownPath),
|
||||
"../共享/说明.pdf"
|
||||
)
|
||||
});
|
||||
});
|
||||
|
||||
it("拒绝危险链接和无文件基准的相对路径", () => {
|
||||
expect(
|
||||
resolveDesktopDocumentLinkAction("javascript:alert(1)")
|
||||
).toEqual({ type: "ignore" });
|
||||
expect(() =>
|
||||
resolveDesktopDocumentLinkAction("../说明.pdf")
|
||||
).toThrow("尚未保存");
|
||||
});
|
||||
});
|
||||
@@ -3,9 +3,12 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createMarkdownContentHash,
|
||||
createMarkdownDocumentKey,
|
||||
findMarkdownFileArgument,
|
||||
isMarkdownFilePath,
|
||||
readMarkdownDocument
|
||||
readMarkdownDocument,
|
||||
readMarkdownFileSnapshot
|
||||
} from "../src/markdown-file.js";
|
||||
|
||||
describe("桌面 Markdown 文件参数", () => {
|
||||
@@ -72,4 +75,33 @@ describe("桌面 Markdown 文件参数", () => {
|
||||
readMarkdownDocument("C:\\docs\\说明.txt", 100)
|
||||
).rejects.toThrow("只允许打开 .md 或 .markdown 文件");
|
||||
});
|
||||
|
||||
it("使用真实路径和内容哈希创建文件快照", async () => {
|
||||
const directory = await mkdtemp(
|
||||
path.join(os.tmpdir(), "md-to-pdf-snapshot-")
|
||||
);
|
||||
const filePath = path.join(directory, "快照.md");
|
||||
try {
|
||||
await writeFile(filePath, "# 第一版", "utf8");
|
||||
const snapshot = await readMarkdownFileSnapshot(filePath, 100);
|
||||
|
||||
expect(snapshot.document).toEqual({
|
||||
markdown: "# 第一版",
|
||||
fileName: "快照.md"
|
||||
});
|
||||
expect(snapshot.filePath).toBe(filePath);
|
||||
expect(snapshot.documentKey).toBe(
|
||||
createMarkdownDocumentKey(filePath)
|
||||
);
|
||||
expect(snapshot.contentHash).toBe(
|
||||
createMarkdownContentHash("# 第一版")
|
||||
);
|
||||
|
||||
await writeFile(filePath, "# 第二版", "utf8");
|
||||
const changed = await readMarkdownFileSnapshot(filePath, 100);
|
||||
expect(changed.contentHash).not.toBe(snapshot.contentHash);
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
interface PackageManifest {
|
||||
scripts?: Record<string, string>;
|
||||
}
|
||||
|
||||
const desktopRoot = fileURLToPath(new URL("../", import.meta.url));
|
||||
const projectRoot = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
|
||||
function readManifest(path: string): PackageManifest {
|
||||
return JSON.parse(readFileSync(path, "utf8")) as PackageManifest;
|
||||
}
|
||||
|
||||
describe("桌面发行构建链", () => {
|
||||
it("打包前按依赖顺序完整重建内嵌 Web", () => {
|
||||
const rootManifest = readManifest(`${projectRoot}/package.json`);
|
||||
const desktopManifest = readManifest(`${desktopRoot}/package.json`);
|
||||
const webBuild = rootManifest.scripts?.["build:web-runtime"] ?? "";
|
||||
const expectedWorkspaces = [
|
||||
"@md-to-pdf/markdown-echarts",
|
||||
"@md-to-pdf/core",
|
||||
"@md-to-pdf/renderer",
|
||||
"@md-to-pdf/application",
|
||||
"@md-to-pdf/preview-engine",
|
||||
"@md-to-pdf/web"
|
||||
];
|
||||
|
||||
let previousIndex = -1;
|
||||
for (const workspace of expectedWorkspaces) {
|
||||
const workspaceIndex = webBuild.indexOf(workspace);
|
||||
expect(workspaceIndex).toBeGreaterThan(previousIndex);
|
||||
previousIndex = workspaceIndex;
|
||||
}
|
||||
|
||||
expect(desktopManifest.scripts?.["build:embedded-web"]).toBe(
|
||||
"npm --prefix ../.. run build:web-runtime"
|
||||
);
|
||||
expect(desktopManifest.scripts?.package).toMatch(
|
||||
/^npm run build:embedded-web && /
|
||||
);
|
||||
expect(desktopManifest.scripts?.make).toMatch(
|
||||
/^npm run build:embedded-web && /
|
||||
);
|
||||
expect(rootManifest.scripts?.["desktop:package"]).toBe(
|
||||
"npm run package -w @md-to-pdf/desktop"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user