legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
225 lines • 9.64 kB
TypeScript
/**
* 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, DOCX).
*
* 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, PDF, and DOCX 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 = await 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 { LegalMarkdownOptions } from './types/index.js';
import { processLegalMarkdown as processLegalMarkdownImpl } from './extensions/remark/legal-markdown-processor.js';
import { type PdfConnectorPreference } from './extensions/generators/pdf-connectors/index.js';
/**
* Process Legal Markdown content using the canonical async remark pipeline.
*
* @param content - Raw Legal Markdown document content.
* @param options - Optional processing settings for parsing, plugins, tracking, and exports.
* @returns Promise resolving to processed markdown, metadata, and optional tracking statistics.
* @throws {ValidationError | PipelineError | ParseError | ImportError | ProcessingError | YamlParsingError | PdfDependencyError}
* Throws typed processing errors when parsing, import resolution, or pipeline execution fails.
* @example
* ```typescript
* import { processLegalMarkdown } from 'legal-markdown-js';
*
* const result = await processLegalMarkdown(markdown, {
* basePath: './docs',
* enableFieldTracking: true,
* });
*
* console.log(result.content);
* ```
*/
export declare const processLegalMarkdown: typeof processLegalMarkdownImpl;
/**
* 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>;
type PublicPdfGenerationOptions = LegalMarkdownOptions & {
cssPath?: string;
highlightCssPath?: string;
includeHighlighting?: boolean;
title?: string;
format?: 'A4' | 'Letter' | 'Legal';
landscape?: boolean;
basePath?: string;
headerTemplate?: string;
footerTemplate?: string;
pdfConnector?: PdfConnectorPreference;
};
/**
* 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
* @param {'auto' | 'puppeteer' | 'system-chrome' | 'weasyprint'} [options.pdfConnector] - PDF backend connector
* @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?: PublicPdfGenerationOptions): 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
* @param {'auto' | 'puppeteer' | 'system-chrome' | 'weasyprint'} [options.pdfConnector] - PDF backend connector
* @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?: Omit<PublicPdfGenerationOptions, 'includeHighlighting'>): Promise<{
normal: Buffer;
highlighted: Buffer;
}>;
/**
* Generate DOCX from Legal Markdown content
*
* @param {string} content - The raw Legal Markdown content to convert
* @param {string} outputPath - File path where the DOCX 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 DOCX
* @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 DOCX buffer
* @throws {Error} When DOCX generation fails
*/
export declare function generateDocx(content: string, outputPath: string, options?: LegalMarkdownOptions & {
cssPath?: string;
highlightCssPath?: string;
includeHighlighting?: boolean;
title?: string;
format?: 'A4' | 'Letter' | 'Legal';
landscape?: boolean;
basePath?: string;
headerTemplate?: string;
footerTemplate?: string;
}): Promise<Buffer>;
/**
* Generate both normal and highlighted DOCX versions
*/
export declare function generateDocxVersions(content: string, outputPath: string, options?: LegalMarkdownOptions & {
cssPath?: string;
highlightCssPath?: string;
title?: string;
format?: 'A4' | 'Letter' | 'Legal';
landscape?: boolean;
basePath?: string;
headerTemplate?: string;
footerTemplate?: string;
}): Promise<{
normal: Buffer;
highlighted: Buffer;
}>;
export * from './types/index.js';
export * from './core/index.js';
export * from './errors/index.js';
export * from './constants/index.js';
export * from './utils/index.js';
export * from './extensions/index.js';
export { fieldTracker } from './extensions/tracking/field-tracker.js';
export { htmlGenerator } from './extensions/generators/html-generator.js';
export { pdfGenerator } from './extensions/generators/pdf-generator.js';
export { docxGenerator } from './extensions/generators/docx-generator.js';
//# sourceMappingURL=index.d.ts.map