legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
127 lines • 4.98 kB
TypeScript
/**
* YAML Front Matter Auto-Population Module for Legal Markdown Documents
*
* This module provides functionality to auto-populate YAML front matter with inferred
* header level patterns and processing properties following the original Legal Markdown
* specification. It analyzes document structure and generates enhanced metadata.
*
* Features:
* - Document structure analysis for header level inference
* - Auto-population of missing header level definitions
* - Properties section generation (no-indent, no-reset, level-style)
* - YAML front matter enhancement and standardization
* - Support for both traditional (l., ll., lll.) and alternative syntax
*
* @example
* ```typescript
* import { autoPopulateYamlFrontMatter } from './yaml-auto-population.js';
*
* const content = `---
* level-1: "Article 1."
* level-2: "Section 1."
* ---
* l. Introduction
* ll. Terms`;
*
* const enhanced = autoPopulateYamlFrontMatter(content);
* // Returns document with enhanced YAML front matter including
* // all level definitions and Properties section
* ```
*
* @module
*/
/**
* Configuration for YAML auto-population
*/
interface YamlAutoPopulationOptions {
/** Whether to add Properties section with processing configurations */
includeProperties?: boolean;
/** Whether to infer missing header levels from document content */
inferMissingLevels?: boolean;
/** Whether to ensure all level definitions are properly quoted */
ensureQuotedLevels?: boolean;
}
/**
* Default header level patterns following Legal Markdown conventions
*
* For complete documentation on header formats and variable usage, see:
* @see {@link ../../../docs/headers_numbering.md} - Complete guide to headers and numbering system
*/
/**
* Auto-populates YAML front matter with inferred header patterns and properties
*
* Analyzes the document structure and enhances the YAML front matter with:
* - Missing header level definitions
* - Properties section with processing configurations
* - Properly quoted level definitions
*
* @param {string} content - The document content with YAML front matter
* @param {YamlAutoPopulationOptions} [options={}] - Configuration options
* @returns {string} Document with enhanced YAML front matter
* @example
* ```typescript
* const input = `---
* level-1: "Article 1."
* ---
* l. Introduction
* ll. Terms`;
*
* const result = autoPopulateYamlFrontMatter(input);
* // Returns document with complete level definitions and Properties section
* ```
*/
export declare function autoPopulateYamlFrontMatter(content: string, options?: YamlAutoPopulationOptions): string;
/**
* Creates enhanced metadata with structured headers and properties sections
*
* @private
* @param {Record<string, any>} existingMetadata - Current document metadata
* @param {boolean} includeProperties - Whether to include Properties section
* @param {boolean} inferMissingLevels - Whether to infer missing levels
* @param {boolean} ensureQuotedLevels - Whether to ensure levels are quoted
* @returns {Record<string, any>} Enhanced metadata object
*/
declare function createEnhancedMetadata(existingMetadata: Record<string, unknown>, includeProperties?: boolean, inferMissingLevels?: boolean, _ensureQuotedLevels?: boolean): Record<string, unknown>;
/**
* Analyzes document content to infer header usage patterns
*
* Scans the document content to determine which header levels are actually used
* and what no-indent patterns might be appropriate.
*
* @private
* @param {string} content - The document content to analyze
* @returns {Object} Analysis results with detected patterns
*/
declare function analyzeDocumentStructure(content: string): {
usedLevels: number[];
noIndentPattern: string;
hasAlternativeSyntax: boolean;
};
/**
* Generates appropriate no-indent pattern based on document analysis
*
* @private
* @param {string} content - Document content to analyze
* @returns {string} Comma-separated no-indent pattern
*/
export declare function generateNoIndentPattern(content: string): string;
/**
* Validates and normalizes YAML front matter structure
*
* Ensures the YAML front matter follows the expected structure with
* proper sectioning and formatting.
*
* @param {Record<string, any>} metadata - Metadata to validate
* @returns {Record<string, any>} Normalized metadata
*/
export declare function normalizeYamlStructure(metadata: Record<string, unknown>): Record<string, unknown>;
/**
* Formats enhanced metadata as YAML with proper comment handling
*
* @private
* @param {Record<string, any>} metadata - Enhanced metadata to format
* @returns {string} Formatted YAML string
*/
declare function formatEnhancedYaml(metadata: Record<string, unknown>): string;
export { createEnhancedMetadata as _createEnhancedMetadata, analyzeDocumentStructure as _analyzeDocumentStructure, formatEnhancedYaml as _formatEnhancedYaml, };
//# sourceMappingURL=yaml-auto-population.d.ts.map