@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
55 lines (54 loc) • 2.35 kB
TypeScript
/**
* Converts LaTeX bracket delimiters to dollar sign delimiters.
* Converts \[...\] to $$...$$ and \(...\) to $...$
* Preserves code blocks during the conversion.
*
* @param text The input string containing LaTeX expressions
* @returns The string with LaTeX bracket delimiters converted to dollar sign delimiters
*/
export declare function convertLatexDelimiters(text: string): string;
/**
* Escapes mhchem commands in LaTeX expressions to ensure proper rendering.
*
* @param text The input string containing LaTeX expressions with mhchem commands
* @returns The string with escaped mhchem commands
*/
export declare function escapeMhchemCommands(text: string): string;
/**
* Escapes pipe characters within LaTeX expressions to prevent them from being interpreted
* as table column separators in markdown tables.
*
* @param text The input string containing LaTeX expressions
* @returns The string with pipe characters escaped in LaTeX expressions
*/
export declare function escapeLatexPipes(text: string): string;
/**
* Escapes underscores within \text{...} commands in LaTeX expressions
* that are not already escaped.
* For example, \text{node_domain} becomes \text{node\_domain},
* but \text{node\_domain} remains \text{node\_domain}.
*
* @param text The input string potentially containing LaTeX expressions
* @returns The string with unescaped underscores escaped within \text{...} commands
*/
export declare function escapeTextUnderscores(text: string): string;
/**
* Preprocesses LaTeX content by performing multiple operations:
* 1. Protects code blocks from processing
* 2. Protects existing LaTeX expressions
* 3. Escapes dollar signs that likely represent currency
* 4. Converts LaTeX delimiters
* 5. Escapes mhchem commands and pipes
*
* @param content The input string containing LaTeX expressions
* @returns The processed string with proper LaTeX formatting
*/
export declare function preprocessLaTeX(str: string): string;
/**
* Checks if the last LaTeX formula in the text is renderable.
* Only validates the formula after the last $$ if there's an odd number of $$.
*
* @param text The input string containing LaTeX formulas
* @returns True if the last formula is renderable or if there's no incomplete formula
*/
export declare const isLastFormulaRenderable: (text: string) => boolean;