danielrosehill Claude commited on
Commit
aa264da
·
1 Parent(s): 9277630

Fix f-string syntax error with backslash escaping

Browse files

- Moved content escaping outside f-string to avoid syntax error
- Properly escape backslashes, backticks, and dollar signs for JavaScript
- Fixes runtime SyntaxError in Hugging Face Space

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -54,6 +54,9 @@ def create_command_card(command):
54
  description = line.strip()
55
  break
56
 
 
 
 
57
  card_html = f"""
58
  <div style="border: 1px solid #ddd; border-radius: 8px; padding: 16px; margin: 10px 0; background: white;">
59
  <div style="display: flex; justify-content: space-between; align-items: start;">
@@ -70,7 +73,7 @@ def create_command_card(command):
70
  <pre style="margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.5;">{content}</pre>
71
  </div>
72
  </details>
73
- <button onclick="navigator.clipboard.writeText(`{content.replace('`', '\\`')}`); this.innerText='Copied!'; setTimeout(() => this.innerText='Copy to Clipboard', 2000)"
74
  style="background: #2563eb; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin-top: 8px;">
75
  Copy to Clipboard
76
  </button>
 
54
  description = line.strip()
55
  break
56
 
57
+ # Escape content for JavaScript - replace backticks and backslashes
58
+ escaped_content = content.replace('\\', '\\\\').replace('`', '\\`').replace('$', '\\$')
59
+
60
  card_html = f"""
61
  <div style="border: 1px solid #ddd; border-radius: 8px; padding: 16px; margin: 10px 0; background: white;">
62
  <div style="display: flex; justify-content: space-between; align-items: start;">
 
73
  <pre style="margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.5;">{content}</pre>
74
  </div>
75
  </details>
76
+ <button onclick="navigator.clipboard.writeText(`{escaped_content}`); this.innerText='Copied!'; setTimeout(() => this.innerText='Copy to Clipboard', 2000)"
77
  style="background: #2563eb; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; margin-top: 8px;">
78
  Copy to Clipboard
79
  </button>