@studiocms/md
Version:
Add Markdown Support to your StudioCMS project with ease!
298 lines (297 loc) • 14.1 kB
TypeScript
import { z } from 'astro/zod';
/**
* Schema definition for Astro-flavored Markdown content.
*
* @remarks
* This schema is used to validate Markdown objects that are specifically
* intended for use with the Astro flavor. It ensures that the `flavor`
* property is set to `'astro'` and that the `sanitize` property conforms
* to the `StudioCMSSanitizeOptionsSchema`.
*
* @property flavor - Specifies the Markdown flavor, must be `'astro'`.
* @property sanitize - Sanitization options for Markdown content, validated
* against `StudioCMSSanitizeOptionsSchema`.
*/
export declare const AstroMarkdownSchema: z.ZodObject<{
/**
* Specifies the Markdown flavor, fixed to 'astro'.
* This property is used to differentiate between different Markdown configurations.
*/
flavor: z.ZodLiteral<"astro">;
/**
* Schema for options used to sanitize Markdown content in StudioCMS.
*
* @remarks
* This schema defines the configuration for controlling which elements and attributes
* are allowed, blocked, or dropped during the sanitization process. It also provides
* options for handling components, custom elements, and comments.
*/
sanitize: z.ZodOptional<z.ZodObject<{
allowElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
blockElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
dropElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
dropAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
allowComponents: z.ZodOptional<z.ZodBoolean>;
allowCustomElements: z.ZodOptional<z.ZodBoolean>;
allowComments: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
flavor: "astro";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}, {
flavor: "astro";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}>;
/**
* Schema definition for StudioCMS Markdown configuration.
*
* @extends AstroMarkdownSchema
* @property {'studiocms'} flavor - Specifies the markdown flavor, fixed to 'studiocms'.
* @property {'github' | 'obsidian' | 'vitepress' | false} [callouts='obsidian'] - Optional callouts style, defaults to 'obsidian'.
* @property {boolean} [autoLinkHeadings=true] - Optionally enables automatic linking of headings, defaults to true.
* @property {boolean} [discordSubtext=true] - Optionally enables Discord subtext, defaults to true.
*/
export declare const StudioCMSMarkdownSchema: z.ZodObject<{
sanitize: z.ZodOptional<z.ZodObject<{
allowElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
blockElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
dropElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
dropAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
allowComponents: z.ZodOptional<z.ZodBoolean>;
allowCustomElements: z.ZodOptional<z.ZodBoolean>;
allowComments: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}>>;
} & {
flavor: z.ZodLiteral<"studiocms">;
callouts: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"github">, z.ZodLiteral<"obsidian">, z.ZodLiteral<"vitepress">, z.ZodLiteral<false>]>>>;
autoLinkHeadings: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
discordSubtext: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
}, "strip", z.ZodTypeAny, {
flavor: "studiocms";
callouts: false | "github" | "obsidian" | "vitepress";
autoLinkHeadings: boolean;
discordSubtext: boolean;
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}, {
flavor: "studiocms";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
callouts?: false | "github" | "obsidian" | "vitepress" | undefined;
autoLinkHeadings?: boolean | undefined;
discordSubtext?: boolean | undefined;
}>;
/**
* Defines a Zod schema for Markdown content, allowing either `AstroMarkdownSchema` or `StudioCMSMarkdownSchema`.
* The schema is optional and defaults to an object with the flavor set to 'studiocms'.
*
* @remarks
* This schema is useful for validating Markdown data that may conform to different formats,
* providing flexibility in content handling within the application.
*/
export declare const MarkdownSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodObject<{
/**
* Specifies the Markdown flavor, fixed to 'astro'.
* This property is used to differentiate between different Markdown configurations.
*/
flavor: z.ZodLiteral<"astro">;
/**
* Schema for options used to sanitize Markdown content in StudioCMS.
*
* @remarks
* This schema defines the configuration for controlling which elements and attributes
* are allowed, blocked, or dropped during the sanitization process. It also provides
* options for handling components, custom elements, and comments.
*/
sanitize: z.ZodOptional<z.ZodObject<{
allowElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
blockElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
dropElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
dropAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
allowComponents: z.ZodOptional<z.ZodBoolean>;
allowCustomElements: z.ZodOptional<z.ZodBoolean>;
allowComments: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
flavor: "astro";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}, {
flavor: "astro";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}>, z.ZodObject<{
sanitize: z.ZodOptional<z.ZodObject<{
allowElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
blockElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
dropElements: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
allowAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
dropAttributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
allowComponents: z.ZodOptional<z.ZodBoolean>;
allowCustomElements: z.ZodOptional<z.ZodBoolean>;
allowComments: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}, {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
}>>;
} & {
flavor: z.ZodLiteral<"studiocms">;
callouts: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"github">, z.ZodLiteral<"obsidian">, z.ZodLiteral<"vitepress">, z.ZodLiteral<false>]>>>;
autoLinkHeadings: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
discordSubtext: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
}, "strip", z.ZodTypeAny, {
flavor: "studiocms";
callouts: false | "github" | "obsidian" | "vitepress";
autoLinkHeadings: boolean;
discordSubtext: boolean;
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
}, {
flavor: "studiocms";
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
callouts?: false | "github" | "obsidian" | "vitepress" | undefined;
autoLinkHeadings?: boolean | undefined;
discordSubtext?: boolean | undefined;
}>]>>>;
export type AstroMarkdownOptions = z.infer<typeof AstroMarkdownSchema>;
export type StudioCMSMarkdownOptions = z.infer<typeof StudioCMSMarkdownSchema>;
export type MarkdownSchemaOptions = z.infer<typeof MarkdownSchema>;