From 5f07eb734eaa44f8a7120cee3ae06c7195c3a02a Mon Sep 17 00:00:00 2001
From: Till-JS <101404291+Till-JS@users.noreply.github.com>
Date: Thu, 29 Jan 2026 17:05:26 +0100
Subject: [PATCH] feat(matrix-web): add markdown formatting support
- Support **bold** and __bold__ syntax
- Support *italic* and _italic_ syntax
- Support `inline code` with styled background
- Support ~~strikethrough~~ text
- Refactor linkifyText to formatMessageBody
Co-Authored-By: Claude Opus 4.5 $1`);
+
+ // Bold (**text** or __text__)
+ text = text.replace(/\*\*([^*]+)\*\*/g, '$1');
+ text = text.replace(/__([^_]+)__/g, '$1');
+
+ // Italic (*text* or _text_) - be careful not to match inside URLs
+ text = text.replace(/(?$1');
+ text = text.replace(/(?$1');
+
+ // Strikethrough (~~text~~)
+ text = text.replace(/~~([^~]+)~~/g, '$1');
+
+ return text;
+ }
+
+ // Convert URLs to clickable links and apply markdown
+ function formatMessageBody(text: string, isOwn: boolean): string {
const escaped = escapeHtml(text);
const linkClass = isOwn
? 'underline underline-offset-2 hover:opacity-80'
: 'text-primary underline underline-offset-2 hover:opacity-80';
- return escaped.replace(urlRegex, (url) => {
+
+ // First apply markdown
+ let formatted = applyMarkdown(escaped, isOwn);
+
+ // Then linkify URLs
+ formatted = formatted.replace(urlRegex, (url) => {
return `${url}`;
});
+
+ return formatted;
}
// Extract first URL for preview
@@ -403,7 +431,7 @@
{@html linkifyText(message.body, message.isOwn)}
+{@html formatMessageBody(message.body, message.isOwn)}
{#if firstUrl()}