import type { Block, Inline, Mark, Node, Text } from "@contentful/rich-text-types"; export type HTMLTagName = keyof HTMLElementTagNameMap; export interface HTMLTextNode { type: "text"; value: string; } export interface HTMLElementNode { type: "element"; tagName: HTMLTagName; children: HTMLNode[]; attrs: { [attr: string]: string; }; } export type HTMLNode = HTMLElementNode | HTMLTextNode; export type ContentfulNodeContent = TNodeType extends Block ? Block["content"][0] : TNodeType extends Inline ? Inline["content"][0] : TNodeType extends Mark ? Block["content"][0] : TNodeType extends Text ? Text : never; export type AnyContentfulNode = Node | Mark | Text; export type ConverterResult = ContentfulNodeContent | Array>; export type Next = (node: HTMLNode, marks?: Mark | Mark[]) => Array>; export type TextConverter = (node: HTMLTextNode, marks: Mark[]) => Text; export type TagConverter = (node: HTMLElementNode, next: Next) => ConverterResult; export type ConvertTagOptions = Record; export type HandleWhitespaceNodes = "preserve" | "remove"; export type HandleTopLevelText = "preserve" | "remove" | "wrap-paragraph"; export type HandleTopLevelInlines = "preserve" | "remove" | "wrap-paragraph"; export interface ParserOptions { handleWhitespaceNodes: HandleWhitespaceNodes; } export interface PostProcessingOptions { handleTopLevelInlines: HandleTopLevelInlines; handleTopLevelText: HandleTopLevelText; } export interface OptionsWithDefaults { convertTag: ConvertTagOptions; defaultTagConverter: TagConverter; convertText: TextConverter; parserOptions: ParserOptions; postProcessing: PostProcessingOptions; } export type Options = Partial & { parserOptions: Partial; postProcessing: Partial; }>;