UNPKG

@synstack/markdown

Version:
177 lines (172 loc) 6.1 kB
import { ZodType, ZodTypeDef } from 'zod/v3'; import { ZodType as ZodType$1 } from 'zod/v4'; /** * A type serializable to string */ type Stringable = { toString(): string; }; type ZodSchema<OUT = any, IN = any> = ZodType<OUT, ZodTypeDef, IN> | ZodType$1<OUT, IN>; /** * Convert HTML to markdown * @param html - The HTML to convert * @returns The markdown (minified for LLM processing) */ declare const fromHtml: (html: Stringable) => string; /** * Get the header data from a markdown document * @param text - The markdown document * @param options - The options (optional) * @param options.schema - The schema to use for deserialization (optional) * @returns The header data */ declare const getHeaderData: <SHAPE = unknown>(text: Stringable, { schema }?: { schema?: ZodSchema<SHAPE>; }) => SHAPE | undefined; /** * Set the header data in a markdown document while preserving the body * @param text - The markdown document * @param data - The data to set * @param options - The options (optional) * @param options.schema - The schema to use for serialization (optional) * @returns The markdown document with the header data set */ declare const setHeaderData: <SHAPE = any>(text: Stringable, data: SHAPE, options?: { schema?: ZodSchema<any, SHAPE>; }) => string; /** * Get the body of a markdown document * @param text - The markdown document * @returns The body as a string */ declare const getBody: (text: string) => string; /** * Set the body of a markdown document while preserving the header * @param text - The markdown document * @param body - The body to set * @returns The markdown document with the body set */ declare const setBody: (text: string, body: string) => string; /** * Minify a markdown document for better LLM processing * @param text - The markdown document * @returns The minified markdown document */ declare const minify: (md: string) => string; /** * Beautify a markdown document for better human readability * @param md - The markdown document * @returns The beautified markdown document */ declare const beautify: (md: string) => string; /** * Markdown document instance */ declare class MdDoc<SHAPE = never, DATA extends SHAPE | undefined = never> { private readonly _body; private readonly _data; private readonly _options; protected constructor(data: DATA, body: string, options?: { schema?: ZodSchema<SHAPE, SHAPE>; }); /** * Create a new markdown document with options * @param options * @param options.schema - The zod schema to use for serialization/deserialization (optional) * @returns A new markdown document instance */ static withOptions<SHAPE = unknown>(this: void, options: { schema?: ZodSchema<SHAPE, SHAPE>; }): MdDoc<SHAPE, undefined>; /** * Create a new markdown document from a string * @param text - The markdown document * @returns The markdown document */ static fromString<SHAPE = unknown>(this: void, text: string): MdDoc<SHAPE, SHAPE>; /** * Create a new markdown document from HTML * @param html - The HTML to convert * @returns The markdown document */ static fromHtml<SHAPE = unknown>(this: void, html: string): MdDoc<SHAPE, undefined>; /** * Get the body of the markdown document * @returns The body of the markdown document */ get body(): string; /** * Get the data of the markdown document * @returns The data of the markdown document */ get data(): DATA; /** * Get the header of the markdown document * @returns The header of the markdown document */ get header(): string; /** * Get the options of the markdown document * @returns The options of the markdown document */ get options(): { schema?: ZodSchema<SHAPE, SHAPE>; }; /** * Create a new markdown document from a string * @param text - The markdown document * @returns A new markdown document */ fromString(text: string): MdDoc<SHAPE, SHAPE>; /** * Create a new markdown document from HTML * @param html - The HTML to convert * @returns A new markdown document */ fromHtml(html: string): MdDoc<any, DATA>; /** * Set the data of the markdown document * @param data - The data to set * @returns A new markdown document */ setData(data: SHAPE): MdDoc<any, SHAPE>; /** * Set the body of the markdown document * @param text - The body to set * @returns A new markdown document */ setBody(text: string): MdDoc<any, DATA>; /** * Minify the markdown document for better LLM processing * @returns A new markdown document */ minify(): MdDoc<any, DATA>; /** * Beautify the markdown document for better human readability * @returns A new markdown document */ beautify(): MdDoc<any, DATA>; /** * Get the markdown document as a string * * @alias {@link toString} * @returns The markdown document as a string */ toMd(): string; /** * Get the markdown document as a string * @returns The markdown document as a string */ toString(): string; } declare const markdown_bundle_beautify: typeof beautify; declare const markdown_bundle_fromHtml: typeof fromHtml; declare const markdown_bundle_getBody: typeof getBody; declare const markdown_bundle_getHeaderData: typeof getHeaderData; declare const markdown_bundle_minify: typeof minify; declare const markdown_bundle_setBody: typeof setBody; declare const markdown_bundle_setHeaderData: typeof setHeaderData; declare namespace markdown_bundle { export { markdown_bundle_beautify as beautify, markdown_bundle_fromHtml as fromHtml, markdown_bundle_getBody as getBody, markdown_bundle_getHeaderData as getHeaderData, markdown_bundle_minify as minify, markdown_bundle_setBody as setBody, markdown_bundle_setHeaderData as setHeaderData }; } export { MdDoc, beautify, fromHtml, getBody, getHeaderData, markdown_bundle as md, minify, setBody, setHeaderData };