1/**
 2 * Matches common Markdown code blocks to exclude them from further processing (e.g. LaTeX).
 3 * - Fenced: ```...```
 4 * - Inline: `...` (does NOT support nested backticks or multi-backtick syntax)
 5 *
 6 * Note: This pattern does not handle advanced cases like:
 7 *       `` `code with `backticks` `` or \\``...\\``
 8 */
 9export const CODE_BLOCK_REGEXP = /(```[\s\S]*?```|`[^`\n]+`)/g;
10
11/**
12 * Matches LaTeX math delimiters \(...\) and \[...\] only when not preceded by a backslash (i.e., not escaped),
13 * while also capturing code blocks (```, `...`) so they can be skipped during processing.
14 *
15 * Uses negative lookbehind `(?<!\\)` to avoid matching \\( or \\[.
16 * Using the look‑behind pattern `(?<!\\)` we skip matches
17 * that are preceded by a backslash, e.g.
18 * `Definitions\\(also called macros)` (title of chapter 20 in The TeXbook)
19 * or `\\[4pt]` (LaTeX line-break).
20 *
21 * group 1: code-block
22 * group 2: square-bracket
23 * group 3: round-bracket
24 */
25export const LATEX_MATH_AND_CODE_PATTERN =
26	/(```[\S\s]*?```|`.*?`)|(?<!\\)\\\[([\S\s]*?[^\\])\\]|(?<!\\)\\\((.*?)\\\)/g;
27
28/** Regex to capture the content of a $$...\\\\...$$ block (display-formula with line-break) */
29export const LATEX_LINEBREAK_REGEXP = /\$\$([\s\S]*?\\\\[\s\S]*?)\$\$/;
30
31/** map from mchem-regexp to replacement */
32export const MHCHEM_PATTERN_MAP: readonly [RegExp, string][] = [
33	[/(\s)\$\\ce{/g, '$1$\\\\ce{'],
34	[/(\s)\$\\pu{/g, '$1$\\\\pu{']
35] as const;