|
@@ -114,17 +114,17 @@ function processDelimiter(html, left, right, displayMode) {
|
|
|
const rightEscaped = escapeRegex(right);
|
|
const rightEscaped = escapeRegex(right);
|
|
|
|
|
|
|
|
// 构建正则表达式
|
|
// 构建正则表达式
|
|
|
- // 【关键修复】排除包含 HTML 标签的内容(不匹配 < 或 >)
|
|
|
|
|
|
|
+ // 【修复】允许数学符号 < 和 >,只排除明确的 HTML 标签(如 <span>, </div>)
|
|
|
let pattern;
|
|
let pattern;
|
|
|
if (left === '$' && right === '$') {
|
|
if (left === '$' && right === '$') {
|
|
|
- // 单个 $...$:不匹配 $$,不匹配包含 < > 的内容
|
|
|
|
|
- pattern = new RegExp(`(?<!\\$)\\$(?!\\$)([^$<>]+?)(?<!\\$)\\$(?!\\$)`, 'g');
|
|
|
|
|
|
|
+ // 单个 $...$:不匹配 $$,允许 < > 但不匹配换行
|
|
|
|
|
+ pattern = new RegExp(`(?<!\\$)\\$(?!\\$)([^$\\n]+?)(?<!\\$)\\$(?!\\$)`, 'g');
|
|
|
} else if (left === '$$' && right === '$$') {
|
|
} else if (left === '$$' && right === '$$') {
|
|
|
- // $$...$$:不匹配包含 < > 的内容
|
|
|
|
|
- pattern = new RegExp(`\\$\\$([^<>]*?)\\$\\$`, 'g');
|
|
|
|
|
|
|
+ // $$...$$:允许多行和 < >
|
|
|
|
|
+ pattern = new RegExp(`\\$\\$([\\s\\S]*?)\\$\\$`, 'g');
|
|
|
} else {
|
|
} else {
|
|
|
- // \(...\) 和 \[...\]:不匹配包含 < > 的内容
|
|
|
|
|
- pattern = new RegExp(`${leftEscaped}([^<>]*?)${rightEscaped}`, 'g');
|
|
|
|
|
|
|
+ // \(...\) 和 \[...\]:允许 < >
|
|
|
|
|
+ pattern = new RegExp(`${leftEscaped}([\\s\\S]*?)${rightEscaped}`, 'g');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return html.replace(pattern, (match, latex) => {
|
|
return html.replace(pattern, (match, latex) => {
|
|
@@ -137,6 +137,12 @@ function processDelimiter(html, left, right, displayMode) {
|
|
|
return match;
|
|
return match;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 【新增】跳过包含 HTML 标签的内容(如 <span>, </div>, <br>)
|
|
|
|
|
+ // 但允许数学符号 < 和 >(如 a > 0, x < y)
|
|
|
|
|
+ if (/<\/?[a-zA-Z][^>]*>/.test(cleanLatex)) {
|
|
|
|
|
+ return match;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 【修复】处理公式内的换行符:将 \n 替换成空格,避免破坏公式
|
|
// 【修复】处理公式内的换行符:将 \n 替换成空格,避免破坏公式
|
|
|
// 使用负向前瞻 (?![a-zA-Z]) 避免误伤 LaTeX 命令如 \neq, \ne, \newline, \nu 等
|
|
// 使用负向前瞻 (?![a-zA-Z]) 避免误伤 LaTeX 命令如 \neq, \ne, \newline, \nu 等
|
|
|
cleanLatex = cleanLatex.replace(/\\n(?![a-zA-Z])/g, ' ').replace(/\n/g, ' ');
|
|
cleanLatex = cleanLatex.replace(/\\n(?![a-zA-Z])/g, ' ').replace(/\n/g, ' ');
|