UNPKG

datocms-structured-text-to-plain-text

Version:
66 lines (65 loc) 4.42 kB
import { RenderMarkRule, renderMarkRule, renderNodeRule, TransformedMeta, TransformMetaFn } from 'datocms-structured-text-generic-html-renderer'; import { Adapter, CdaStructuredTextRecord, CdaStructuredTextValue, Document as StructuredTextDocument, Node, Record as StructuredTextGraphQlResponseRecord, RenderError, RenderResult, RenderRule, StructuredText as StructuredTextGraphQlResponse, TypesafeCdaStructuredTextValue, TypesafeStructuredText as TypesafeStructuredTextGraphQlResponse } from 'datocms-structured-text-utils'; export { renderNodeRule, renderMarkRule, RenderError }; export type { StructuredTextDocument, CdaStructuredTextValue, TypesafeCdaStructuredTextValue, CdaStructuredTextRecord, }; export declare const defaultAdapter: { renderNode: (tagName: string, attrs: Record<string, string>, ...children: Array<undefined | string | string[]>) => string; renderFragment: (children: Array<undefined | string | string[]> | undefined) => string; renderText: (text: string) => string; }; declare type H = typeof defaultAdapter.renderNode; declare type T = typeof defaultAdapter.renderText; declare type F = typeof defaultAdapter.renderFragment; declare type RenderInlineRecordContext<R extends StructuredTextGraphQlResponseRecord> = { record: R; adapter: Adapter<H, T, F>; }; declare type RenderRecordLinkContext<R extends StructuredTextGraphQlResponseRecord> = { record: R; adapter: Adapter<H, T, F>; children: RenderResult<H, T, F>; transformedMeta: TransformedMeta; }; declare type RenderBlockContext<R extends StructuredTextGraphQlResponseRecord> = { record: R; adapter: Adapter<H, T, F>; }; export declare type RenderSettings<BlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, LinkRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, InlineBlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord> = { /** A set of additional rules to convert the document to a string **/ customNodeRules?: RenderRule<H, T, F>[]; /** A set of additional rules to convert marks to HTML **/ customMarkRules?: RenderMarkRule<H, T, F>[]; /** Function that converts 'link' and 'itemLink' `meta` into HTML attributes */ metaTransformer?: TransformMetaFn; /** Fuction that converts an 'inlineItem' node into a string **/ renderInlineRecord?: (context: RenderInlineRecordContext<LinkRecord>) => string | null | undefined; /** Fuction that converts an 'itemLink' node into a string **/ renderLinkToRecord?: (context: RenderRecordLinkContext<LinkRecord>) => string | null | undefined; /** Fuction that converts a 'block' node into a string **/ renderBlock?: (context: RenderBlockContext<BlockRecord>) => string | null | undefined; /** Fuction that converts an 'inlineBlock' node into a string **/ renderInlineBlock?: (context: RenderBlockContext<InlineBlockRecord>) => string | null | undefined; /** Fuction that converts a simple string text into a string **/ renderText?: T; /** React.createElement-like function to use to convert a node into a string **/ renderNode?: H; /** Function to use to generate a React.Fragment **/ renderFragment?: F; /** @deprecated use `customNodeRules` instead **/ customRules?: RenderRule<H, T, F>[]; }; export declare function render<BlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, LinkRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord, InlineBlockRecord extends StructuredTextGraphQlResponseRecord = StructuredTextGraphQlResponseRecord>( /** The actual field value you get from DatoCMS **/ structuredTextOrNode: StructuredTextGraphQlResponse<BlockRecord, LinkRecord, InlineBlockRecord> | StructuredTextDocument | Node | null | undefined, /** Additional render settings **/ settings?: RenderSettings<BlockRecord, LinkRecord, InlineBlockRecord>): ReturnType<F> | null; /** * @deprecated Use renderNodeRule instead */ export { renderNodeRule as renderRule }; /** @deprecated Use CdaStructuredTextValue */ export type { StructuredTextGraphQlResponse }; /** @deprecated Use TypesafeCdaStructuredTextValue */ export type { TypesafeStructuredTextGraphQlResponse }; /** @deprecated Use CdaStructuredTextRecord */ export type { StructuredTextGraphQlResponseRecord };