prism-react-editor
Version:
Lightweight, extensible code editor component for React apps
39 lines (38 loc) • 1.44 kB
TypeScript
import { Token } from '../../prism';
import { PrismEditor } from '../../types';
export interface BracketMatcher {
/**
* Array of tuples containing in the following order:
* - The bracket's `Token`
* - Its starting position
* - Its ending position
* - Its level of nesting
* - Its text content
* - Whether it's an opening bracket
*/
readonly brackets: Bracket[];
/** Array mapping the index of a bracket to the index of its matching bracket. */
readonly pairs: (number | undefined)[];
}
/**
* Tuple containing in the following order:
* - The bracket's `Token`
* - Its starting position
* - Its ending position
* - Its level of nesting
* - Its text content
* - Whether it's an opening bracket
*/
export type Bracket = [Token, number, number, number, string, boolean];
/**
* Hook that matches punctuation tokens together. Intended for matching brackets.
*
* Note that when adding the extension dynamically with rainbow brackets, they won't be
* added until the next time the editor rerenders.
*
* @param rainbowBrackets Whether to add extra classes to brackets for styling. Defaults
* to `true`.
* @param pairs Which characters to match together. The opening character must be followed
* by the corresponding closing character. Defaults to `"()[]{}"`.
*/
export declare const useBracketMatcher: (editor: PrismEditor, rainbowBrackets?: boolean, pairs?: string) => void;