UNPKG

legal-markdown-js

Version:

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

239 lines 10.2 kB
/** * Main Entry Point for Legal Markdown Processing Library * * This module provides the primary API for processing Legal Markdown documents * with support for YAML front matter, cross-references, optional clauses, mixins, * header processing, and multi-format output generation (HTML, PDF). * * Features: * - YAML front matter parsing and metadata extraction * - Cross-reference processing and resolution * - Optional clause conditional rendering * - Mixin system for reusable content blocks * - Header numbering and formatting * - Field tracking for document highlighting * - HTML and PDF generation with styling * - RST and LaTeX preprocessing support * - Metadata export capabilities * * @example * ```typescript * import { processLegalMarkdown, generateHtml, generatePdf } from 'legal-markdown-js'; * * // Basic document processing * const result = processLegalMarkdown(content, { * enableFieldTracking: true, * basePath: './documents' * }); * * // Generate HTML output * const html = await generateHtml(content, { * title: 'Legal Agreement', * includeHighlighting: true * }); * * // Generate PDF output * const pdf = await generatePdf(content, './output.pdf', { * format: 'A4', * includeHighlighting: true * }); * ``` */ import { fieldTracker } from './extensions/tracking/field-tracker'; import { LegalMarkdownOptions } from './types'; /** * Main function to process a Legal Markdown document (async version) * * This function orchestrates the complete processing pipeline for Legal Markdown * documents, including YAML parsing, content preprocessing, clause processing, * cross-reference resolution, mixin expansion, header formatting, and metadata export. * * @param {string} content - The raw Legal Markdown content to process * @param {LegalMarkdownOptions} [options={}] - Configuration options for processing * @returns {Promise<Object>} Processing result containing processed content, metadata, and reports * @returns {string} returns.content - The processed document content * @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata * @returns {string[]} [returns.exportedFiles] - Array of exported metadata files * @returns {Object} [returns.fieldReport] - Field tracking report if enabled * @example * ```typescript * const result = await processLegalMarkdownAsync(content, { * enableFieldTracking: true, * basePath: './documents', * noClauses: false, * noReferences: false * }); * * console.log(result.content); // Processed markdown * console.log(result.metadata); // YAML front matter * console.log(result.fieldReport); // Field usage report * ``` */ export declare function processLegalMarkdownAsync(content: string, options?: LegalMarkdownOptions): Promise<{ content: string; metadata?: Record<string, any>; exportedFiles?: string[]; fieldReport?: ReturnType<typeof fieldTracker.generateReport>; }>; /** * Main function to process a Legal Markdown document (sync version with fallback) * * This function uses the legacy processing approach to maintain synchronous operation. * For better performance, debugging, and features, consider using the async version * `processLegalMarkdownAsync` which uses the new pipeline system. * * @param {string} content - The raw Legal Markdown content to process * @param {LegalMarkdownOptions} [options={}] - Configuration options for processing * @returns {Object} Processing result containing processed content, metadata, and reports * @returns {string} returns.content - The processed document content * @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata * @returns {string[]} [returns.exportedFiles] - Array of exported metadata files * @returns {Object} [returns.fieldReport] - Field tracking report if enabled * @example * ```typescript * const result = processLegalMarkdown(content, { * enableFieldTracking: true, * basePath: './documents', * noClauses: false, * noReferences: false * }); * * console.log(result.content); // Processed markdown * console.log(result.metadata); // YAML front matter * console.log(result.fieldReport); // Field usage report * ``` */ export declare function processLegalMarkdown(content: string, options?: LegalMarkdownOptions): { content: string; metadata?: Record<string, any>; exportedFiles?: string[]; fieldReport?: ReturnType<typeof fieldTracker.generateReport>; }; /** * Generate HTML from Legal Markdown content * * This function processes Legal Markdown content and generates a complete HTML * document with styling, field highlighting, and responsive design features. * It combines the Legal Markdown processing pipeline with HTML generation. * * @param {string} content - The raw Legal Markdown content to convert * @param {LegalMarkdownOptions & Object} [options={}] - Configuration options * @param {string} [options.cssPath] - Path to custom CSS file * @param {string} [options.highlightCssPath] - Path to field highlighting CSS * @param {boolean} [options.includeHighlighting] - Whether to include field highlighting * @param {string} [options.title] - Document title for HTML * @returns {Promise<string>} A promise that resolves to the complete HTML document * @throws {Error} When HTML generation fails * @example * ```typescript * const html = await generateHtml(content, { * title: 'Service Agreement', * cssPath: './custom-styles.css', * includeHighlighting: true, * enableFieldTracking: true * }); * ``` */ export declare function generateHtml(content: string, options?: LegalMarkdownOptions & { cssPath?: string; highlightCssPath?: string; includeHighlighting?: boolean; title?: string; }): Promise<string>; /** * Generate PDF from Legal Markdown content * * This function processes Legal Markdown content and generates a PDF document * with professional styling, field highlighting, and customizable page formatting. * It combines the Legal Markdown processing pipeline with PDF generation. * * @param {string} content - The raw Legal Markdown content to convert * @param {string} outputPath - File path where the PDF will be saved * @param {LegalMarkdownOptions & Object} [options={}] - Configuration options * @param {string} [options.cssPath] - Path to custom CSS file * @param {string} [options.highlightCssPath] - Path to field highlighting CSS * @param {boolean} [options.includeHighlighting] - Whether to include field highlighting * @param {string} [options.title] - Document title for PDF * @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format * @param {boolean} [options.landscape] - Whether to use landscape orientation * @returns {Promise<Buffer>} A promise that resolves to the PDF buffer * @throws {Error} When PDF generation fails * @example * ```typescript * const pdf = await generatePdf(content, './contract.pdf', { * title: 'Service Agreement', * format: 'A4', * includeHighlighting: true, * enableFieldTracking: true * }); * ``` */ export declare function generatePdf(content: string, outputPath: string, options?: LegalMarkdownOptions & { cssPath?: string; highlightCssPath?: string; includeHighlighting?: boolean; title?: string; format?: 'A4' | 'Letter' | 'Legal'; landscape?: boolean; }): Promise<Buffer>; /** * Generate both normal and highlighted PDF versions * * This function creates two PDF versions of the same Legal Markdown document: * one with standard formatting and another with field highlighting enabled. * This is useful for document review processes where both clean and annotated * versions are needed. * * @param {string} content - The raw Legal Markdown content to convert * @param {string} outputPath - Base file path for PDFs (will be modified for each version) * @param {LegalMarkdownOptions & Object} [options={}] - Configuration options * @param {string} [options.cssPath] - Path to custom CSS file * @param {string} [options.highlightCssPath] - Path to field highlighting CSS * @param {string} [options.title] - Document title for PDFs * @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format * @param {boolean} [options.landscape] - Whether to use landscape orientation * @returns {Promise<Object>} A promise that resolves to both PDF buffers * @returns {Buffer} returns.normal - The normal PDF without highlighting * @returns {Buffer} returns.highlighted - The highlighted PDF with field annotations * @throws {Error} When PDF generation fails * @example * ```typescript * const { normal, highlighted } = await generatePdfVersions(content, './contract.pdf', { * title: 'Service Agreement', * format: 'A4' * }); * // Creates: contract.pdf and contract.HIGHLIGHT.pdf * ``` */ export declare function generatePdfVersions(content: string, outputPath: string, options?: LegalMarkdownOptions & { cssPath?: string; highlightCssPath?: string; title?: string; format?: 'A4' | 'Letter' | 'Legal'; landscape?: boolean; }): Promise<{ normal: Buffer; highlighted: Buffer; }>; export * from './types'; export * from './core/index'; export * from './errors/index'; export * from './constants/index'; export * from './utils/index'; export * from './extensions/index'; export { fieldTracker } from './extensions/tracking/field-tracker'; export { htmlGenerator } from './extensions/generators/html-generator'; export { pdfGenerator } from './extensions/generators/pdf-generator'; export { processLegalMarkdownWithRemark, processLegalMarkdownWithRemarkSync, } from './extensions/remark/legal-markdown-processor'; /** * Wrapper function that provides legacy API compatibility with remark processing * * This function bridges the gap between the legacy `processLegalMarkdown` interface * and the new remark-based processor. It maintains 100% API compatibility while * internally using the modern remark pipeline. * * @param content - The raw Legal Markdown content to process * @param options - Legacy LegalMarkdownOptions (will be mapped to remark options) * @returns Processing result in legacy format */ //# sourceMappingURL=index.d.ts.map