/** * MarkdownPatternDetector - Utility for detecting and validating markdown syntax patterns * in contenteditable elements for automatic conversion to rich text formatting. */ /** * Represents a markdown pattern definition */ export interface MarkdownPattern { type: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'codeInline' | 'codeBlock' | 'link'; openDelimiter: string; closeDelimiter: string; priority: number; /** If true, use custom detection logic instead of standard delimiter matching */ customDetection?: boolean; } /** * Represents a detected markdown pattern match */ export interface PatternMatch { pattern: MarkdownPattern; startOffset: number; endOffset: number; contentStart: number; contentEnd: number; content: string; linkUrl?: string; } /** * Context information for pattern detection */ export interface DetectionContext { text: string; cursorOffset: number; triggerChar: string; scopeStart: number; scopeEnd: number; } /** * Supported markdown patterns ordered by priority (highest first) */ export declare const MARKDOWN_PATTERNS: MarkdownPattern[]; /** * Map of trigger characters to their associated patterns for efficient lookup */ export declare const TRIGGER_CHARS: Record; /** * Detects markdown patterns in text at cursor position * * @param context - Detection context with text, cursor position, and scope boundaries * @returns PatternMatch if valid pattern found, null otherwise */ export declare function detectMarkdownPattern(context: DetectionContext): PatternMatch | null; /** * Validates that a pattern match is properly formed * * @param match - Pattern match to validate * @param context - Detection context * @returns true if pattern is valid, false otherwise */ export declare function validatePattern(match: PatternMatch, context: DetectionContext): boolean; /** * Checks if a position in text is within an escape sequence * * @param text - Full text content * @param position - Position to check * @returns true if position is escaped, false otherwise */ export declare function isEscaped(text: string, position: number): boolean; /** * Finds scope boundaries (paragraph/block element) for pattern matching * * @param element - Container element * @param cursorNode - Current cursor node * @param cursorOffset - Current cursor offset * @returns Object with start and end offsets of the scope */ export declare function findScopeBoundaries(element: HTMLElement, cursorNode: Node, cursorOffset: number): { start: number; end: number; }; /** * Checks if the cursor is currently inside a mention element. * Mention elements use ``. * * @param cursorNode - The DOM node where the cursor is positioned * @param containerElement - The contenteditable container element * @returns true if cursor is inside a mention span, false otherwise */ export declare function isCursorInsideMention(cursorNode: Node, containerElement: HTMLElement): boolean; /** * Checks if the cursor is currently inside a link (anchor) element. * * @param cursorNode - The DOM node where the cursor is positioned * @param containerElement - The contenteditable container element * @returns true if cursor is inside an element, false otherwise */ export declare function isCursorInsideLink(cursorNode: Node, containerElement: HTMLElement): boolean; /** * Checks if a pattern match spans across a mention or link element boundary. * This prevents markdown patterns from being matched when the opening delimiter * is outside a mention/link and the closing delimiter is inside (or vice versa). * * @param containerElement - The contenteditable container element * @param startOffset - Text offset of the pattern start (opening delimiter) * @param endOffset - Text offset of the pattern end (closing delimiter) * @returns true if the pattern crosses a mention or link boundary, false otherwise */ export declare function patternCrossesMentionOrLink(containerElement: HTMLElement, startOffset: number, endOffset: number): boolean;