feat: 建立统一语义文档模型
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ExportConfig } from "./export-config.js";
|
||||
import type { DocumentProfile } from "./document-profile.js";
|
||||
import type { SemanticDocumentModel } from "./semantic-document.js";
|
||||
import type { ThemeFeature } from "./theme.js";
|
||||
|
||||
export interface MarkdownDocumentMetadata {
|
||||
@@ -16,6 +17,7 @@ export interface RenderedMarkdownDocument {
|
||||
articleHtml: string;
|
||||
bodyHtml: string;
|
||||
metadata: MarkdownDocumentMetadata;
|
||||
semanticDocument: SemanticDocumentModel;
|
||||
features: ThemeFeature[];
|
||||
warnings: string[];
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ export * from "./docx-style.js";
|
||||
export * from "./document-profile.js";
|
||||
export * from "./document-link.js";
|
||||
export * from "./export-config.js";
|
||||
export * from "./semantic-document.js";
|
||||
export * from "./theme.js";
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { z } from "zod";
|
||||
import { documentProfileNameSchema } from "./document-profile.js";
|
||||
|
||||
export const semanticDocumentRoleSchema = z.enum([
|
||||
"official-masthead",
|
||||
"official-classification",
|
||||
"official-secrecy",
|
||||
"official-urgency",
|
||||
"official-issuer",
|
||||
"official-issue-row",
|
||||
"official-number",
|
||||
"official-signatory",
|
||||
"official-title",
|
||||
"official-signature",
|
||||
"official-signature-issuer",
|
||||
"official-signature-date",
|
||||
"official-edition",
|
||||
"official-copy-to",
|
||||
"official-printing-row",
|
||||
"official-printing-office",
|
||||
"official-printing-date",
|
||||
"briefing-masthead",
|
||||
"briefing-masthead-text",
|
||||
"briefing-meta",
|
||||
"briefing-issue",
|
||||
"briefing-publisher",
|
||||
"briefing-signatory",
|
||||
"briefing-date",
|
||||
"briefing-title",
|
||||
"briefing-contact",
|
||||
"project-report-cover",
|
||||
"project-report-project-name",
|
||||
"project-report-title",
|
||||
"project-report-version",
|
||||
"project-report-owner",
|
||||
"project-report-prepared-by",
|
||||
"project-report-date",
|
||||
"tender-cover",
|
||||
"tender-copy-mark",
|
||||
"tender-project-name",
|
||||
"tender-project-number",
|
||||
"tender-title",
|
||||
"tender-volume",
|
||||
"tender-bidder",
|
||||
"tender-representative",
|
||||
"tender-date"
|
||||
]);
|
||||
|
||||
export type SemanticDocumentRole = z.infer<
|
||||
typeof semanticDocumentRoleSchema
|
||||
>;
|
||||
|
||||
export interface SemanticDocumentTextNode {
|
||||
kind: "text";
|
||||
role: SemanticDocumentRole;
|
||||
text: string;
|
||||
label?: string | undefined;
|
||||
}
|
||||
|
||||
export interface SemanticDocumentGroupNode {
|
||||
kind: "group";
|
||||
role: SemanticDocumentRole;
|
||||
children: SemanticDocumentNode[];
|
||||
}
|
||||
|
||||
export type SemanticDocumentNode =
|
||||
| SemanticDocumentTextNode
|
||||
| SemanticDocumentGroupNode;
|
||||
|
||||
export const semanticDocumentNodeSchema: z.ZodType<
|
||||
SemanticDocumentNode
|
||||
> = z.lazy(() =>
|
||||
z.discriminatedUnion("kind", [
|
||||
z.object({
|
||||
kind: z.literal("text"),
|
||||
role: semanticDocumentRoleSchema,
|
||||
text: z.string().min(1).max(1000),
|
||||
label: z.string().min(1).max(100).optional()
|
||||
}),
|
||||
z.object({
|
||||
kind: z.literal("group"),
|
||||
role: semanticDocumentRoleSchema,
|
||||
children: z.array(semanticDocumentNodeSchema).min(1).max(30)
|
||||
})
|
||||
])
|
||||
);
|
||||
|
||||
export const semanticDocumentRegionKindSchema = z.enum([
|
||||
"cover",
|
||||
"prefix",
|
||||
"suffix"
|
||||
]);
|
||||
|
||||
export type SemanticDocumentRegionKind = z.infer<
|
||||
typeof semanticDocumentRegionKindSchema
|
||||
>;
|
||||
|
||||
export const semanticDocumentSectionIntentSchema = z.object({
|
||||
headerFooter: z.literal("none"),
|
||||
pageNumber: z.literal("hidden"),
|
||||
breakAfter: z.literal("next-page"),
|
||||
followingPageNumberStart: z.number().int().min(0).max(100000)
|
||||
});
|
||||
|
||||
export type SemanticDocumentSectionIntent = z.infer<
|
||||
typeof semanticDocumentSectionIntentSchema
|
||||
>;
|
||||
|
||||
export const semanticDocumentRegionSchema = z.object({
|
||||
kind: semanticDocumentRegionKindSchema,
|
||||
nodes: z.array(semanticDocumentNodeSchema).min(1).max(30),
|
||||
section: semanticDocumentSectionIntentSchema.optional()
|
||||
});
|
||||
|
||||
export type SemanticDocumentRegion = z.infer<
|
||||
typeof semanticDocumentRegionSchema
|
||||
>;
|
||||
|
||||
export const semanticDocumentTitlePolicySchema = z.object({
|
||||
metadataTitle: z.enum(["emit", "suppress"]),
|
||||
firstBodyHeading: z.enum(["keep", "suppress"])
|
||||
});
|
||||
|
||||
export type SemanticDocumentTitlePolicy = z.infer<
|
||||
typeof semanticDocumentTitlePolicySchema
|
||||
>;
|
||||
|
||||
export const semanticDocumentModelSchema = z.object({
|
||||
schemaVersion: z.literal(1),
|
||||
profile: documentProfileNameSchema.optional(),
|
||||
titlePolicy: semanticDocumentTitlePolicySchema,
|
||||
regions: z.array(semanticDocumentRegionSchema).max(10)
|
||||
});
|
||||
|
||||
export type SemanticDocumentModel = z.infer<
|
||||
typeof semanticDocumentModelSchema
|
||||
>;
|
||||
@@ -18,6 +18,14 @@ describe("分页文档载荷", () => {
|
||||
keywords: [],
|
||||
language: "zh-CN"
|
||||
},
|
||||
semanticDocument: {
|
||||
schemaVersion: 1,
|
||||
titlePolicy: {
|
||||
metadataTitle: "suppress",
|
||||
firstBodyHeading: "keep"
|
||||
},
|
||||
regions: []
|
||||
},
|
||||
features: ["table"],
|
||||
warnings: []
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user