Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -342,35 +342,45 @@ def index():
|
|
| 342 |
<script>
|
| 343 |
async function analyze() {
|
| 344 |
const btn = document.getElementById('load-btn');
|
| 345 |
-
const
|
| 346 |
-
if(!
|
| 347 |
|
| 348 |
btn.innerText = "Analyzing...";
|
| 349 |
const fd = new FormData();
|
| 350 |
-
fd.append('markdown_text',
|
| 351 |
|
| 352 |
try {
|
| 353 |
const res = await fetch('/parse', {method:'POST', body:fd});
|
|
|
|
| 354 |
const data = await res.json();
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
document.getElementById('detected-format').innerText = "Detected: " + data.format;
|
| 358 |
const list = document.getElementById('comp-list');
|
|
|
|
|
|
|
| 359 |
list.innerHTML = '';
|
|
|
|
| 360 |
data.components.forEach(c => {
|
| 361 |
-
|
|
|
|
| 362 |
list.innerHTML += `
|
| 363 |
<div class="comp-card">
|
| 364 |
<label style="cursor:pointer; display:block;">
|
| 365 |
-
<input type="checkbox" checked class="c-check"
|
|
|
|
|
|
|
| 366 |
<b>${c.filename}</b>
|
| 367 |
</label>
|
| 368 |
<textarea readonly>${c.content.substring(0,80)}...</textarea>
|
| 369 |
</div>`;
|
| 370 |
});
|
| 371 |
document.getElementById('comp-section').style.display = 'block';
|
| 372 |
-
} catch(e) {
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
|
| 376 |
async function process(action, type = null) {
|
|
|
|
| 342 |
<script>
|
| 343 |
async function analyze() {
|
| 344 |
const btn = document.getElementById('load-btn');
|
| 345 |
+
const input = document.getElementById('md-input');
|
| 346 |
+
if(!input.value.trim()) return alert("Please enter markdown text first.");
|
| 347 |
|
| 348 |
btn.innerText = "Analyzing...";
|
| 349 |
const fd = new FormData();
|
| 350 |
+
fd.append('markdown_text', input.value);
|
| 351 |
|
| 352 |
try {
|
| 353 |
const res = await fetch('/parse', {method:'POST', body:fd});
|
| 354 |
+
if (!res.ok) throw new Error("Server error during analysis");
|
| 355 |
const data = await res.json();
|
| 356 |
+
|
| 357 |
+
const banner = document.getElementById('detected-format');
|
|
|
|
| 358 |
const list = document.getElementById('comp-list');
|
| 359 |
+
|
| 360 |
+
banner.innerText = "Detected: " + (data.format || "Unknown");
|
| 361 |
list.innerHTML = '';
|
| 362 |
+
|
| 363 |
data.components.forEach(c => {
|
| 364 |
+
// Use encodeURIComponent to handle special characters safely
|
| 365 |
+
const safeContent = btoa(encodeURIComponent(c.content));
|
| 366 |
list.innerHTML += `
|
| 367 |
<div class="comp-card">
|
| 368 |
<label style="cursor:pointer; display:block;">
|
| 369 |
+
<input type="checkbox" checked class="c-check"
|
| 370 |
+
data-name="${c.filename}"
|
| 371 |
+
data-content="${safeContent}">
|
| 372 |
<b>${c.filename}</b>
|
| 373 |
</label>
|
| 374 |
<textarea readonly>${c.content.substring(0,80)}...</textarea>
|
| 375 |
</div>`;
|
| 376 |
});
|
| 377 |
document.getElementById('comp-section').style.display = 'block';
|
| 378 |
+
} catch(e) {
|
| 379 |
+
console.error(e);
|
| 380 |
+
alert("Analysis failed: " + e.message);
|
| 381 |
+
} finally {
|
| 382 |
+
btn.innerText = "Analyze Content";
|
| 383 |
+
}
|
| 384 |
}
|
| 385 |
|
| 386 |
async function process(action, type = null) {
|