legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
69 lines • 2.46 kB
TypeScript
/**
* Cross-Reference Processing Module for Legal Markdown Documents
*
* This module provides functionality to process internal cross-references in Legal Markdown
* documents, allowing sections to reference other sections by their keys.
* Based on the original Ruby Legal Markdown specification.
*
* Features:
* - Internal cross-reference syntax: |reference_key|
* - Automatic section numbering and reference resolution
* - Reference capture from headers with |key| syntax
* - Section reference replacement throughout the document
* - Compatible with legal document numbering (l., ll., lll.)
*
* @example
* ```typescript
* import { processCrossReferences } from './reference-processor';
*
* const content = `
* l. **Definitions** |definitions|
*
* Terms defined in |definitions| apply throughout this agreement.
*
* l. **Payment Terms** |payment|
*
* As outlined in |payment|, payment is due within 30 days.
* Reference to |definitions| for term meanings.
* `;
*
* const processed = processCrossReferences(content, {});
* console.log(processed);
* // Output:
* // Article 1. **Definitions**
* //
* // Terms defined in Article 1 apply throughout this agreement.
* //
* // Article 2. **Payment Terms**
* //
* // As outlined in Article 2, payment is due within 30 days.
* // Reference to Article 1 for term meanings.
* ```
*/
/**
* Processes internal cross-references in a Legal Markdown document
*
* This function implements a hybrid approach:
* 1. First tries to resolve |key| as internal section references (Ruby spec)
* 2. Falls back to metadata values for backward compatibility
*
* @param {string} content - The document content containing cross-references
* @param {Record<string, any>} metadata - Document metadata (used for level formatting and fallback)
* @returns {string} Processed content with internal references resolved
* @example
* ```typescript
* const content = `
* l. **Contract Terms** |terms|
*
* As specified in |terms|, this agreement is binding.
* Reference to |client_name| from metadata.
* `;
*
* const metadata = { client_name: "ACME Corp" };
* const result = processCrossReferences(content, metadata);
* // |terms| -> "Article 1." (internal reference)
* // |client_name| -> "ACME Corp" (metadata fallback)
* ```
*/
export declare function processCrossReferences(content: string, metadata: Record<string, any>): string;
//# sourceMappingURL=reference-processor.d.ts.map