Skip to content

render the generated reply as html instead of showing raw markdown - #446

Merged
abhinavxd merged 1 commit into
mainfrom
fix-ai-reply-markdown
Jul 30, 2026
Merged

render the generated reply as html instead of showing raw markdown#446
abhinavxd merged 1 commit into
mainfrom
fix-ai-reply-markdown

Conversation

@abhinavxd

@abhinavxd abhinavxd commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • AI-generated replies now support formatted HTML when displayed in conversations.
    • Reply drafts follow clearer formatting guidelines, including simpler Markdown and safer link usage.
  • Bug Fixes
    • Prevented generated reply content from being incorrectly converted or displayed with unintended formatting.

@abhinavxd
abhinavxd marked this pull request as ready for review July 30, 2026 11:23
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

AI-generated reply formatting is constrained by the copilot prompt, converted from Markdown to HTML by the backend, and preserved as HTML by the reply box for AI-generated replies.

Changes

AI reply formatting

Layer / File(s) Summary
Reply formatting constraints
internal/ai/copilot.go
The reply-drafting prompt permits limited Markdown, disallows headings, tables, code blocks, and images, and restricts links to approved URLs with matching text.
Reply HTML conversion
cmd/ai.go, frontend/apps/main/src/features/conversation/ReplyBox.vue
The backend converts generated Markdown to HTML, while the frontend stores that response directly as HTML for the AI reply path and retains conditional text conversion elsewhere.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: generated replies are rendered as HTML instead of raw markdown.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ai-reply-markdown

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/ai.go`:
- Line 298: Update the response handling around Markdown2HTML so SendEnvelope
never receives unescaped markdown as HTML when conversion fails. Propagate the
conversion error from Markdown2HTML, or escape its fallback before passing the
result to SendEnvelope while preserving the endpoint’s guaranteed-HTML contract.
- Line 298: Update the response handling around Markdown2HTML and SendEnvelope
so fallback AI output is sanitized before persistence or editor loading.
Sanitize raw HTML and reject dangerous URL schemes for both rendered Markdown
and error-fallback content, preserving the existing SendEnvelope flow while
ensuring no unsanitized model response reaches TextEditor.vue.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fb313da2-c4d5-4b0d-83e9-a37fb12ee45e

📥 Commits

Reviewing files that changed from the base of the PR and between fb4d665 and 16b9906.

📒 Files selected for processing (3)
  • cmd/ai.go
  • frontend/apps/main/src/features/conversation/ReplyBox.vue
  • internal/ai/copilot.go

Comment thread cmd/ai.go
return sendErrorEnvelope(r, envelope.NewError(envelope.GeneralError, app.i18n.T("ai.emptyResponse"), nil))
}
return r.SendEnvelope(resp)
return r.SendEnvelope(stringutil.Markdown2HTML(resp))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve a guaranteed-HTML response contract.

Markdown2HTML returns the original markdown when conversion fails, but this endpoint now sends that fallback to the frontend as HTML. Return/propagate the conversion error or escape the fallback before sending it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/ai.go` at line 298, Update the response handling around Markdown2HTML so
SendEnvelope never receives unescaped markdown as HTML when conversion fails.
Propagate the conversion error from Markdown2HTML, or escape its fallback before
passing the result to SendEnvelope while preserving the endpoint’s
guaranteed-HTML contract.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -C3 'markdownRenderer|Markdown2HTML|goldmark|blackfriday|html/template' internal/stringutil/stringutil.go
rg -n -C3 'v-html|innerHTML|setContent|htmlContent' frontend/apps/main/src/features/conversation

Repository: abhinavxd/libredesk

Length of output: 11078


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Go files mentioning Markdown2HTML:"
rg -n -C3 'Markdown2HTML' --glob '*.go' .

echo
echo "Relevant editor files:"
fd -i 'Editor' frontend/apps/main/src | sed -n '1,80p'

echo
echo "Search frontend for html/v-html/innerHTML assignments using model values or envelope data:"
rg -n -C3 'htmlContent|innerHTML|v-html|setContent|contenteditable|dangerouslySetInnerHTML|envelope|data\.data|Markdown|HTML' frontend/apps/main/src --glob '*.vue' --glob '*.ts' --glob '*.js' | sed -n '1,240p'

Repository: abhinavxd/libredesk

Length of output: 22175


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Editor component files:"
fd -e vue . frontend/apps/main/src/components/editor | sort

echo
for f in frontend/apps/main/src/components/editor/*.vue; do
  echo "===== $f ====="
  wc -l "$f"
  if [ "$f" = "frontend/apps/main/src/components/editor/TextEditor.vue" ] || [ "$f" = "frontend/apps/main/src/components/editor/CodeEditor.vue" ]; then
    cat -n "$f"
  fi
done

echo
echo "TextEditor references:"
rg -n -C4 'htmlContent|textContent|innerHTML|v-html|sanitize|DOMPurify|marked|showdown|highlight|prism|Quill|TipTap|TinyMCE|contenteditable' frontend/apps/main/src/components/editor frontend/apps/main/src/features/conversation frontend/apps/main/src --glob '*.vue' --glob '*.ts' --glob '*.js' | sed -n '1,260p'

echo
echo "Check local goldmark version/module references:"
grep -n 'github.com/yuin/goldmark' go.mod go.sum -A2 -B2 || true

Repository: abhinavxd/libredesk

Length of output: 49352


Sanitize AI HTML before loading it into the editor.

Markdown2HTML escapes raw HTML for normal Markdown output, but any error fallback returns the model response as plain HTML. TextEditor.vue then assigns htmlContent.value through editor.commands.setContent(...), so fallback HTML can bypass the Markdown renderer’s protections. Ensure the fallback also sanitizes raw HTML and dangerous URL schemes before it is persisted or loaded into the editor.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/ai.go` at line 298, Update the response handling around Markdown2HTML and
SendEnvelope so fallback AI output is sanitized before persistence or editor
loading. Sanitize raw HTML and reject dangerous URL schemes for both rendered
Markdown and error-fallback content, preserving the existing SendEnvelope flow
while ensuring no unsanitized model response reaches TextEditor.vue.

@abhinavxd
abhinavxd merged commit 9c1c413 into main Jul 30, 2026
5 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 31, 2026
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