#18655: fix(mattermost): preserve markdown formatting and native tables
channel: mattermost
size: S
Cluster:
Mattermost Threading Enhancements
## Summary
Refresh of the old markdown/table work from stale PR #12809 onto current `main`.
This keeps Mattermost message formatting intact by preserving block-level markdown structure when removing mentions, and restores native table rendering behavior.
## Changes
- preserve leading indentation/newlines when stripping bot mention (`normalizeMention`)
- add/refresh tests for mention normalization behavior
- export `DEFAULT_TABLE_MODES` and assert runtime table-mode behavior via tests
## Validation
- `pnpm exec vitest run extensions/mattermost/src/mattermost/monitor-helpers.test.ts src/config/markdown-tables.test.ts`
Closes #12238
Refs #12245
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Refreshed markdown formatting preservation work from stale PR #12809. The changes ensure Mattermost messages maintain block-level markdown structure when removing bot mentions, and restore native table rendering by setting the default table mode to `off` for Mattermost.
**Key Changes:**
- Refactored `normalizeMention` to preserve leading indentation, newlines, and markdown formatting (headings, lists, blockquotes, code blocks) when stripping bot mentions
- Exported `DEFAULT_TABLE_MODES` constant to enable testing
- Added Mattermost to `DEFAULT_TABLE_MODES` map with `off` mode to render tables natively
- Added comprehensive test coverage for mention normalization edge cases
- Added tests to verify runtime table mode behavior
The implementation properly handles markdown structure preservation by replacing mentions with empty strings (avoiding space injection) and only collapsing multiple spaces within lines while preserving leading indentation.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-tested, focused, and straightforward. The `normalizeMention` refactor properly preserves markdown structure using a clear multi-step approach. The regex escaping is correct and matches existing patterns in the codebase. The table mode change is a simple configuration update with test coverage. The PR has excellent test coverage including edge cases for nested lists, code blocks, and various markdown formats.
- No files require special attention
<sub>Last reviewed commit: ae2824f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#12257: fix(mattermost): default table mode to 'off' for native Markdown re...
by mcaxtr · 2026-02-09
88.4%
#18657: feat(mattermost): add native slash command support (refresh)
by echo931 · 2026-02-16
75.4%
#22442: test(ci): unbreak baseline tui metadata + msteams local-file assert...
by SmithLabsLLC · 2026-02-21
74.4%
#20795: fix(markdown): prevent triple newlines after blockquotes
by novalis133 · 2026-02-19
74.2%
#20419: fix(webchat): explicitly pass gfm and breaks options to marked.parse()
by Limitless2023 · 2026-02-18
74.1%
#20441: fix: preserve newlines for markdown table rendering in WebChat
by MisterGuy420 · 2026-02-18
73.8%
#22075: mattermost: honor account requireMention override
by armindocachada · 2026-02-20
73.4%
#7719: fix(slack): thread replies with @mentions dropped in requireMention...
by SocialNerd42069 · 2026-02-03
73.1%
#12468: feat(mattermost): add read, search, and channel-list actions
by adamsbytes · 2026-02-09
73.1%
#10027: Mattermost: fix attachment downloads (GET + private-network hosts)
by transportrefer · 2026-02-06
72.9%