legal-markdown-js
Version:
Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version
111 lines • 3.61 kB
TypeScript
/**
* @fileoverview reStructuredText Parser Extension for Legal Markdown
*
* This module provides functionality to parse reStructuredText (.rst) documents
* and convert them to Legal Markdown format. It uses Pandoc for robust parsing
* with intelligent fallback to basic regex-based parsing when Pandoc is not
* available or fails.
*
* Features:
* - AST-based reStructuredText parsing using Pandoc
* - Fallback regex-based parsing for simple documents
* - Content type detection and validation
* - Section header conversion to Legal Markdown syntax
* - Text formatting preservation (emphasis, strong)
* - Code block and literal block handling
* - Bullet and enumerated list conversion
* - Reference and hyperlink preservation
*
* @example
* ```typescript
* import { convertRstToLegalMarkdown, convertRstToLegalMarkdownSync } from './rst-parser';
*
* const rstContent = `
* ============
* Introduction
* ============
*
* This is a sample reStructuredText document.
*
* Section 1
* =========
*
* Some *emphasized* and **strong** text.
* `;
*
* // Async conversion (preferred)
* const legalMarkdown = await convertRstToLegalMarkdown(rstContent);
*
* // Sync conversion (fallback)
* const legalMarkdownSync = convertRstToLegalMarkdownSync(rstContent);
* ```
*/
/**
* Converts reStructuredText content to markdown format using pandoc
*/
export declare function parseRestructuredText(content: string): Promise<string>;
/**
* Synchronous version using fallback parser
*/
export declare function parseRestructuredTextSync(content: string): string;
/**
* Checks if a file appears to be reStructuredText
*/
export declare function isRestructuredText(content: string): boolean;
/**
* Converts reStructuredText content to Legal Markdown format (async version)
*
* This function provides robust conversion of reStructuredText documents to Legal
* Markdown format using Pandoc when available. It automatically detects RST content
* and only performs conversion when necessary, preserving non-RST content unchanged.
*
* @param {string} content - The input content that may contain reStructuredText
* @returns {Promise<string>} A promise that resolves to Legal Markdown formatted content
* @example
* ```typescript
* const rstContent = `
* ============
* Introduction
* ============
*
* This is a sample reStructuredText document.
* `;
*
* const legalMarkdown = await convertRstToLegalMarkdown(rstContent);
* console.log(legalMarkdown);
* // Output:
* // l. Introduction
* //
* // This is a sample reStructuredText document.
* ```
*/
export declare function convertRstToLegalMarkdown(content: string): Promise<string>;
/**
* Converts reStructuredText content to Legal Markdown format (sync version)
*
* This synchronous function provides fallback conversion of reStructuredText
* documents using regex-based parsing when Pandoc is not available. It's designed
* for environments where async operations are not suitable or when simple
* conversion is sufficient.
*
* @param {string} content - The input content that may contain reStructuredText
* @returns {string} Legal Markdown formatted content
* @example
* ```typescript
* const rstContent = `
* Section Title
* =============
*
* Some **bold** and *italic* text.
* `;
*
* const legalMarkdown = convertRstToLegalMarkdownSync(rstContent);
* console.log(legalMarkdown);
* // Output:
* // l. Section Title
* //
* // Some **bold** and *italic* text.
* ```
*/
export declare function convertRstToLegalMarkdownSync(content: string): string;
//# sourceMappingURL=rst-parser.d.ts.map