Skip to content

fix(mattermost): preserve markdown formatting and native tables#18655

Merged
mukhtharcm merged 7 commits intoopenclaw:mainfrom
0mg-cc:refresh/mattermost-markdown-12238-12245
Mar 10, 2026
Merged

fix(mattermost): preserve markdown formatting and native tables#18655
mukhtharcm merged 7 commits intoopenclaw:mainfrom
0mg-cc:refresh/mattermost-markdown-12238-12245

Conversation

@echo931
Copy link
Contributor

@echo931 echo931 commented Feb 16, 2026

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 Summary

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.

Confidence Score: 5/5

  • 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

Last reviewed commit: ae2824f

Echo added 3 commits February 16, 2026 18:18
… natively

Three related bugs in the Mattermost channel plugin:

1. normalizeMention() used \s+ replacement which collapsed newlines into
   spaces, destroying all block-level Markdown (headings, lists, blockquotes,
   task lists) in inbound messages. Fixed to only collapse horizontal
   whitespace (spaces/tabs) while preserving newlines.

2. DEFAULT_TABLE_MODES did not include mattermost, so it fell through to
   the "code" default which wraps tables in fenced code blocks. Mattermost
   clients render pipe tables natively, so the correct default is "off".

3. When tableMode was "code" and a message contained tables, the entire
   text was re-rendered through the IR pipeline which also stripped block
   formatting from non-table content.

Also extracted normalizeMention to monitor-helpers.ts for testability and
added unit tests for both fixes.

Fixes: openclaw#12247, openclaw#12245, openclaw#12238
…eedback)

Replaced blanket horizontal-whitespace collapse with a line-by-line approach
that only collapses runs of multiple spaces after non-space characters,
preserving leading indentation for nested lists and code blocks.
…of source text

Address review feedback: replace brittle fs.readFileSync source
inspection with direct import of the exported map.
@echo931
Copy link
Contributor Author

echo931 commented Feb 16, 2026

@codex review

@openclaw-barnacle openclaw-barnacle bot added channel: mattermost Channel integration: mattermost size: S labels Feb 16, 2026
@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Nice work!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mukhtharcm mukhtharcm merged commit bda63c3 into openclaw:main Mar 10, 2026
26 of 28 checks passed
@mukhtharcm
Copy link
Member

Merged via squash.

Thanks @echo931!

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 10, 2026
* main: (43 commits)
  docs: add openclaw#42173 to CHANGELOG — strip leaked model control tokens (openclaw#42216)
  Agents: align onPayload callback and OAuth imports
  docs: add Tengji (George) Zhang to maintainer table (openclaw#42190)
  fix: strip leaked model control tokens from user-facing text (openclaw#42173)
  Changelog: add unreleased March 9 entries
  chore: add .dev-state to .gitignore (openclaw#41848)
  fix(agents): avoid duplicate same-provider cooldown probes in fallback runs (openclaw#41711)
  fix(mattermost): preserve markdown formatting and native tables (openclaw#18655)
  feat(acp): add resumeSessionId to sessions_spawn for ACP session resume (openclaw#41847)
  ACPX: bump bundled acpx to 0.1.16 (openclaw#41975)
  mattermost: fix DM media upload for unprefixed user IDs (openclaw#29925)
  fix(msteams): use General channel conversation ID as team key for Bot Framework compatibility (openclaw#41838)
  fix(mattermost): read replyTo param in plugin handleAction send (openclaw#41176)
  fix(sandbox): pass real workspace to sessions_spawn when workspaceAccess is ro (openclaw#40757)
  fix(ui): replace Manual RPC text input with sorted method dropdown (openclaw#14967)
  CI: select Swift 6.2 toolchain for CodeQL (openclaw#41787)
  fix(agents): forward memory flush write path (openclaw#41761)
  fix(telegram): move network fallback to resolver-scoped dispatchers (openclaw#40740)
  fix(security): harden replaceMarkers() to catch space/underscore boundary marker variants (openclaw#35983)
  fix(web-search): recover OpenRouter Perplexity citations from message annotations (openclaw#40881)
  ...
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
frankekn pushed a commit to MoerAI/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
frankekn pushed a commit to Effet/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
frankekn pushed a commit to ImLukeF/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
dominicnunez pushed a commit to dominicnunez/openclaw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
ahelpercn pushed a commit to ahelpercn/openclaw that referenced this pull request Mar 12, 2026
…claw#18655)

Merged via squash.

Prepared head SHA: d30fff1
Co-authored-by: echo931 <259437483+echo931@users.noreply.github.com>
Co-authored-by: mukhtharcm <56378562+mukhtharcm@users.noreply.github.com>
Reviewed-by: @mukhtharcm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Mattermost channel wraps Markdown tables in fenced code blocks instead of rendering tables

2 participants