'commit'
This commit is contained in:
13
dsLightRag/static/Formula.json
Normal file
13
dsLightRag/static/Formula.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"Data": {
|
||||||
|
"algo_version": "",
|
||||||
|
"content": "\\left \\{ \\begin{array} { l } x = a \\cos t \\\\ y = b \\sin t \\end{array} \\right . \\left ( 0 \\le t \\le 2 \\pi \\right )",
|
||||||
|
"height": 71,
|
||||||
|
"orgHeight": 71,
|
||||||
|
"orgWidth": 235,
|
||||||
|
"prism_version": "1.0.9",
|
||||||
|
"prism_wnum": 0,
|
||||||
|
"width": 235
|
||||||
|
},
|
||||||
|
"RequestId": "B90B6C5C-517F-5D84-BFD7-9EA7A612E704"
|
||||||
|
}
|
@@ -163,7 +163,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.option-item {
|
.option-item {
|
||||||
display: inline-block; /* 保持行内块级特性 */
|
display: block !important; /* 强制块级显示 */
|
||||||
|
margin: 0.5em 0; /* 上下间距 */
|
||||||
|
padding: 0.3em; /* 内边距 */
|
||||||
|
width: 100%; /* 占满容器宽度 */
|
||||||
|
box-sizing: border-box; /* 确保padding不会溢出 */
|
||||||
padding-right: 15px; /* 序号与内容间距 */
|
padding-right: 15px; /* 序号与内容间距 */
|
||||||
font-weight: bold; /* 突出显示选项序号 */
|
font-weight: bold; /* 突出显示选项序号 */
|
||||||
}
|
}
|
||||||
@@ -196,7 +200,7 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 200px;
|
min-height: 200px;
|
||||||
color: #666;
|
color: #666;
|
||||||
background-color: rgba(249, 249, 249, 0.7); /* 调整透明度为0.7 */
|
background-color: rgba(249, 249, 249, 0.7); /* 将不透明度从0.95调整为0.7 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.spinner {
|
.spinner {
|
||||||
@@ -339,35 +343,40 @@
|
|||||||
function recognizeFormula() {
|
function recognizeFormula() {
|
||||||
const imageUrl = document.getElementById('formulaImageUrl').value.trim();
|
const imageUrl = document.getElementById('formulaImageUrl').value.trim();
|
||||||
const resultArea = document.getElementById('formulaResult');
|
const resultArea = document.getElementById('formulaResult');
|
||||||
|
|
||||||
if (!imageUrl) { alert('请输入图片URL!'); return; }
|
if (!imageUrl) { alert('请输入图片URL!'); return; }
|
||||||
|
|
||||||
resultArea.innerHTML = '<div class="loading-animation"><div class="spinner"></div><div>正在识别公式...</div></div>';
|
resultArea.innerHTML = '<div class="loading-animation"><div class="spinner"></div><div>正在识别公式...</div></div>';
|
||||||
|
|
||||||
fetch('/api/recognize-formula', {
|
// 添加延迟模拟API调用
|
||||||
method: 'POST',
|
setTimeout(() => {
|
||||||
headers: { 'Content-Type': 'application/json' },
|
// 读取本地JSON文件
|
||||||
body: JSON.stringify({ image_url: imageUrl })
|
fetch('Formula.json')
|
||||||
})
|
.then(response => {
|
||||||
.then(response => response.json())
|
console.log('JSON请求响应:', response);
|
||||||
.then(data => {
|
if (!response.ok) throw new Error('无法加载本地JSON文件');
|
||||||
if (data.error) { resultArea.innerHTML = `<div style="color:red">识别失败: ${data.error}</div>`; return; }
|
return response.json();
|
||||||
|
})
|
||||||
const content = data.Data?.content || '';
|
.then(data => {
|
||||||
if (!content) { resultArea.innerHTML = '<div>未识别到公式内容</div>'; return; }
|
if (data.error) { resultArea.innerHTML = `<div style="color:red">识别失败: ${data.error}</div>`; return; }
|
||||||
|
|
||||||
try {
|
const content = data.Data?.content || '';
|
||||||
resultArea.innerHTML = `<div class="tex2jax_process">$$${content}$$</div>`;
|
if (!content) { resultArea.innerHTML = '<div>未识别到公式内容</div>'; return; }
|
||||||
renderWithMathJax(resultArea);
|
|
||||||
} catch (error) {
|
try {
|
||||||
console.error('公式处理错误:', error);
|
resultArea.innerHTML = `<div class="tex2jax_process">$$${content}$$</div>`;
|
||||||
resultArea.innerHTML = `<div style="color:red">公式处理失败: ${error.message}</div>`;
|
renderWithMathJax(resultArea);
|
||||||
}
|
} catch (error) {
|
||||||
})
|
console.error('公式处理错误:', error);
|
||||||
.catch(error => {
|
resultArea.innerHTML = `<div style="color:red">公式处理失败: ${error.message}</div>`;
|
||||||
console.error('请求错误:', error);
|
}
|
||||||
resultArea.innerHTML = `<div style="color:red">请求出错,请重试</div>`;
|
})
|
||||||
});
|
.catch(error => {
|
||||||
|
console.error('请求错误:', error);
|
||||||
|
const errorMsg = '加载本地JSON失败: ' + error.message;
|
||||||
|
resultArea.innerHTML = `<div style="color:red">${errorMsg}</div>`;
|
||||||
|
});
|
||||||
|
}, 1000); // 1秒延迟
|
||||||
}
|
}
|
||||||
|
|
||||||
// 识别试题
|
// 识别试题
|
||||||
@@ -397,10 +406,24 @@
|
|||||||
console.log("处理前:"+content);
|
console.log("处理前:"+content);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 处理选项格式 - 序号与内容同行,选项间换行
|
// 彻底修复选项标签闭合问题 - 采用分而治之策略
|
||||||
content = content.replace(/([A-D])\s*\.\s*/g, '<span class="option-item">$$$1. </span><br>');
|
// 1. 首先拆分所有选项为独立数组
|
||||||
console.log("处理后:"+content);
|
const options = content.split(/(?=[A-D]\s*\.)/);
|
||||||
// 确保不替换已添加的<br>标签
|
// 2. 逐个处理每个选项确保标签完整
|
||||||
|
content = options.map(option => {
|
||||||
|
// 仅处理以选项标签开头的部分
|
||||||
|
if (/^[A-D]\s*\./.test(option)) {
|
||||||
|
return `<span class="option-item">$${option}$</span>`; // 添加$符号
|
||||||
|
}
|
||||||
|
return option;
|
||||||
|
}).join('');
|
||||||
|
// 3. 清理可能的空标签
|
||||||
|
content = content.replace(/<span class="option-item"><\/span>/g, '');
|
||||||
|
if (!content.includes('<span class="option-item">')) {
|
||||||
|
content = content.replace(/((?:[A-D]\s*\.\s*[^.]+)+)/g, '<span class="option-item">$1</span>');
|
||||||
|
}
|
||||||
|
// 添加选项间的分隔处理
|
||||||
|
content = content.replace(/<\/span>\s*<span class="option-item">/g, '</span>\n<span class="option-item">');
|
||||||
const latexContainer = document.createElement('div');
|
const latexContainer = document.createElement('div');
|
||||||
latexContainer.className = 'tex2jax_process';
|
latexContainer.className = 'tex2jax_process';
|
||||||
latexContainer.innerHTML = content;
|
latexContainer.innerHTML = content;
|
||||||
|
Reference in New Issue
Block a user