@lobehub/ui 2.1.8 → 2.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,16 @@ export declare function escapeMhchemCommands(text: string): string;
22
22
  * @returns The string with pipe characters escaped in LaTeX expressions
23
23
  */
24
24
  export declare function escapeLatexPipes(text: string): string;
25
+ /**
26
+ * Escapes underscores within \text{...} commands in LaTeX expressions
27
+ * that are not already escaped.
28
+ * For example, \text{node_domain} becomes \text{node\_domain},
29
+ * but \text{node\_domain} remains \text{node\_domain}.
30
+ *
31
+ * @param text The input string potentially containing LaTeX expressions
32
+ * @returns The string with unescaped underscores escaped within \text{...} commands
33
+ */
34
+ export declare function escapeTextUnderscores(text: string): string;
25
35
  /**
26
36
  * Preprocesses LaTeX content by performing multiple operations:
27
37
  * 1. Protects code blocks from processing
@@ -45,6 +45,25 @@ export function escapeLatexPipes(text) {
45
45
  return text;
46
46
  }
47
47
 
48
+ /**
49
+ * Escapes underscores within \text{...} commands in LaTeX expressions
50
+ * that are not already escaped.
51
+ * For example, \text{node_domain} becomes \text{node\_domain},
52
+ * but \text{node\_domain} remains \text{node\_domain}.
53
+ *
54
+ * @param text The input string potentially containing LaTeX expressions
55
+ * @returns The string with unescaped underscores escaped within \text{...} commands
56
+ */
57
+ export function escapeTextUnderscores(text) {
58
+ return text.replaceAll(/\\text{([^}]*)}/g, function (match, textContent) {
59
+ // textContent is the content within the braces, e.g., "node_domain" or "already\_escaped"
60
+ // Replace underscores '_' with '\_' only if they are NOT preceded by a backslash '\'.
61
+ // The (?<!\\) is a negative lookbehind assertion that ensures the character before '_' is not a '\'.
62
+ var escapedTextContent = textContent.replaceAll(/(?<!\\)_/g, '\\_');
63
+ return "\\text{".concat(escapedTextContent, "}");
64
+ });
65
+ }
66
+
48
67
  /**
49
68
  * Preprocesses LaTeX content by performing multiple operations:
50
69
  * 1. Protects code blocks from processing
@@ -58,37 +77,41 @@ export function escapeLatexPipes(text) {
58
77
  */
59
78
  export function preprocessLaTeX(str) {
60
79
  // Step 1: Protect code blocks
61
- var codeBlocks = [];
62
- var content = str.replaceAll(/(```[\S\s]*?```|`[^\n`]+`)/g, function (match, code) {
63
- codeBlocks.push(code);
64
- return "<<CODE_BLOCK_".concat(codeBlocks.length - 1, ">>");
65
- });
80
+ // const codeBlocks: string[] = [];
81
+ // let content = str.replaceAll(/(```[\S\s]*?```|`[^\n`]+`)/g, (match, code) => {
82
+ // codeBlocks.push(code);
83
+ // return `<<CODE_BLOCK_${codeBlocks.length - 1}>>`;
84
+ // });
66
85
 
67
- // Step 2: Protect existing LaTeX expressions
68
- var latexExpressions = [];
69
- content = content.replaceAll(/(\$\$[\S\s]*?\$\$|\\\[[\S\s]*?\\]|\\\(.*?\\\))/g, function (match) {
70
- latexExpressions.push(match);
71
- return "<<LATEX_".concat(latexExpressions.length - 1, ">>");
72
- });
86
+ // // Step 2: Protect existing LaTeX expressions
87
+ // const latexExpressions: string[] = [];
88
+ // content = content.replaceAll(/(\$\$[\S\s]*?\$\$|\\\[[\S\s]*?\\]|\\\(.*?\\\))/g, (match) => {
89
+ // latexExpressions.push(match);
90
+ // return `<<LATEX_${latexExpressions.length - 1}>>`;
91
+ // });
73
92
 
74
93
  // Step 3: Escape dollar signs that are likely currency indicators
75
94
  // Deprecated, as it causes parsing errors for formulas starting with a number, such as `$1$`
76
95
  // content = content.replaceAll(/\$(?=\d)/g, '\\$');
77
96
 
78
97
  // Step 4: Restore LaTeX expressions
79
- content = content.replaceAll(/<<LATEX_(\d+)>>/g, function (_, index) {
80
- return latexExpressions[Number.parseInt(index)];
81
- });
98
+ // content = content.replaceAll(
99
+ // /<<LATEX_(\d+)>>/g,
100
+ // (_, index) => latexExpressions[Number.parseInt(index)],
101
+ // );
82
102
 
83
- // Step 5: Restore code blocks
84
- content = content.replaceAll(/<<CODE_BLOCK_(\d+)>>/g, function (_, index) {
85
- return codeBlocks[Number.parseInt(index)];
86
- });
103
+ // // Step 5: Restore code blocks
104
+ // content = content.replaceAll(
105
+ // /<<CODE_BLOCK_(\d+)>>/g,
106
+ // (_, index) => codeBlocks[Number.parseInt(index)],
107
+ // );
108
+ var content = str;
87
109
 
88
110
  // Step 6: Apply additional escaping functions
89
111
  content = convertLatexDelimiters(content);
90
112
  content = escapeMhchemCommands(content);
91
113
  content = escapeLatexPipes(content);
114
+ content = escapeTextUnderscores(content);
92
115
  return content;
93
116
  }
94
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",