import { editor, languages } from 'monaco-editor-core'; /** * !Important: The exported `formatter` function in this file should remain unbound to monarch as it * can be used standalone to format MDC content strings. The function is also utilized in * the `@nuxtlabs/vscode-mdc` VSCode extension https://github.com/nuxtlabs/vscode-mdc. * * Any changes to the function signature or behavior should be tested and verified in the extension. */ /** * Formatter Options */ interface FormatterOptions { /** The number of spaces to use for indentation. Defaults to `2`. */ tabSize?: number; /** Whether the formatter is being used for on-type formatting. Defaults to `false`. */ isFormatOnType?: boolean; } /** * MDC Formatter: Handles formatting and indentation of MDC files which contain: * - MDC block components * - MDC block component YAML frontmatter, including multiline strings * - Nested MDC block components * * @param {string} content - The raw MDC content to format * @param {FormatterOptions} options - The formatter options * @param {number} options.tabSize - The number of spaces to use for indentation. Defaults to `2`. * @param {boolean} options.isFormatOnType - Whether the formatter is being used for on-type formatting. Defaults to `false`. */ declare const formatter: (content: string, { tabSize, isFormatOnType }: FormatterOptions) => string; /** * Provides folding ranges for the MDC language in the Monaco editor. * * @param {editor.ITextModel} model - The text model for which folding ranges are to be provided. * @returns A promise that resolves to an array of folding ranges. */ declare const foldingProvider: (model: editor.ITextModel) => languages.ProviderResult; /** * !Important: The exported `getDocumentFoldingRanges` function in this file is also utilized in * the `@nuxtlabs/vscode-mdc` VSCode extension https://github.com/nuxtlabs/vscode-mdc. * * Any changes to the function signature or behavior should be tested and verified in the extension. */ /** Represents a text document, providing methods to access its content. */ interface TextDocument$1 { /** * Retrieves the content of a specific line in the document. * @param lineNumber - The zero-based line number to retrieve. * @returns The content of the specified line. */ getLine: (lineNumber: number) => string; lineCount: number; } /** * A range in a text document that can be folded. * * @interface FoldingRange * @property {number} start - The zero-based line number where the folding starts. * @property {number} end - The zero-based line number where the folding ends. */ interface FoldingRange { start: number; end: number; } /** * Generates the folding ranges for a given text document. This function is designed to be used with * text documents that follow the Monarch or TextMate syntax highlighting conventions. * * @param {TextDocument} document - The text document to compute folding ranges for. * @param {(lineNumber: number) => string} document.getLine - A function that returns the content of a line given its line number. * @param {number} document.lineCount - The total number of lines in the document. * @returns {FoldingRange[]} - An array of FoldingRange objects representing the folding regions in the document. */ declare const getDocumentFoldingRanges: (document: TextDocument$1) => FoldingRange[]; /** * Options for customizing bracket matcher appearance and behavior. */ interface BracketMatcherOptions { /** * CSS class name for matched bracket decorations. * If not provided, default styles will be used. * @default 'mdc-bracket-match' */ className?: string; /** * Inline CSS class name for matched bracket decorations. * @default 'mdc-bracket-match-inline' */ inlineClassName?: string; /** * Whether to automatically inject default styles into the document. * Set to false if you want to provide your own CSS. * @default true */ injectStyles?: boolean; /** * Maximum number of lines to scan for bracket matching. * Bracket matching will be disabled for documents exceeding this limit * to maintain performance. Set to 0 to disable the limit. * @default 5000 */ maxLineCount?: number; } /** * Disposable object for cleaning up bracket matcher resources. */ interface BracketMatcherDisposable { /** * Removes all event listeners and decorations. */ dispose: () => void; } /** * Registers a bracket matcher for MDC block components in Monaco Editor. * * The bracket matcher highlights matching opening and closing `::` markers when the cursor * is adjacent to them. It automatically injects the necessary CSS styles unless disabled. * * @example * ```typescript * import { registerBracketMatcher } from '@nuxtlabs/monarch-mdc' * * const disposable = registerBracketMatcher(editor, { * injectStyles: true, // default * maxLineCount: 5000, // default, disables for large documents * }) * * // Clean up when done * disposable.dispose() * ``` * * @param monacoEditor - The Monaco editor instance to attach the bracket matcher to * @param options - Configuration options for the bracket matcher * @returns A disposable object that can be used to clean up the bracket matcher */ declare function registerBracketMatcher(monacoEditor: editor.ICodeEditor, options?: BracketMatcherOptions): BracketMatcherDisposable; /** * !Important: The exported functions in this file are also utilized in * the `@nuxtlabs/vscode-mdc` VSCode extension https://github.com/nuxtlabs/vscode-mdc. * * Any changes to the function signatures or behavior should be tested and verified in the extension. */ /** Represents a text document, providing methods to access its content. */ interface TextDocument { /** * Retrieves the content of a specific line in the document. * @param lineNumber - The zero-based line number to retrieve. * @returns The content of the specified line. */ getLine: (lineNumber: number) => string; /** The total number of lines in the document. */ lineCount: number; } /** * Represents a position in a text document (line and column). */ interface Position { /** Line number (zero-based). */ line: number; /** Column number (zero-based). */ column: number; } /** * Represents a range in a text document. */ interface Range { /** Starting line number (zero-based). */ startLine: number; /** Starting column number (zero-based). */ startColumn: number; /** Ending line number (zero-based). */ endLine: number; /** Ending column number (zero-based). */ endColumn: number; } /** * Represents a matched bracket pair with their positions. */ interface BracketMatch { /** Range of the opening bracket (e.g., `::component-name`) */ opening: Range; /** Range of the closing bracket (e.g., `::`) */ closing: Range; /** Number of colons in the matched pair */ colonCount: number; } /** * Finds matching MDC block component brackets (:: markers) when cursor is adjacent to one. * * @param document - The text document to search * @param position - The current cursor position * @returns The matched bracket pair if found, otherwise null */ declare function findMatchingBrackets(document: TextDocument, position: Position): BracketMatch | null; /** * MDC language * Based on official markdown language */ declare const conf: languages.LanguageConfiguration; declare const language: languages.IMonarchLanguage; export { conf, findMatchingBrackets, foldingProvider, formatter, getDocumentFoldingRanges, language, registerBracketMatcher };