UNPKG

legal-markdown-js

Version:

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

105 lines 3.37 kB
/** * Base Processor Interface for Legal Markdown Processing Pipeline * * This module defines the fundamental interface that all processors in the Legal Markdown * pipeline must implement. It provides a standardized contract for processing steps, * enabling the pipeline manager to orchestrate document processing in a consistent manner. * * Features: * - Standardized processor interface * - Enable/disable logic per processor * - Consistent processing contract * - Pipeline orchestration support * - Backward compatibility with existing processors * * @example * ```typescript * import { BaseProcessor } from './base-processor.js'; * * class MyCustomProcessor implements BaseProcessor { * name = 'my-custom-processor'; * * isEnabled(options: LegalMarkdownOptions): boolean { * return !options.noCustomProcessing; * } * * process(content: string, metadata: Record<string, any>, options: any): string { * // Custom processing logic * return processedContent; * } * } * ``` * * @module */ /** * Abstract base class that provides common functionality for processors * * This class implements common patterns and provides utility methods that * most processors will need, reducing boilerplate code. * * @abstract * @class AbstractProcessor * @example * ```typescript * class MyProcessor extends AbstractProcessor { * name = 'my-processor'; * * isEnabled(options: LegalMarkdownOptions): boolean { * return !options.noMyProcessor; * } * * protected performProcessing(content: string, metadata: Record<string, any>, options: LegalMarkdownOptions): string { * // Actual processing logic here * return processedContent; * } * } * ``` */ export class AbstractProcessor { /** * Template method that handles common processing patterns * * This method provides error handling, logging, and other common functionality, * delegating the actual processing to the performProcessing method. */ process(content, metadata, options) { if (!this.isEnabled(options)) { return content; } try { return this.performProcessing(content, metadata, options); } catch (error) { console.warn(`Processor '${this.name}' failed, returning original content:`, error); return content; } } /** * Utility method to check if content has already been processed by another step * * This helps prevent double-processing and conflicts between processors. * * @param content - The content to check * @returns True if content appears to have been processed (contains spans, etc.) * @protected */ hasBeenProcessed(content) { return (content.includes('class="imported-value"') || content.includes('class="missing-value"') || content.includes('class="highlight"')); } /** * Utility method to log processing information in debug mode * * @param message - The message to log * @param data - Optional data to include in the log * @protected */ debug(message, data) { if (process.env.NODE_ENV === 'development') { console.log(`[${this.name.toUpperCase()}] ${message}`, data || ''); } } } //# sourceMappingURL=base-processor.js.map