UNPKG

legal-markdown-js

Version:

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

103 lines 3.59 kB
/** * @fileoverview Force Commands Parser for Legal Markdown * * This module provides functionality to parse and apply forced configuration commands * from YAML front matter. It allows documents to specify their own processing options * directly in the document metadata, enabling automatic configuration based on document content. * * Features: * - Parse command strings from YAML front matter * - Support for template variable resolution in commands * - Integration with existing CLI options * - Override protection for critical options * - Validation and error handling * * @example * ```yaml * --- * title: Contract * client: Acme Corp * force_commands: > * --css custom.css * --output-name Contract_{{title}}_{{client}}_{{formatDate(date, "YYYYMMDD")}}.pdf * --pdf --highlight * --- * ``` */ import { LegalMarkdownOptions } from '../../types'; /** * Interface for parsed command line arguments */ export interface ParsedCommands { /** CSS file path */ css?: string; /** Output file name/path (maps to CLI --output) */ output?: string; /** PDF generation flag */ pdf?: boolean; /** HTML generation flag */ html?: boolean; /** Field highlighting flag */ highlight?: boolean; /** Export YAML metadata flag */ exportYaml?: boolean; /** Export JSON metadata flag */ exportJson?: boolean; /** Custom output path for exports */ outputPath?: string; /** Page format for PDF */ format?: 'A4' | 'letter' | 'legal'; /** Landscape orientation flag */ landscape?: boolean; /** Debug mode flag */ debug?: boolean; /** Custom title */ title?: string; } /** * Parse a force_commands string into structured options * * @param commandString - The command string from YAML front matter * @param metadata - Document metadata for template resolution * @param processingOptions - Current processing options for template context * @returns Parsed command options or null if parsing fails * * @example * ```typescript * const commands = parseForceCommands( * "--css theme.css --pdf --output-name {{title}}_{{client}}.pdf", * { title: "Contract", client: "Acme" }, * {} * ); * // Returns: { css: "theme.css", pdf: true, output: "Contract_Acme.pdf" } * ``` */ export declare function parseForceCommands(commandString: string, metadata?: Record<string, any>, processingOptions?: Partial<LegalMarkdownOptions>): ParsedCommands | null; /** * Apply parsed force commands to existing options * * Force commands will override existing options where applicable. * Some options (like processing flags) are preserved from original options. * * @param existingOptions - Current processing options * @param forceCommands - Parsed force commands to apply * @returns Updated options with force commands applied * * @example * ```typescript * const updated = applyForceCommands( * { debug: false, pdf: false }, * { debug: true, css: "custom.css" } * ); * // Returns: { debug: true, pdf: false, css: "custom.css" } * ``` */ export declare function applyForceCommands(existingOptions: Partial<LegalMarkdownOptions> & Record<string, any>, forceCommands: ParsedCommands): Partial<LegalMarkdownOptions> & Record<string, any>; /** * Check if metadata contains force_commands and extract them * * @param metadata - Document metadata from YAML front matter * @returns Force commands string or null if not found */ export declare function extractForceCommands(metadata: Record<string, any>): string | null; //# sourceMappingURL=force-commands-parser.d.ts.map