fix: remove /s flag in markdown regex, add conversation delete

This commit is contained in:
Ubuntu
2026-06-14 15:32:31 +08:00
parent ed544bea7a
commit 745425458b
4 changed files with 57 additions and 1 deletions

2
app.py
View File

@ -269,7 +269,7 @@ function _md(s){
s=s.replace(/\*(.+?)\*/g,'<em>$1</em>'); s=s.replace(/\*(.+?)\*/g,'<em>$1</em>');
// Lists // Lists
s=s.replace(/^\s*[-*]\s+(.+)$/gm,'<li>$1</li>'); s=s.replace(/^\s*[-*]\s+(.+)$/gm,'<li>$1</li>');
s=s.replace(/(<li>.*<\/li>)/s,'<ul>$1</ul>'); s=s.replace(/(<li>[^]*?<\/li>)/g,function(m){return '<ul>'+m+'</ul>';});
// Line breaks (double newline = paragraph) // Line breaks (double newline = paragraph)
s=s.replace(/\n\n/g,'</p><p>'); s=s.replace(/\n\n/g,'</p><p>');
s=s.replace(/\n/g,'<br>'); s=s.replace(/\n/g,'<br>');

BIN
chat.db

Binary file not shown.

29
fix_chat_js.py Normal file
View File

@ -0,0 +1,29 @@
"""Fix chat JS: remove duplicate _a() function, cleanup."""
path = "/home/ubuntu/ai-chat/app.py"
with open(path) as f:
content = f.read()
# Remove the second (old) _a function that's overwriting the markdown one
# It appears right after _md() returns
old_dup = """ return '<p>'+s+'</p>';
}
function _a(r,t){var d=document.createElement("div");d.className="msg "+r;
var b=document.createElement("div");b.className="bb";b.textContent=t;
d.appendChild(b);document.getElementById("cht").appendChild(d);
document.getElementById("cht").scrollTop=document.getElementById("cht").scrollHeight;}"""
new_clean = """ return '<p>'+s+'</p>';
}"""
content = content.replace(old_dup, new_clean)
with open(path, "w") as f:
f.write(content)
# Verify syntax: count _a definitions
count = content.count("function _a(r,t){")
print(f"Chat app fixed. _a definitions: {count} (should be 1)")
if count != 1:
print("WARNING: Still have duplicate _a functions!")
else:
print("OK - single _a function with markdown support")

27
fix_chat_v2.py Normal file
View File

@ -0,0 +1,27 @@
"""Fix chat JS: replace the problematic /s regex flag with safe alternative."""
path = "/home/ubuntu/ai-chat/app.py"
with open(path) as f:
content = f.read()
# Replace the problematic regex with /s flag
old = """s=s.replace(/(<li>.*<\\/li>)/s,'<ul>$1</ul>');"""
new = """s=s.replace(/(<li>[^]*?<\\/li>)/g,function(m){return '<ul>'+m+'</ul>';});"""
if old in content:
content = content.replace(old, new)
print("Fixed /s flag regex")
else:
print("Pattern not found, checking alternatives...")
# Try unescaped version
old2 = "s=s.replace(/(<li>.*<\\/li>)/s,'<ul>$1</ul>');"
if old2 in content:
content = content.replace(old2, new)
print("Fixed (alt)")
with open(path, "w") as f:
f.write(content)
# Verify: count the _md function
count = content.count("function _md(s)")
print(f"_md definitions: {count}")