# Line Breaks Issue — Debug Status (2026-03-03)

## Problem
Replies sent to Addons API have excessive line breaks. On Addons, each `\n` renders as `<br><br>` (double line break), so every newline becomes a visible blank line.

## Root Cause Discovery
**Addons uses `<br>` for line breaks, NOT `\n`.** Inbound messages from Addons have `<br>` for single line breaks and `<br><br>` for blank lines. When we send `\n`, Addons converts each `\n` to `<br><br>` (doubling the spacing).

Evidence from inbound message body_raw:
```
Buenos días,<br>Necesito que aparezca...<br>Necesito que aparezca más grande.<br><br>Gracias
```

## Secondary Issue: Signature HTML
`buildSignatureHtml()` in `app.js:794` was generating `<p></p>` for empty lines (from `sig.split('\n').map(...)`), but Quill expects `<p><br></p>`. This caused Quill to insert literal `\n` inside `<p>` tags: `<p>Best regards,\n</p><p>\n</p>`.

**Fix applied (app.js:794):** Empty lines now produce `<p><br></p>`:
```javascript
sig.split('\n').map(line => line.trim() ? '<p>' + escHtml(line) + '</p>' : '<p><br></p>').join('')
```
**User MUST Ctrl+Shift+R to get this fix** — Flask doesn't watch static JS files.

## Current State of Conversion Code (main.py ~line 950)
The conversion has normalization to handle the bad signature HTML:
```python
addons_text = re.sub(r'\s+</p>', '</p>', addons_text)  # strip trailing \n before </p>
addons_text = re.sub(r'<p>\s*(?:<br\s*/?>)?\s*</p>', '{{BLANK}}', addons_text)  # blank lines
addons_text = re.sub(r'</p>', '\n', addons_text)  # paragraph end = newline
addons_text = re.sub(r'<p>', '', addons_text)
addons_text = re.sub(r'<br\s*/?>', '\n', addons_text)
addons_text = re.sub(r'{{BLANK}}', '\n', addons_text)  # blank marker = extra newline
addons_text = bleach.clean(addons_text, tags=[], strip=True)
addons_text = re.sub(r'\n{4,}', '\n\n\n', addons_text)  # cap excessive
addons_text = addons_text.strip()
```

This produces CORRECT plain text locally. But **Addons doubles every `\n`** so the output still looks bad on the marketplace.

## Unsolved: How to send line breaks to Addons API
- Sending `\n` → Addons converts to `<br><br>` (double spacing) :(
- Sending `<br>` → User says HTML gets escaped. **NOT YET TESTED** — worth testing once to confirm.
- The Addons API `message` field: unclear if it accepts HTML or only plain text.
- Inbound messages have `<br>` in `body_raw`, but that might be Addons' internal format, not what the API accepts.

## What to Try Next
1. **Test sending `<br>` tags** in a single test message to confirm if Addons escapes them or renders them. If it works → problem solved. If escaped → need different approach.
2. If HTML is escaped: the only option may be accepting that `\n` = paragraph break on Addons, and adjusting the signature format (fewer blank lines).
3. Check Addons API docs for a `format=html` parameter or similar.

## Other Completed Work This Session
- **Review Request feature** — fully implemented (sync_service, main.py, base.html, _inbox_rows.html, ticket.html)
- **Sync growl notification** — slide-in card from top-right after sync
- **Paste image detection** — Quill clipboard IMG matcher + document capture listener + confirmation dialog
- **API error handling** — `send_reply()` return value now checked, user sees error toast on rejection
- **Settings textarea** — `rows="4"` → `rows="14"` so full signature is visible

## Debug Logging Still Active (REMOVE WHEN DONE)
- `main.py`: `logger.info("DEBUG_REPLY addons_text: %r", addons_text)`
- `addons.py`: `logger.info("DEBUG send_reply payload message: %r", message)` and response logging

## Flask Reloader Issue
The auto-reloader was NOT picking up main.py changes during this session. Multiple Flask instances accumulated (up to 6!). The `--debug` stat reloader seems unreliable on Windows with Dropbox sync. **Always verify code is running** by checking for debug log output or testing behavior. May need manual restart: kill all python.exe Flask processes, then start fresh.
