UNPKG

legal-markdown-js

Version:

Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version

74 lines 2.56 kB
/** * Remark plugin to parse legal header syntax (l., ll., lll., etc.) * * This plugin converts paragraphs that start with legal header patterns * into proper heading nodes in the AST, which can then be processed * by the headers plugin for numbering. * * @example * Input: * ``` * l. First Level Header * ll. Second Level Header * lll. Third Level Header * ``` * * Converts to: * ``` * # First Level Header * ## Second Level Header * ### Third Level Header * ``` * * @module */ import { Plugin } from 'unified'; import { Root, Paragraph, Heading } from 'mdast'; interface LegalHeadersParserOptions { debug?: boolean; } /** * Check if a paragraph node contains legal header syntax */ declare function isLegalHeader(node: Paragraph): { level: number; text: string; } | null; /** * Convert a paragraph node to a heading node */ declare function convertToHeading(node: Paragraph, level: number, text: string): Heading; /** * Remark plugin to parse legal header syntax */ declare const remarkLegalHeadersParser: Plugin<[LegalHeadersParserOptions?], Root>; /** * Parse inline markdown formatting (bold, italic) within text * * Converts markdown syntax to AST nodes: * - `_text_` → emphasis * - `__text__` → strong * - `*text*` → emphasis * - `**text**` → strong * * **Issue #139 Fix**: Excludes template fields `{{...}}` from formatting. * * **Problem**: When legal headers contain template fields with underscores * (e.g., `ll. Party {{counterparty.legal_name}}`), the underscore would be * interpreted as an emphasis delimiter, resulting in incorrect AST nodes. * * **Solution**: Detect all `{{...}}` regions and skip emphasis/strong parsing * within those regions. Template fields are expanded later by remarkTemplateFields. * * @see https://github.com/petalo/legal-markdown-js/issues/139 * @see src/plugins/remark/template-fields.ts - Handles template field expansion * @see src/extensions/remark/legal-markdown-processor.ts - escapeTemplateUnderscores() * * @param text - Header text that may contain markdown formatting and template fields * @returns Array of AST nodes (text, emphasis, strong, inlineCode) */ declare function parseMarkdownInlineFormatting(text: string): import('mdast').PhrasingContent[]; export default remarkLegalHeadersParser; export { remarkLegalHeadersParser }; export { isLegalHeader as _isLegalHeader, convertToHeading as _convertToHeading, parseMarkdownInlineFormatting as _parseMarkdownInlineFormatting, }; //# sourceMappingURL=legal-headers-parser.d.ts.map