legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
94 lines • 3.14 kB
TypeScript
/**
* Remark Plugin for Import Processing
*
* This plugin processes import directives in legal documents using AST processing.
* Imports allow including content from external files, with support for partial
* content inclusion, metadata merging, and circular import detection.
*
* Features:
* - File-based imports with @import directive
* - Partial content imports from files
* - YAML frontmatter merging from imported files
* - Circular import detection and prevention
* - Relative and absolute path resolution
* - Import caching for performance
*
* @example
* ```typescript
* import { unified } from 'unified';
* import remarkParse from 'remark-parse';
* import remarkStringify from 'remark-stringify';
* import { remarkImports } from './imports';
*
* const processor = unified()
* .use(remarkParse)
* .use(remarkImports, {
* basePath: './documents',
* mergeMetadata: true
* })
* .use(remarkStringify);
* ```
*
* @module
*/
import { Plugin } from 'unified';
import { Root } from 'mdast';
/**
* Options for the remark imports plugin
* @interface RemarkImportsOptions
*/
export interface RemarkImportsOptions {
/** Base path for resolving import files */
basePath?: string;
/** Whether to merge metadata from imported files */
mergeMetadata?: boolean;
/** Enable debug logging */
debug?: boolean;
/** Maximum import depth for circular import prevention */
maxDepth?: number;
/** Maximum execution time in milliseconds for import processing */
timeoutMs?: number;
/** Whether to filter reserved fields from imported metadata */
filterReserved?: boolean;
/** Whether to validate type compatibility before merging */
validateTypes?: boolean;
/** Whether to log import operations for debugging */
logImportOperations?: boolean;
/** Callback for handling imported metadata */
onMetadataMerged?: (mergedMetadata: Record<string, any>, fromFile: string) => void;
/** List of files currently being processed (for circular import detection) */
importStack?: string[];
}
/**
* Result of import processing
*/
export interface ImportResult {
/** The processed content */
content: string;
/** Merged metadata from all imports */
mergedMetadata: Record<string, any>;
/** List of successfully imported files */
importedFiles: string[];
/** Detailed merge statistics */
mergeStats?: {
totalImports: number;
propertiesAdded: number;
conflictsResolved: number;
reservedFieldsFiltered: number;
addedFields: string[];
conflictedFields: string[];
filteredFields: string[];
};
}
/**
* Remark plugin for processing imports
*
* This plugin identifies and processes import directives in markdown text,
* loading content from external files and optionally merging their metadata.
*
* @param options - Configuration options for import processing
* @returns Remark plugin transformer function
*/
export declare const remarkImports: Plugin<[RemarkImportsOptions], Root>;
export default remarkImports;
//# sourceMappingURL=imports.d.ts.map