mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
feat(editor): provide callout markdown export options middleware (#12283)
Closes: [BS-3491](https://linear.app/affine-design/issue/BS-3491/支持-callout-导出成-vitepress-文档站支持的-markdown-格式) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for exporting callout blocks in both GFM and Admonition markdown styles, including configurable admonition types and custom titles. - Introduced middleware to customize callout export options for markdown serialization. - **Tests** - Enhanced test coverage for callout markdown export, including scenarios with and without export middleware for different styles and content structures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import type { TransformerMiddleware } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const CALLOUT_MARKDOWN_EXPORT_OPTIONS_KEY =
|
||||
'calloutMarkdownExportOptions';
|
||||
|
||||
export enum CalloutExportStyle {
|
||||
GFM = 'GFM',
|
||||
Admonitions = 'Admonitions',
|
||||
}
|
||||
|
||||
export enum CalloutAdmonitionType {
|
||||
Info = 'info',
|
||||
Tip = 'tip',
|
||||
Warning = 'warning',
|
||||
Danger = 'danger',
|
||||
Details = 'details',
|
||||
}
|
||||
|
||||
export const DEFAULT_ADMONITION_TYPE = CalloutAdmonitionType.Info;
|
||||
|
||||
export const CalloutAdmonitionTypeSet: Set<string> = new Set(
|
||||
Object.values(CalloutAdmonitionType)
|
||||
);
|
||||
|
||||
export const calloutMarkdownExportOptionsSchema = z.object({
|
||||
style: z.nativeEnum(CalloutExportStyle),
|
||||
admonitionType: z.nativeEnum(CalloutAdmonitionType).optional(),
|
||||
});
|
||||
export type CalloutMarkdownExportOptions = z.infer<
|
||||
typeof calloutMarkdownExportOptionsSchema
|
||||
>;
|
||||
|
||||
/**
|
||||
* Middleware to set the export style of the callout block
|
||||
* @param style - The markdown export style of the callout block
|
||||
* @returns A TransformerMiddleware that sets the markdown export style of the callout block
|
||||
*/
|
||||
export const calloutMarkdownExportMiddleware = (
|
||||
options: CalloutMarkdownExportOptions
|
||||
): TransformerMiddleware => {
|
||||
return ({ adapterConfigs }) => {
|
||||
adapterConfigs.set(CALLOUT_MARKDOWN_EXPORT_OPTIONS_KEY, options);
|
||||
};
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './callout-export-options';
|
||||
export * from './code';
|
||||
export * from './copy';
|
||||
export * from './doc-link';
|
||||
|
||||
Reference in New Issue
Block a user