A complete Node.js/TypeScript reimplementation of the original Ruby LegalMarkdown tool with 100% feature parity.
Process markdown with YAML front matter, conditional clauses [text]{condition}, cross-references |reference|, mixins {{variable}}, imports @import, and generate professional PDFs ready to be shared.
- Core Parity: 1:1 compatibility with the original Ruby legal-markdown tool in src/core/
- Node.js Extensions: Additional functionality leveraging the Node.js ecosystem in src/extensions/
- Type Safety: Full TypeScript implementation with comprehensive type definitions
- Modern Tooling: Built with modern development practices and tooling
After installation, you'll have access to these commands:
- legal-md - Standard command-line interface with options and flags
- legal-md-ui - Interactive CLI with guided prompts and smart defaults
- legal-md-setup - Configuration setup script for easy environment setup
- legal-md-playground - Local playground server for testing and exploration
- legal2md - Alias for legal-md (for compatibility)
Live Playground - Try Legal Markdown JS directly in your browser with live examples and real-time processing.
You can also run the playground locally for offline use or testing:
The playground provides the same interactive experience as the online version, including real-time processing, syntax highlighting, and example templates.
For the best experience, especially if you're new to Legal Markdown JS, run the setup script to configure your environment:
This creates a personalized configuration file that the tool will automatically find and use.
For a guided, user-friendly experience, use the interactive CLI:
The interactive CLI provides:
- 📁 Smart file discovery: Automatically scans your input directory for supported files (.md, .markdown, .rst, .tex, .latex, .txt)
- 🎯 Multiple output formats: Select any combination of PDF, HTML, Markdown, and metadata export
- ⚙️ Conditional options: Processing options adapt based on your selected formats
- 🎨 CSS selection: Choose from available stylesheets or proceed without custom styling
- 📦 Source archiving: Configure automatic archiving of source files after successful processing
- 📋 Configuration summary: Review all settings before processing
- ✅ Clear results: See exactly which files were generated
All original Legal Markdown features are fully implemented:
- File Formats: Markdown, ASCII, reStructuredText, LaTeX
- YAML Front Matter: Complete parsing with all standard fields
- Headers & Numbering: Full hierarchical numbering system (l., ll., lll.)
- Optional Clauses: Boolean, equality, and logical operations ([text]{condition})
- Cross-References: Internal section references using (|reference|) syntax
- Partial Imports: File inclusion with path resolution (@import)
- Metadata Export: YAML and JSON export with custom paths
Additional features available only in the Node.js version:
- Interactive CLI: User-friendly guided interface with smart file discovery and configuration management
- Mixins System: Template substitution and helpers with {{variable}} syntax
- AST-Based Processing: Modern AST-based mixin processing to prevent text contamination (v2.4.0+)
- Pipeline Architecture: Configurable step-based processing pipeline with dependency management and performance monitoring (v2.4.0+)
- PDF Generation: Professional PDF output with styling and field highlighting
- HTML Generation: Custom HTML output with CSS support
- Template Loops: Array iteration with {{#items}}...{{/items}} syntax
- Helper Functions: Date, number, and string formatting helpers
- Force Commands: Document-driven configuration with embedded CLI options
- Batch Processing: Multi-file processing with concurrency control
- Field Tracking: Enhanced field tracking with proper categorization for document review
- Source File Archiving: Automatic archiving of source files after successful processing with conflict resolution
Legal Markdown JS features a completely rewritten processing pipeline that provides:
- Step-Based Architecture: Configurable processing steps with dependency management
- AST-Based Processing: Modern AST parsing for mixin processing to prevent text contamination
- Performance Monitoring: Built-in step profiling and performance metrics
- Error Recovery: Graceful fallback to legacy processing when needed
- Field Tracking: Enhanced field tracking with proper status categorization
The new pipeline ensures correct processing order to prevent conflicts:
- YAML Front Matter - Parse document metadata
- Import Processing - Handle file imports and inclusions
- Optional Clauses - Process conditional text blocks
- Cross-References - Resolve internal document references
- Template Loops - Expand array iterations first
- AST Mixin Processing - Process variables and helpers (avoids loop conflicts)
- Header Processing - Apply numbering and formatting
- Field Tracking - Apply highlighting and generate reports
- Getting Started - Installation and setup guide
- CLI Reference - Complete command-line interface documentation
- Features Guide - All features, helpers, and advanced usage
- Headers & Numbering - Hierarchical numbering system guide
- CSS Classes Reference - CSS classes for styling and document review
- Compatibility - Ruby version compatibility tracking
- Architecture - Complete system architecture and design patterns
- Contributing Guide - Development workflow, standards, and contribution guidelines
- Helper Functions - Complete reference for template helpers and functions
- Development Guide - Complete developer setup and workflow
- Release Process - Versioning and release procedures
- Scripts Reference - Available npm scripts and commands
- API Documentation - Auto-generated TypeScript API docs
- Unit Tests: Test individual components in isolation
- Integration Tests: Test complete workflows and feature combinations
- E2E Tests: Test CLI interface and full application behavior
- Path Validation Tests: Test environment configuration and error handling
Legal Markdown JS supports environment-based configuration for customizing file paths and directories.
For easy configuration setup, especially for non-technical users:
This script will:
- Create a configuration directory at ~/.config/legal-markdown-js/
- Copy the configuration template with helpful comments
- Provide clear instructions on how to customize your paths
- Show you exactly where to edit your settings
If you prefer manual setup, create a .env file in one of these locations (in order of precedence):
- Current working directory: ./.env
- Your home directory: ~/.env
- Config directory: ~/.config/legal-markdown-js/.env
We welcome contributions! Please see our Contributing Guide for:
- Development setup and workflow
- Coding standards and best practices
- Testing requirements
- Pull request process
- Fork the repository
- Create a feature branch (git checkout -b feature/amazing-feature)
- Follow the development guidelines
- Run the test suite (npm test)
- Submit a Pull Request
MIT License - see LICENSE file for details.
- Original LegalMarkdown project by Casey Kuhlman
- The legal tech community for inspiration and feedback