legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
126 lines • 4.14 kB
TypeScript
/**
* Remark Plugin for Mixin Processing
*
* This plugin processes mixins in legal documents using AST processing.
* Mixins provide a way to include reusable content blocks and templates
* within legal documents, with support for variable substitution and
* conditional logic.
*
* Features:
* - Mixin inclusion with @include directive
* - Variable substitution within mixins
* - Nested mixin support
* - Template field processing within mixins
* - File-based mixin imports
*
* @example
* ```typescript
* import { unified } from 'unified';
* import remarkParse from 'remark-parse';
* import remarkStringify from 'remark-stringify';
* import { remarkMixins } from './mixins.js';
*
* const processor = unified()
* .use(remarkParse)
* .use(remarkMixins, {
* metadata: { client: 'ACME Corp' },
* basePath: './mixins'
* })
* .use(remarkStringify);
* ```
*
* @module
*/
import { Plugin } from 'unified';
import { Root, Text } from 'mdast';
import type { YamlValue } from '../../types/index.js';
/**
* Options for the remark mixins plugin
* @interface RemarkMixinsOptions
*/
export interface RemarkMixinsOptions {
/** Document metadata for variable substitution */
metadata: Record<string, YamlValue>;
/** Base path for resolving mixin files */
basePath?: string;
/** Enable debug logging */
debug?: boolean;
/** Maximum recursion depth for nested mixins */
maxDepth?: number;
/** Custom mixin definitions */
customMixins?: Record<string, string>;
}
/**
* Mixin inclusion directive
*/
interface MixinDirective {
/** Name of the mixin to include */
name: string;
/** Parameters passed to the mixin */
parameters?: Record<string, YamlValue>;
/** Start and end positions in the text */
start: number;
end: number;
/** Full match text */
fullMatch: string;
}
/**
* Mixin processing context
*/
interface MixinContext {
/** Current recursion depth */
depth: number;
/** Maximum allowed depth */
maxDepth: number;
/** Base path for file resolution */
basePath: string;
/** Global metadata */
metadata: Record<string, YamlValue>;
/** Debug mode flag */
debug: boolean;
/** Custom mixin definitions */
customMixins: Record<string, string>;
/** Cache of loaded mixin files */
fileCache: Map<string, string>;
}
/**
* Remark plugin for processing mixins
*
* This plugin identifies and processes mixin inclusion directives in markdown text,
* loading mixin content from files or inline definitions and performing variable
* substitution within the mixin content.
*
* @param options - Configuration options for mixin processing
* @returns Remark plugin transformer function
*/
export declare const remarkMixins: Plugin<[RemarkMixinsOptions], Root>;
/**
* Process a text node for mixin directives
*/
declare function processTextNode(node: Text, context: MixinContext): void;
/**
* Extract mixin directives from text
*/
declare function extractMixinDirectives(text: string): MixinDirective[];
/**
* Parse parameter string into object
*/
declare function parseParameters(paramString: string): Record<string, YamlValue>;
/**
* Parse a parameter value (string, number, boolean)
*/
declare function parseParameterValue(value: string): YamlValue;
/**
* Process a mixin directive
*/
declare function processMixinDirective(directive: MixinDirective, context: MixinContext): string;
/**
* Load mixin content from custom definitions or files
*/
declare function loadMixinContent(mixinName: string, context: MixinContext): string | null;
/**
* Process template fields within mixin content
*/
declare function processTemplateFields(content: string, metadata: Record<string, YamlValue>, debug: boolean): string;
export { processTextNode as _processTextNode, extractMixinDirectives as _extractMixinDirectives, parseParameters as _parseParameters, parseParameterValue as _parseParameterValue, processMixinDirective as _processMixinDirective, loadMixinContent as _loadMixinContent, processTemplateFields as _processTemplateFields, };
//# sourceMappingURL=mixins.d.ts.map