legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
95 lines • 3.3 kB
TypeScript
import { PandocParser, PandocOptions } from './pandoc-parser';
/**
* @fileoverview Pandoc Parser Factory for Cross-Platform Document Processing
*
* This module provides a factory pattern implementation for creating appropriate
* Pandoc parser instances based on the runtime environment. It automatically
* selects between native Pandoc (Node.js) and WASM-based Pandoc (browser)
* implementations to enable document conversion across platforms.
*
* Features:
* - Environment-aware parser selection (Node.js vs Browser)
* - Native Pandoc integration for server-side processing
* - WASM Pandoc support for client-side processing
* - Graceful fallback handling when Pandoc is unavailable
* - Lazy loading of WASM modules for performance
* - Unified interface across different implementations
*
* @example
* ```typescript
* import { PandocFactory } from './pandoc-factory';
*
* // Create a parser instance appropriate for the environment
* const parser = await PandocFactory.create({
* from: 'rst',
* to: 'json'
* });
*
* if (parser) {
* const result = await parser.parse(content);
* }
* ```
*/
/**
* Factory class for creating appropriate Pandoc parser instances
*
* Provides static methods to create Pandoc parser instances based on the
* runtime environment, automatically choosing between native and WASM
* implementations for optimal performance and compatibility.
*
* @class PandocFactory
* @example
* ```typescript
* // Server-side usage (Node.js)
* const nodeParser = await PandocFactory.create({ from: 'latex' });
*
* // Client-side usage (Browser)
* const wasmParser = await PandocFactory.create({ from: 'rst' });
* ```
*/
export declare class PandocFactory {
/**
* Creates a Pandoc parser instance based on the runtime environment
*
* Automatically selects the appropriate implementation:
* - Node.js: Uses native Pandoc binary via child process
* - Browser: Uses Pandoc WASM module for client-side processing
* Returns null if no suitable parser can be created.
*
* @param {PandocOptions} [options={}] - Configuration options for the parser
* @returns {Promise<PandocParser | null>} A promise that resolves to a parser instance or null
* @example
* ```typescript
* // Create parser for RST to JSON conversion
* const parser = await PandocFactory.create({
* from: 'rst',
* to: 'json'
* });
*
* if (parser) {
* const ast = await parser.parse(rstContent);
* console.log('Parsed AST:', ast);
* } else {
* console.log('Pandoc not available in this environment');
* }
* ```
*/
static create(options?: PandocOptions): Promise<PandocParser | null>;
/**
* Create parser for specific content if pandoc is available
*/
static createForContent(content: string, options?: PandocOptions): Promise<PandocParser | null>;
/**
* Check if pandoc is available in current environment
*/
static isAvailable(): Promise<boolean>;
/**
* Get environment info for debugging
*/
static getEnvironmentInfo(): {
environment: 'node' | 'browser';
pandocWasmLoaded: boolean;
pandocWasmInstance: any;
};
}
//# sourceMappingURL=pandoc-factory.d.ts.map