UNPKG

legal-markdown-js

Version:

Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version

158 lines 5.76 kB
/** * Legal Markdown Processor with Remark Pipeline * * This module provides a comprehensive processor for Legal Markdown documents * using the remark ecosystem. It combines multiple remark plugins to provide * AST-based processing that avoids text contamination issues. * * Features: * - Complete remark pipeline with all Legal Markdown plugins * - Field tracking integration with automatic clearing * - Cross-reference processing with section numbering * - Metadata extraction and processing * - Comprehensive error handling and debugging * - Compatible with existing Legal Markdown API * * @example * ```typescript * import { processLegalMarkdownWithRemark } from './legal-markdown-processor'; * * const result = await processLegalMarkdownWithRemark(content, { * basePath: './documents', * enableFieldTracking: true, * debug: true * }); * * console.log(result.content); // Processed markdown * console.log(result.metadata); // Extracted metadata * console.log(result.fieldReport); // Field tracking report * ``` * * @module */ /** * Configuration options for the Legal Markdown processor * @interface LegalMarkdownProcessorOptions */ export interface LegalMarkdownProcessorOptions { /** Base path for resolving relative imports */ basePath?: string; /** Enable field tracking and highlighting */ enableFieldTracking?: boolean; /** Enable debug logging */ debug?: boolean; /** Additional metadata to merge with document metadata */ additionalMetadata?: Record<string, any>; /** Custom field patterns for field tracking */ fieldPatterns?: string[]; /** Disable specific processing steps */ disableCrossReferences?: boolean; disableFieldTracking?: boolean; /** Metadata export options */ exportMetadata?: boolean; exportFormat?: 'yaml' | 'json'; exportPath?: string; /** Processing flags (for compatibility with legacy processor) */ yamlOnly?: boolean; noHeaders?: boolean; noClauses?: boolean; noReferences?: boolean; noImports?: boolean; noMixins?: boolean; noReset?: boolean; noIndent?: boolean; throwOnYamlError?: boolean; } /** * Result from Legal Markdown processing * @interface LegalMarkdownProcessorResult */ export interface LegalMarkdownProcessorResult { /** Processed markdown content */ content: string; /** Extracted and processed metadata */ metadata: Record<string, any>; /** Array of exported metadata files */ exportedFiles?: string[]; /** Field tracking report (if enabled) */ fieldReport?: { totalFields: number; uniqueFields: number; fields: Map<string, any>; }; /** Processing statistics and debugging info */ stats: { processingTime: number; pluginsUsed: string[]; crossReferencesFound: number; fieldsTracked: number; }; /** Any warnings or non-fatal errors encountered */ warnings: string[]; } /** * Process Legal Markdown content using remark pipeline * * This is the main entry point for remark-based Legal Markdown processing. * It provides a complete AST-based processing pipeline with: * - YAML frontmatter parsing and metadata extraction * - Template field processing with nested helper support * - Cross-reference resolution and section numbering * - Field tracking for document highlighting * - Import processing for modular documents * - Comprehensive error handling and debugging * * @param content - Raw Legal Markdown content to process * @param options - Processing options and configuration * @returns Promise resolving to processed content, metadata, and statistics * * @example * ```typescript * const result = await processLegalMarkdownWithRemark(markdownContent, { * enableFieldTracking: true, * basePath: './templates', * debug: true * }); * * console.log(result.content); // Processed markdown * console.log(result.stats.fieldsTracked); // Number of tracked fields * ``` */ export declare function processLegalMarkdownWithRemark(content: string, options?: LegalMarkdownProcessorOptions): Promise<LegalMarkdownProcessorResult>; /** * Synchronous version of the Legal Markdown processor * * Note: This is not truly synchronous as remark is async. * This is a simplified fallback that throws an error suggesting async usage. * For real sync processing, use the legacy processor. */ export declare function processLegalMarkdownWithRemarkSync(content: string, options?: LegalMarkdownProcessorOptions): Omit<LegalMarkdownProcessorResult, 'fieldReport'> & { fieldReport?: any; }; /** * Create a pre-configured processor instance for reuse * * This factory function creates a reusable processor instance with pre-configured * options. Useful for batch processing multiple documents with the same settings. * * @param options - Base configuration options for all processing operations * @returns Object with async and sync processing methods * * @example * ```typescript * const processor = createReusableLegalMarkdownProcessor({ * enableFieldTracking: true, * basePath: './templates' * }); * * const result1 = await processor.process(content1); * const result2 = await processor.process(content2, { debug: true }); * ``` */ export declare function createReusableLegalMarkdownProcessor(options?: LegalMarkdownProcessorOptions): { process(content: string, additionalOptions?: Partial<LegalMarkdownProcessorOptions>): Promise<LegalMarkdownProcessorResult>; processSync(content: string, additionalOptions?: Partial<LegalMarkdownProcessorOptions>): Omit<LegalMarkdownProcessorResult, "fieldReport"> & { fieldReport?: any; }; }; //# sourceMappingURL=legal-markdown-processor.d.ts.map