Skip to content

Enable rich-text messages in matrix channel#1370

Merged
yinwm merged 2 commits intosipeed:mainfrom
dim:matrix/formatting
Mar 11, 2026
Merged

Enable rich-text messages in matrix channel#1370
yinwm merged 2 commits intosipeed:mainfrom
dim:matrix/formatting

Conversation

@dim
Copy link
Contributor

@dim dim commented Mar 11, 2026

📝 Description

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL: n/a
  • Reasoning: Messages are being sent as markdown but not picked up in common Matrix client, e.g. Element or FluffyChat

🧪 Test Environment

  • Hardware: Raspberry Pi 5
  • OS: Debian 13
  • Model/Provider: Gemini
  • Channels: Matrix

📸 Evidence (Optional)

Details image

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@CLAassistant
Copy link

CLAassistant commented Mar 11, 2026

CLA assistant check
All committers have signed the CLA.

@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: channel go Pull requests that update go code labels Mar 11, 2026
Copy link
Collaborator

@yinwm yinwm left a comment

Choose a reason for hiding this comment

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

Review Summary

This PR adds rich-text message support for the Matrix channel by converting Markdown to HTML format. The implementation is clean and well-structured.

✅ What's Good

  1. Clean code reuse: The messageContent() method is properly shared between Send() and EditMessage(), eliminating code duplication.

  2. Correct Matrix spec compliance: The implementation correctly keeps the original Markdown in Body as fallback while providing HTML in FormattedBody:

    mc := &event.MessageEventContent{MsgType: event.MsgText, Body: text}  // fallback
    mc.FormattedBody = markdownToHTML(text)  // rich text
  3. Sensible defaults: Richtext is enabled by default (when MessageFormat is empty or "richtext"), with explicit "plain" option for users who prefer raw Markdown.

  4. Good test coverage: Both TestMarkdownToHTML and TestMessageContent cover the key scenarios including richtext, plain, and default configurations.

  5. Documentation: README is updated with clear explanation of the new message_format option.

🔒 Security

The gomarkdown/markdown library doesn't parse raw HTML by default, and Matrix clients are responsible for HTML sanitization per the spec. The generated tags (<strong>, <em>, <code>, <pre>, <a>, headers, lists, etc.) are all within Matrix's allowed HTML subset.

LGTM! 🚀

@yinwm yinwm merged commit 39a451d into sipeed:main Mar 11, 2026
4 checks passed
@yinwm
Copy link
Collaborator

yinwm commented Mar 11, 2026

thanks for the pr

Alix-007 pushed a commit to Alix-007/picoclaw that referenced this pull request Mar 12, 2026
* Enable rich-text messages in matrix channel

* Fix lint
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 14, 2026
* Enable rich-text messages in matrix channel

* Fix lint
dj-oyu pushed a commit to dj-oyu/picoclaw that referenced this pull request Mar 16, 2026
* Enable rich-text messages in matrix channel

* Fix lint
j0904 pushed a commit to j0904/picoclaw that referenced this pull request Mar 22, 2026
* Enable rich-text messages in matrix channel

* Fix lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: channel go Pull requests that update go code type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants