UNPKG

legal-markdown-js

Version:

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

87 lines 3.06 kB
/** * Remark plugin for field tracking in Legal Markdown documents * * This plugin processes text nodes to track field usage for highlighting and * analysis purposes. It excludes code blocks and inline code to prevent * false positives from field-like patterns in code. * * Features: * - Tracks field patterns like {{field_name}} in text nodes only * - Excludes code and inlineCode nodes to prevent contamination * - Integrates with field tracker for highlighting support * - Supports both simple fields and complex field expressions * - Maintains field usage statistics and metadata * * @example * ```typescript * import { unified } from 'unified'; * import remarkParse from 'remark-parse'; * import remarkFieldTracking from './field-tracking.js'; * * const processor = unified() * .use(remarkParse) * .use(remarkFieldTracking, { * patterns: ['{{(.+?)}}'], // Custom field patterns * trackingEnabled: true * }); * ``` * * @module */ import type { Plugin } from 'unified'; import type { Root, Text, Node } from 'mdast'; import type { YamlValue } from '../../types/index.js'; /** * Configuration options for the field tracking plugin */ export interface FieldTrackingOptions { /** Enable/disable field tracking (default: true) */ trackingEnabled?: boolean; /** Custom field patterns to track (default: ['{{(.+?)}}']) */ patterns?: string[]; /** Debug mode for logging field tracking operations */ debug?: boolean; /** Metadata object to store tracking statistics */ metadata?: Record<string, YamlValue>; } /** * Field tracking result information */ interface FieldTrackingResult { /** The field key/name */ key: string; /** The original field pattern matched */ originalValue: string; /** The resolved field value */ value: string; /** Whether this field has logic/processing */ hasLogic: boolean; /** Position information if available */ position?: { line: number; column: number; }; } /** * Check if a node should be excluded from field tracking */ declare function shouldExcludeNode(node: Node, parent?: Node): boolean; /** * Extract field name from matched pattern */ declare function extractFieldName(match: string, pattern: string): string; /** * Resolve field value from metadata or return empty string */ declare function resolveFieldValue(fieldName: string, metadata: Record<string, YamlValue>): string; /** * Track fields found in a text node */ declare function trackFieldsInTextNode(textNode: Text, patterns: string[], metadata: Record<string, YamlValue>, debug?: boolean): FieldTrackingResult[]; /** * Remark plugin for field tracking in Legal Markdown documents */ declare const remarkFieldTracking: Plugin<[FieldTrackingOptions?], Root>; export default remarkFieldTracking; export { shouldExcludeNode as _shouldExcludeNode, extractFieldName as _extractFieldName, resolveFieldValue as _resolveFieldValue, trackFieldsInTextNode as _trackFieldsInTextNode, }; //# sourceMappingURL=field-tracking.d.ts.map