UNPKG

@curvenote/schema

Version:

Schema and markdown parser for @curvenote/editor

50 lines (49 loc) 2.3 kB
import type { GenericNode } from 'mystjs'; import type { Node } from 'prosemirror-model'; import type { MdSerializerState } from '../types'; import { nodeNames } from '../types'; import type { NodeSpecAttrs, NumberedNode } from './types'; export declare const getImageWidth: (width?: number | string | null) => number; export declare function readBooleanAttr(val?: string | boolean | null): boolean; export declare function readBooleanDomAttr(dom: HTMLElement, attr: string): boolean; export declare function convertToBooleanAttribute(value: boolean): "" | undefined; export declare const getNumberedDefaultAttrs: () => NodeSpecAttrs<NumberedNode>; export declare function getAttr(dom: HTMLElement, name: string, defaultValue?: any): any; export declare function getNumberedAttrs(dom: HTMLElement): NumberedNode; export declare function setNumberedAttrs(attrs: Record<string, any>): Record<keyof NumberedNode, string | undefined>; /** * @param node ProsemirrorNode * @param name Name of the node(s) to find * @param descend go through all children of the node, default=false is only direct children * @returns The first node with the name found */ export declare function getFirstChildWithName(node: Node, name: nodeNames | nodeNames[], descend?: boolean): Node | null; export declare const TOTAL_TABLE_WIDTH = 886; export declare function renderPColumn(width: number): string; /** * given a table node, return the column widths * * @param node - node.type.name === 'table' * @returns */ export declare function getColumnWidths(node: Node): { widths: any; columnSpec: any; numColumns: any; }; /** Given a node, return true if there is a fancy table descendent * * "fancy" means there are table_cells or table_headers with * colspan or rowspan > 1. */ export declare function hasFancyTable(node: Node): boolean; export declare function addMdastSnippet(state: MdSerializerState, node: Node): string | false; export declare function writeMdastSnippet(state: MdSerializerState, node: Node): boolean; export declare function normalizeLabel(label?: string | null): { identifier: string; label: string; } | undefined; /** * Take a node and return a single flattened text value from value/children */ export declare function flattenValues(node: GenericNode): string;