legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
64 lines • 2.07 kB
TypeScript
/**
* Remark plugin for Legal Markdown template field processing
*
* This plugin processes template fields like {{field_name}} in Legal Markdown documents
* using AST-based processing. It handles:
* - Simple variables: {{client.name}}
* - Nested object access: {{client.contact.email}}
* - Helper functions: {{formatDate(@today, "YYYY-MM-DD")}}
* - Conditional expressions: {{active ? "Active" : "Inactive"}}
* - Field tracking integration for highlighting
*
* Architecture:
* 1. Parse template field patterns in text nodes
* 2. Resolve field values from metadata
* 3. Replace patterns with resolved values
* 4. Track fields for highlighting support
*
* @example
* ```typescript
* import { unified } from 'unified';
* import remarkParse from 'remark-parse';
* import remarkTemplateFields from './template-fields';
*
* const processor = unified()
* .use(remarkParse)
* .use(remarkTemplateFields, { metadata: { client_name: 'ACME Corp' } });
*
* const result = await processor.process('Hello {{client_name}}!');
* ```
*
* @module
*/
import type { Plugin } from 'unified';
import type { Root } from 'mdast';
/**
* Template field definition extracted from text
*/
interface TemplateField {
pattern: string;
fieldName: string;
expression: string;
startIndex: number;
endIndex: number;
}
/**
* Plugin options for template field processing
*/
interface TemplateFieldOptions {
/** Document metadata containing field values */
metadata: Record<string, any>;
/** Enable debug logging */
debug?: boolean;
/** Custom field patterns (defaults to {{field}} syntax) */
fieldPatterns?: string[];
/** Enable field tracking with highlighting during AST processing */
enableFieldTracking?: boolean;
}
/**
* Remark plugin for processing template fields in Legal Markdown documents
*/
declare const remarkTemplateFields: Plugin<[TemplateFieldOptions], Root>;
export default remarkTemplateFields;
export type { TemplateFieldOptions, TemplateField };
//# sourceMappingURL=template-fields.d.ts.map