UNPKG

ts-markdown

Version:

An extensible TypeScript markdown generator that takes JSON and creates a markdown document.

78 lines (77 loc) 2.55 kB
import { MarkdownRenderer } from '../rendering.types'; import { MarkdownEntry, SupportedPrimitive, RichTextEntry } from '../shared.types'; /** * A markdown entry for generating tables. */ export interface TableEntry extends MarkdownEntry { /** * The table row and column data, and identifying property for the renderer. */ table: { /** * The column headers for the table. */ columns: (TableColumn | string)[]; /** * The row data for the table. */ rows: (TableRow | TableCell[])[]; }; /** * Option which will arbitrarily append a string immediately below the table, ignoring block-level settings. */ append?: string; /** * Function to replace pipes in a cell's content, which is necessary to avoid breaking the table layout. * @defaultValue Function which replaces pipe characters with the entity "&#124;". */ pipeReplacer?: (content: string) => string; /** * Determines whether the "prefix" specified via RenderOptions is applied to cell values or not. If set to true, * every data cell (excluding table headers and the separator row) will have the prefix prepended. If set to false, * then the prefix will not be included in the cells. * * In any case, the prefix will be prepended to every row of the table (including header and separator rows). * * @defaultValue true */ prefixCellValues?: boolean; } /** * A table column header. */ export declare type TableColumn = { /** * The name of the column. */ name: string; /** * The property which the column should use when pulling data from a given row. * If not specified, then `name` will be used as the field. */ field?: string; /** * The horizontal alignment of the entire column. */ align?: 'left' | 'center' | 'right'; }; /** * A a row of table data. */ export declare type TableRow = { /** * A cell of table data. * Each key in this object represents a column header name, case-sensitively. */ [key: string]: TableCell; }; export declare type TableCell = RichTextEntry | SupportedPrimitive; /** * The renderer for table entries. * * @param entry The table entry. * @param options Document-level render options. * @returns Block-level table markdown content. */ export declare const tableRenderer: MarkdownRenderer; export declare function table(settings: TableEntry['table'], options?: Omit<TableEntry, 'table'>): TableEntry;