Add /html command (#560)

### Description

Adds a command called `/html` to send HTML messages.

#### Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
Rose authored and GitHub committed 2026-03-27 22:50:55 +00:00
commit f401f07247
2 files changed
+26

No files matched your search

@@ -0,0 +1,5 @@
---
default: minor
---
# Adds a `/html` command to send HTML messages
+21
View File
@@ -252,6 +252,7 @@ export enum Command {
SetExt = 'setext',
DelExt = 'delext',
DiscardSession = 'discardsession',
Html = 'html',
// Cute Events
Hug = 'hug',
Cuddle = 'cuddle',
@@ -1323,6 +1324,26 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
}
},
},
[Command.Html]: {
name: Command.Html,
description:
'Send a message with HTML content. Example: /html <span data-mx-color="#ff0000">Red</span>',
exe: async (payload) => {
await mx.sendMessage(room.roomId, {
msgtype: MsgType.Text,
body: payload
.replaceAll('<br>', '\n')
.replaceAll('<li>', '\n- ')
.replaceAll(
/<a(.*?)href="(?<link>(.*?))"(.*?)>(?<text>(.*?))<\/a>/g,
'[$<text>]($<link>)'
)
.replaceAll(/<[^>]*>/g, ''),
format: 'org.matrix.custom.html',
formatted_body: payload,
});
},
},
// Sharing E2EE History of a room with a user
[Command.ShareE2EEHistory]: {
name: Command.ShareE2EEHistory,