@lobehub/ui 2.13.4 → 2.13.5
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.
|
@@ -32,6 +32,19 @@ export declare function escapeLatexPipes(text: string): string;
|
|
|
32
32
|
* @returns The string with unescaped underscores escaped within \text{...} commands
|
|
33
33
|
*/
|
|
34
34
|
export declare function escapeTextUnderscores(text: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Escapes dollar signs that appear to be currency symbols to prevent them from being
|
|
37
|
+
* interpreted as LaTeX math delimiters.
|
|
38
|
+
*
|
|
39
|
+
* This function identifies currency patterns such as:
|
|
40
|
+
* - $20, $100, $1,000
|
|
41
|
+
* - $20-50, $100+
|
|
42
|
+
* - Patterns within markdown tables
|
|
43
|
+
*
|
|
44
|
+
* @param text The input string containing potential currency symbols
|
|
45
|
+
* @returns The string with currency dollar signs escaped
|
|
46
|
+
*/
|
|
47
|
+
export declare function escapeCurrencyDollars(text: string): string;
|
|
35
48
|
/**
|
|
36
49
|
* Preprocesses LaTeX content by performing multiple operations:
|
|
37
50
|
* 1. Protects code blocks from processing
|
|
@@ -51,7 +51,8 @@ export function escapeLatexPipes(text) {
|
|
|
51
51
|
// Replace unescaped '|' inside LaTeX math spans with '\vert' so that
|
|
52
52
|
// remark-gfm table parsing won't treat them as column separators.
|
|
53
53
|
// Leave code blocks/inline code untouched.
|
|
54
|
-
|
|
54
|
+
// Also ignore escaped dollars (\$) which are currency symbols
|
|
55
|
+
var pattern = /(```[\S\s]*?```|`[^\n`]*`)|\$\$([\S\s]*?)\$\$|(?<!\\)(?<!\$)\$(?!\$)([\S\s]*?)(?<!\\)(?<!\$)\$(?!\$)/g;
|
|
55
56
|
return text.replaceAll(pattern, function (match, code, display, inline) {
|
|
56
57
|
if (code !== undefined) return code; // preserve code fences/inline code
|
|
57
58
|
if (display !== undefined) return "$$".concat(replaceUnescapedPipes(display), "$$");
|
|
@@ -79,6 +80,41 @@ export function escapeTextUnderscores(text) {
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Escapes dollar signs that appear to be currency symbols to prevent them from being
|
|
85
|
+
* interpreted as LaTeX math delimiters.
|
|
86
|
+
*
|
|
87
|
+
* This function identifies currency patterns such as:
|
|
88
|
+
* - $20, $100, $1,000
|
|
89
|
+
* - $20-50, $100+
|
|
90
|
+
* - Patterns within markdown tables
|
|
91
|
+
*
|
|
92
|
+
* @param text The input string containing potential currency symbols
|
|
93
|
+
* @returns The string with currency dollar signs escaped
|
|
94
|
+
*/
|
|
95
|
+
export function escapeCurrencyDollars(text) {
|
|
96
|
+
// Protect code blocks and existing LaTeX expressions from processing
|
|
97
|
+
var protectedStrings = [];
|
|
98
|
+
var content = text.replaceAll(/(```[\S\s]*?```|`[^\n`]*`|\$\$[\S\s]*?\$\$|\\\[[\S\s]*?\\]|\\\(.*?\\\))/g, function (match) {
|
|
99
|
+
protectedStrings.push(match);
|
|
100
|
+
return "<<PROTECTED_".concat(protectedStrings.length - 1, ">>");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Escape dollar signs that are clearly currency:
|
|
104
|
+
// - $ followed by a digit
|
|
105
|
+
// - Not preceded by another $ (to avoid breaking $$)
|
|
106
|
+
// - Followed by number patterns with optional commas, decimals, ranges, or plus signs
|
|
107
|
+
// Match patterns like: $20, $1,000, $19.99, $20-50, $300+, $1,000-2,000+
|
|
108
|
+
// In the replacement: \\ = backslash, $$ = literal $, $1 = capture group 1
|
|
109
|
+
content = content.replaceAll(/(?<!\$)\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?(?:-\d{1,3}(?:,\d{3})*(?:\.\d+)?)?\+?)/g, '\\$$$1');
|
|
110
|
+
|
|
111
|
+
// Restore protected content
|
|
112
|
+
content = content.replaceAll(/<<PROTECTED_(\d+)>>/g, function (_, index) {
|
|
113
|
+
return protectedStrings[Number.parseInt(index)];
|
|
114
|
+
});
|
|
115
|
+
return content;
|
|
116
|
+
}
|
|
117
|
+
|
|
82
118
|
/**
|
|
83
119
|
* Preprocesses LaTeX content by performing multiple operations:
|
|
84
120
|
* 1. Protects code blocks from processing
|
|
@@ -123,6 +159,8 @@ export function preprocessLaTeX(str) {
|
|
|
123
159
|
var content = str;
|
|
124
160
|
|
|
125
161
|
// Step 6: Apply additional escaping functions
|
|
162
|
+
// Escape currency dollar signs FIRST before other LaTeX processing
|
|
163
|
+
content = escapeCurrencyDollars(content);
|
|
126
164
|
content = convertLatexDelimiters(content);
|
|
127
165
|
content = escapeMhchemCommands(content);
|
|
128
166
|
content = escapeLatexPipes(content);
|