refactor: 收敛渲染链路共享抽象
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import type { ExportConfig } from "./export-config.js";
|
||||
import type { ThemeFeature } from "./theme.js";
|
||||
|
||||
export interface MarkdownDocumentMetadata {
|
||||
title: string;
|
||||
author: string;
|
||||
subject: string;
|
||||
keywords: string[];
|
||||
language: string;
|
||||
}
|
||||
|
||||
export interface RenderedMarkdownDocument {
|
||||
rendererVersion: number;
|
||||
articleHtml: string;
|
||||
bodyHtml: string;
|
||||
metadata: MarkdownDocumentMetadata;
|
||||
features: ThemeFeature[];
|
||||
warnings: string[];
|
||||
}
|
||||
|
||||
export interface PagedDocumentPayload {
|
||||
articleHtml: string;
|
||||
fileName: string;
|
||||
metadata: MarkdownDocumentMetadata;
|
||||
features: ThemeFeature[];
|
||||
themeCss: string;
|
||||
exportConfig: ExportConfig;
|
||||
}
|
||||
|
||||
export interface CreatePagedDocumentPayloadOptions {
|
||||
document: RenderedMarkdownDocument;
|
||||
fileName: string;
|
||||
themeCss: string;
|
||||
exportConfig: ExportConfig;
|
||||
}
|
||||
|
||||
export function createPagedDocumentPayload({
|
||||
document,
|
||||
fileName,
|
||||
themeCss,
|
||||
exportConfig
|
||||
}: CreatePagedDocumentPayloadOptions): PagedDocumentPayload {
|
||||
return {
|
||||
articleHtml: document.articleHtml,
|
||||
fileName,
|
||||
metadata: document.metadata,
|
||||
features: document.features,
|
||||
themeCss,
|
||||
exportConfig
|
||||
};
|
||||
}
|
||||
|
||||
export interface PagedDocumentTimings {
|
||||
setupMs: number;
|
||||
mermaidMs: number;
|
||||
mermaidFitMs: number;
|
||||
mermaidConversionMs: number;
|
||||
resourceWaitMs: number;
|
||||
paginationMs: number;
|
||||
finalizeMs: number;
|
||||
totalMs: number;
|
||||
}
|
||||
|
||||
export interface PagedDocumentRenderResult {
|
||||
pageCount: number;
|
||||
mermaidErrors: string[];
|
||||
timings: PagedDocumentTimings;
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./document.js";
|
||||
export * from "./export-config.js";
|
||||
export * from "./theme.js";
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createPagedDocumentPayload,
|
||||
defaultExportConfig,
|
||||
type RenderedMarkdownDocument
|
||||
} from "../src/index.js";
|
||||
|
||||
describe("分页文档载荷", () => {
|
||||
it("从统一渲染结果提取预览与 PDF 共用字段", () => {
|
||||
const document: RenderedMarkdownDocument = {
|
||||
rendererVersion: 1,
|
||||
articleHtml: '<article id="write"><h1>测试</h1></article>',
|
||||
bodyHtml: "<h1>测试</h1>",
|
||||
metadata: {
|
||||
title: "测试",
|
||||
author: "",
|
||||
subject: "",
|
||||
keywords: [],
|
||||
language: "zh-CN"
|
||||
},
|
||||
features: ["table"],
|
||||
warnings: []
|
||||
};
|
||||
|
||||
expect(
|
||||
createPagedDocumentPayload({
|
||||
document,
|
||||
fileName: "测试.md",
|
||||
themeCss: "#write { color: #333; }",
|
||||
exportConfig: defaultExportConfig
|
||||
})
|
||||
).toEqual({
|
||||
articleHtml: document.articleHtml,
|
||||
fileName: "测试.md",
|
||||
metadata: document.metadata,
|
||||
features: document.features,
|
||||
themeCss: "#write { color: #333; }",
|
||||
exportConfig: defaultExportConfig
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user