docstudio API reference
Every public export of docstudio in DocStudio 0.2.0: functions, constants, types and interfaces with signatures.
Import from docstudio.
Never throws. Problems are returned as diagnostics.
Functions
renderDocument
Compiles and renders a template with data in one call and returns ok, html and the merged diagnostics.
renderDocument(template: unknown, data: unknown, options?: RenderDocumentOptions): RenderedDocumentErrors. Never throws. A template that cannot be compiled returns ok false and empty html.
import { renderDocument } from 'docstudio';
export function run(): string {
const result = renderDocument(
{
schemaVersion: '1.0.0',
body: [{ id: 'hello', type: 'text', content: ['Hello ', { path: 'name' }] }],
},
{ name: 'Ada' },
{ target: 'print', title: 'Greeting' },
);
if (!result.ok) {
throw new Error(result.diagnostics.map((item) => item.message).join('; '));
}
return result.html;
}Interfaces
RenderDocumentOptions
export interface RenderDocumentOptions {
readonly target?: RenderTarget;
readonly title?: string;
readonly lang?: string;
readonly assets?: RenderOptions['assets'];
readonly maxImageBytes?: number;
readonly fonts?: RenderOptions['fonts'];
readonly compile?: Omit<CompileOptions, 'template' | 'data'>;
}RenderedDocument
export interface RenderedDocument {
readonly ok: boolean;
readonly html: string;
readonly diagnostics: readonly Diagnostic[];
}