diff --git a/app.py b/app.py index 4965349..c5770b2 100644 --- a/app.py +++ b/app.py @@ -269,7 +269,7 @@ function _md(s){ s=s.replace(/\*(.+?)\*/g,'$1'); // Lists s=s.replace(/^\s*[-*]\s+(.+)$/gm,'
  • $1
  • '); - s=s.replace(/(
  • .*<\/li>)/s,''); + s=s.replace(/(
  • [^]*?<\/li>)/g,function(m){return '';}); // Line breaks (double newline = paragraph) s=s.replace(/\n\n/g,'

    '); s=s.replace(/\n/g,'
    '); diff --git a/chat.db b/chat.db index 2099960..59f61d4 100644 Binary files a/chat.db and b/chat.db differ diff --git a/fix_chat_js.py b/fix_chat_js.py new file mode 100644 index 0000000..1be8307 --- /dev/null +++ b/fix_chat_js.py @@ -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 '

    '+s+'

    '; +} +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 '

    '+s+'

    '; +}""" + +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") diff --git a/fix_chat_v2.py b/fix_chat_v2.py new file mode 100644 index 0000000..fbd71e7 --- /dev/null +++ b/fix_chat_v2.py @@ -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>)/s,'');""" +new = """s=s.replace(/(
  • [^]*?<\\/li>)/g,function(m){return '';});""" + +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>)/s,'');" + 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}")