Skip to content

Fix web chat streaming markdown gibberish#505

Merged
bokelley merged 1 commit into
mainfrom
bokelley/fix-web-chat-gibberish
Jan 3, 2026
Merged

Fix web chat streaming markdown gibberish#505
bokelley merged 1 commit into
mainfrom
bokelley/fix-web-chat-gibberish

Conversation

@bokelley

@bokelley bokelley commented Jan 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixed web chat producing gibberish text when streaming markdown responses
  • Added hasBalancedMarkdown() function to validate markdown markers are balanced before rendering
  • Falls back to plain text rendering when markers are unbalanced (e.g., incomplete ** for bold)
  • Uses arithmetic instead of lookbehind regex for Safari < 16.4 compatibility

Root Cause

The marked.js parser was receiving incomplete markdown during streaming (e.g., 1. **Access the admin) and producing garbled output. The fix validates that markdown markers (**, *, `, ```) are balanced before rendering.

Test plan

  • Open chat.html and send a message that triggers a formatted response
  • Verify streaming shows text without gibberish
  • Verify final message is properly formatted with markdown
  • Test in Safari to confirm no regex errors

🤖 Generated with Claude Code

The marked.js parser was producing garbled output when receiving incomplete
markdown during streaming (e.g., unbalanced ** for bold text). Added a
hasBalancedMarkdown() check that validates markdown markers are balanced
before rendering, falling back to plain text if not.

- Uses arithmetic instead of lookbehind regex for Safari < 16.4 compatibility
- Checks for balanced **, *, `, and ``` markers
- Falls back to plain text rendering when markers are unbalanced
- Final message is always rendered with full markdown after streaming completes

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit 6c4dfd3 into main Jan 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant