Skip to content

feat(message-parser): add GFM table support#41109

Open
ggazzo wants to merge 8 commits into
developfrom
feat/message-parser-markdown-gaps
Open

feat(message-parser): add GFM table support#41109
ggazzo wants to merge 8 commits into
developfrom
feat/message-parser-markdown-gaps

Conversation

@ggazzo

@ggazzo ggazzo commented Jun 29, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Adds GFM-style table support across the message parser and the renderer.

Parser (@rocket.chat/message-parser)

The parser now recognizes tables and emits new TABLE, TABLE_ROW, and TABLE_CELL AST nodes:

| Header 1 | Header 2 |
| -------- | :------: |
| Cell 1   | Cell 2   |

Behavior:

  • Column alignment is read from the delimiter row: :--- (left), :--: (center), ---: (right), --- (none).
  • Inline markup (bold, italic, links, emoji, …) is supported inside cells.
  • A leading and trailing pipe is required on every row; rows without surrounding pipes fall back to a paragraph.
  • A literal pipe inside a cell must be escaped as \|.

AST shape:

{ type: 'TABLE', value: { header: TableCell[], rows: TableRow[] } }
{ type: 'TABLE_ROW', value: TableCell[] }
{ type: 'TABLE_CELL', align: 'left' | 'center' | 'right' | undefined, value: Inlines[] }

Renderer (@rocket.chat/gazzodown)

  • Renders the new table nodes using Fuselage's Table / TableHead / TableBody / TableRow / TableCell components.
  • Cell alignment is translated to Fuselage's start / center / end.
  • Tables are rendered striped.
  • Message previews show a compact single-row rendering of the table header.
  • Added a Table story (and a table block in the Example story) to Markup.stories.tsx.
image

Steps to test or reproduce

Parser:

  1. cd packages/message-parser
  2. yarn jest tests/table.test.ts

Renderer (visual):

  1. yarn turbo run build --filter=@rocket.chat/gazzodown
  2. yarn workspace @rocket.chat/gazzodown storybook
  3. Open the Markup stories → Table / Example.

Or paste in a message:

| Name | Status | Score |
| :--- | :----: | ----: |
| Alice | **done** | 9.5 |
| Bob | :smile: | 7 |

Further comments

Tables require surrounding pipes in this first iteration to keep the grammar unambiguous against the existing inline | (spoiler) syntax.

Review in cubic

Task: ARCH-2196

Summary by CodeRabbit

  • New Features
    • Added GFM-style Markdown table support in message parsing, including per-column alignment, inline formatting within cells, and escaped literal pipes.
    • Tables now render in the message view, with table headers shown in previews.
    • Added Storybook examples demonstrating table rendering.
  • Bug Fixes
    • Improved detection of valid table syntax and ensured malformed/incomplete table-like text continues to render as normal content.
  • Documentation
    • Documented table markup rules in the message-parser README.
  • Tests
    • Added Jest coverage for table parsing, normalization, and edge cases.

@dionisio-bot

dionisio-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds GFM-style table parsing to @rocket.chat/message-parser and table rendering to @rocket.chat/gazzodown. It introduces new table AST types and grammar rules, adds parser tests and docs, and wires TABLE nodes into full rendering and preview paths.

Changes

GFM Table Support

Layer / File(s) Summary
Table AST types and parsing core
packages/message-parser/src/definitions.ts, packages/message-parser/src/grammar.pegjs, packages/message-parser/src/utils.ts
Adds table node types and parser support for aligned pipe tables, escaped pipes, trimmed cell content, and optional fallback ranges.
Parser tests and documentation
packages/message-parser/tests/helpers.ts, packages/message-parser/tests/table.test.ts, packages/message-parser/README.md, .changeset/tame-tables-render.md
Adds table test builders, parsing coverage, Markdown docs, and release note text for the new table format.
Table rendering and previews
packages/gazzodown/src/blocks/TableBlock.tsx, packages/gazzodown/src/Markup.tsx, packages/gazzodown/src/PreviewMarkup.tsx, packages/gazzodown/src/Markup.stories.tsx
Adds table rendering in markup and preview components and includes Storybook examples for table content.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MarkdownInput
  participant grammar.pegjs
  participant utils.ts
  participant Markup.tsx
  participant TableBlock.tsx

  MarkdownInput->>grammar.pegjs: parse table rows
  grammar.pegjs->>grammar.pegjs: derive alignment and cells
  grammar.pegjs->>utils.ts: table(header, aligns, rows, fallback)
  utils.ts->>utils.ts: trim cell whitespace
  utils.ts-->>Markup.tsx: TABLE AST node
  Markup.tsx->>TableBlock.tsx: render header and rows
  TableBlock.tsx->>TableBlock.tsx: map alignments and inline cells
Loading

Suggested labels: type: feature

Suggested reviewers: sampaiodiego

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding GFM table support, centered on the message parser.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • ARCH-2196: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5516f46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
@rocket.chat/message-parser Minor
@rocket.chat/gazzodown Major
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/core-typings Patch
@rocket.chat/livechat Patch
@rocket.chat/rest-typings Patch
rocketchat-services Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.32099% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.17%. Comparing base (4117a1d) to head (5516f46).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41109      +/-   ##
===========================================
+ Coverage    69.12%   69.17%   +0.04%     
===========================================
  Files         3433     3434       +1     
  Lines       132444   132799     +355     
  Branches     23097    23222     +125     
===========================================
+ Hits         91552    91862     +310     
- Misses       37531    37566      +35     
- Partials      3361     3371      +10     
Flag Coverage Δ
unit 70.02% <54.32%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ggazzo

ggazzo commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

Follow-up: #41110 adds a graceful block-level fallback (degrade unsupported blocks to their raw source text instead of null), so renderers that don't implement tables yet — e.g. mobile — don't silently drop the content.

@ggazzo ggazzo added this to the 8.7.0 milestone Jun 30, 2026
@ggazzo

ggazzo commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

/jira ARCH-2167

@ggazzo ggazzo force-pushed the feat/message-parser-markdown-gaps branch from ebb5c54 to ac9dd0f Compare July 1, 2026 14:24
@ggazzo ggazzo marked this pull request as ready for review July 1, 2026 14:38
@coderabbitai coderabbitai Bot added the type: feature Pull requests that introduces new feature label Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/gazzodown/src/blocks/TableBlock.tsx (1)

19-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding unit/snapshot tests for TableBlock.

No test file accompanies this new component; coverage currently relies only on the Storybook story. A basic render test (alignment mapping, empty rows/header) would guard against regressions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/gazzodown/src/blocks/TableBlock.tsx` around lines 19 - 42, Add
unit/snapshot coverage for TableBlock, since the new TableBlock component
currently has no test file and only relies on the Storybook story. Create tests
that render TableBlock with representative header/rows data and verify the table
renders correctly, including alignment mapping through toAlign and behavior when
header or rows are empty. Use the TableBlock component and its props shape as
the main entry points for locating the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/message-parser/README.md`:
- Around line 55-59: The fenced markdown example in the README is missing a
language tag, which triggers markdownlint MD040. Update the opening fence in the
example to use a markdown language identifier such as md or markdown so the
snippet stays lint-clean; this change is in the fenced example block in the
README.

In `@packages/message-parser/src/grammar.pegjs`:
- Around line 103-115: The table grammar currently lets Table parse a header row
and a delimiter row with different column counts, which can still produce a
TABLE with mismatched header/alignment mappings. Update the Table rule in
grammar.pegjs to validate that TableRowLine and TableDelimiterRow produce the
same number of cells before calling table(...), and reject the parse when they
differ; keep the check close to the Table/TableRowLine/TableDelimiterRow symbols
so the GFM table shape is enforced consistently.

---

Nitpick comments:
In `@packages/gazzodown/src/blocks/TableBlock.tsx`:
- Around line 19-42: Add unit/snapshot coverage for TableBlock, since the new
TableBlock component currently has no test file and only relies on the Storybook
story. Create tests that render TableBlock with representative header/rows data
and verify the table renders correctly, including alignment mapping through
toAlign and behavior when header or rows are empty. Use the TableBlock component
and its props shape as the main entry points for locating the code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84e8f087-9654-40fc-ad0b-4b0c0dcf8d1f

📥 Commits

Reviewing files that changed from the base of the PR and between 70c0ff0 and ac9dd0f.

📒 Files selected for processing (12)
  • .changeset/gazzodown-render-tables.md
  • .changeset/tame-tables-render.md
  • packages/gazzodown/src/Markup.stories.tsx
  • packages/gazzodown/src/Markup.tsx
  • packages/gazzodown/src/PreviewMarkup.tsx
  • packages/gazzodown/src/blocks/TableBlock.tsx
  • packages/message-parser/README.md
  • packages/message-parser/src/definitions.ts
  • packages/message-parser/src/grammar.pegjs
  • packages/message-parser/src/utils.ts
  • packages/message-parser/tests/helpers.ts
  • packages/message-parser/tests/table.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (6)
  • GitHub Check: 🚢 Build Docker (arm64, account-service, presence-service, omnichannel-transcript-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, rocketchat, coverage)
  • GitHub Check: 🚢 Build Docker (arm64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: 🚢 Build Docker (amd64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/gazzodown/src/blocks/TableBlock.tsx
  • packages/gazzodown/src/PreviewMarkup.tsx
  • packages/message-parser/tests/table.test.ts
  • packages/gazzodown/src/Markup.tsx
  • packages/gazzodown/src/Markup.stories.tsx
  • packages/message-parser/tests/helpers.ts
  • packages/message-parser/src/utils.ts
  • packages/message-parser/src/definitions.ts
🧠 Learnings (5)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/tame-tables-render.md
  • .changeset/gazzodown-render-tables.md
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • packages/gazzodown/src/blocks/TableBlock.tsx
  • packages/gazzodown/src/PreviewMarkup.tsx
  • packages/gazzodown/src/Markup.tsx
  • packages/gazzodown/src/Markup.stories.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/gazzodown/src/blocks/TableBlock.tsx
  • packages/gazzodown/src/PreviewMarkup.tsx
  • packages/message-parser/tests/table.test.ts
  • packages/gazzodown/src/Markup.tsx
  • packages/gazzodown/src/Markup.stories.tsx
  • packages/message-parser/tests/helpers.ts
  • packages/message-parser/src/utils.ts
  • packages/message-parser/src/definitions.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/tests/table.test.ts
  • packages/message-parser/tests/helpers.ts
  • packages/message-parser/src/utils.ts
  • packages/message-parser/src/definitions.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/tests/table.test.ts
  • packages/message-parser/tests/helpers.ts
  • packages/message-parser/src/utils.ts
  • packages/message-parser/src/definitions.ts
🪛 markdownlint-cli2 (0.22.1)
packages/message-parser/README.md

[warning] 55-55: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (5)
packages/gazzodown/src/blocks/TableBlock.tsx (1)

1-45: LGTM!

packages/gazzodown/src/Markup.tsx (1)

9-9: LGTM!

Also applies to: 66-68

packages/gazzodown/src/PreviewMarkup.tsx (1)

89-100: LGTM!

packages/gazzodown/src/Markup.stories.tsx (1)

261-272: LGTM!

Also applies to: 306-310

.changeset/gazzodown-render-tables.md (1)

1-5: LGTM!

Comment thread packages/message-parser/README.md Outdated
Comment on lines +103 to +115
Table = header:TableRowLine aligns:TableDelimiterRow body:TableRowLine* { return table(header, aligns, body, [range().start, range().end]); }

TableRowLine = "|" cells:(@TableCell "|")+ EndOfLine? { return cells; }

TableCell = items:TableCellItem* { return reducePlainTexts(items); }

TableCellItem
= "\\|" { return plain('|'); }
/ !"|" !EndOfLine @(InlineItemPattern / Any)

TableDelimiterRow = "|" aligns:(@TableDelimiterCell "|")+ EndOfLine? { return aligns; }

TableDelimiterCell = [ \t]* left:":"? "-"+ right:":"? [ \t]* {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject header/delimiter width mismatches.

TableRowLine and TableDelimiterRow are parsed independently here, so input like | a | b |\n| - | still becomes a TABLE. That contradicts the GFM table contract and leaves downstream code with a malformed column/alignment mapping.

Suggested fix
-Table = header:TableRowLine aligns:TableDelimiterRow body:TableRowLine* { return table(header, aligns, body, [range().start, range().end]); }
+Table
+  = header:TableRowLine aligns:TableDelimiterRow &{ return header.length === aligns.length; } body:TableRowLine* {
+      return table(header, aligns, body, [range().start, range().end]);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Table = header:TableRowLine aligns:TableDelimiterRow body:TableRowLine* { return table(header, aligns, body, [range().start, range().end]); }
TableRowLine = "|" cells:(@TableCell "|")+ EndOfLine? { return cells; }
TableCell = items:TableCellItem* { return reducePlainTexts(items); }
TableCellItem
= "\\|" { return plain('|'); }
/ !"|" !EndOfLine @(InlineItemPattern / Any)
TableDelimiterRow = "|" aligns:(@TableDelimiterCell "|")+ EndOfLine? { return aligns; }
TableDelimiterCell = [ \t]* left:":"? "-"+ right:":"? [ \t]* {
Table
= header:TableRowLine aligns:TableDelimiterRow &{ return header.length === aligns.length; } body:TableRowLine* {
return table(header, aligns, body, [range().start, range().end]);
}
TableRowLine = "|" cells:(`@TableCell` "|")+ EndOfLine? { return cells; }
TableCell = items:TableCellItem* { return reducePlainTexts(items); }
TableCellItem
= "\\|" { return plain('|'); }
/ !"|" !EndOfLine @(InlineItemPattern / Any)
TableDelimiterRow = "|" aligns:(`@TableDelimiterCell` "|")+ EndOfLine? { return aligns; }
TableDelimiterCell = [ \t]* left:":"? "-"+ right:":"? [ \t]* {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/message-parser/src/grammar.pegjs` around lines 103 - 115, The table
grammar currently lets Table parse a header row and a delimiter row with
different column counts, which can still produce a TABLE with mismatched
header/alignment mappings. Update the Table rule in grammar.pegjs to validate
that TableRowLine and TableDelimiterRow produce the same number of cells before
calling table(...), and reject the parse when they differ; keep the check close
to the Table/TableRowLine/TableDelimiterRow symbols so the GFM table shape is
enforced consistently.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

3 issues found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/message-parser/src/grammar.pegjs">

<violation number="1" location="packages/message-parser/src/grammar.pegjs:103">
P2: Implement GFM column-count semantics in the table rule. Malformed header/delimiter counts should fall back to paragraphs, and ragged body rows should be padded/truncated before rendering.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

* the delimiter row: `:---` left, `:--:` center, `---:` right, `---` none.
* A literal pipe inside a cell must be escaped as `\|`.
*/
Table = header:TableRowLine aligns:TableDelimiterRow body:TableRowLine* { return table(header, aligns, body, [range().start, range().end]); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Implement GFM column-count semantics in the table rule. Malformed header/delimiter counts should fall back to paragraphs, and ragged body rows should be padded/truncated before rendering.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/message-parser/src/grammar.pegjs, line 103:

<comment>Implement GFM column-count semantics in the table rule. Malformed header/delimiter counts should fall back to paragraphs, and ragged body rows should be padded/truncated before rendering.</comment>

<file context>
@@ -86,6 +88,37 @@ BlockquoteLine
+ * the delimiter row: `:---` left, `:--:` center, `---:` right, `---` none.
+ * A literal pipe inside a cell must be escaped as `\|`.
+ */
+Table = header:TableRowLine aligns:TableDelimiterRow body:TableRowLine* { return table(header, aligns, body, [range().start, range().end]); }
+
+TableRowLine = "|" cells:(@TableCell "|")+ EndOfLine? { return cells; }
</file context>

Comment thread packages/message-parser/src/utils.ts
Comment thread packages/message-parser/src/utils.ts

@hacktron-app hacktron-app Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file

Severity Count
MEDIUM 1

View full scan results

Comment thread packages/gazzodown/src/blocks/TableBlock.tsx Outdated
ggazzo added 7 commits July 1, 2026 17:03
Parse GFM-style tables into new TABLE/TABLE_ROW/TABLE_CELL AST nodes.
Column alignment is read from the delimiter row (:---, :--:, ---:), and
inline markup is supported inside cells. A leading and trailing pipe is
required on every row; a literal pipe inside a cell must be escaped as \|.
Map TABLE/TABLE_ROW/TABLE_CELL AST nodes to Fuselage's Table, TableHead,
TableBody, TableRow and TableCell components, translating cell alignment
(left/center/right) to Fuselage's start/center/end. Message previews show
a compact single-row rendering of the table header.
The TABLE node now carries an optional `fallback` plain-text node holding
its matched source (via the grammar's text()), so consumers without a table
renderer can degrade to the original markup instead of dropping the node.
Replace the duplicated plain-text `fallback` on the TABLE node with a
[start, end] offset span (new SourceRange type) into the original source.
Avoids bloating the persisted/transmitted AST; consumers slice the source
(available as message.msg) to render the raw markup.
@ggazzo ggazzo force-pushed the feat/message-parser-markdown-gaps branch from 3f39b26 to 509f163 Compare July 1, 2026 20:05
- Normalize ragged table body rows to the header column count (pad missing
  cells, drop extras) so GFM rows stay aligned with the header/delimiter.
- Map table cell alignment with an explicit switch instead of an object lookup,
  so a crafted AST align (e.g. __proto__/toString) can't resolve to an
  inherited value in the renderer.
- Add a language to the README table fence (markdownlint MD040).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/message-parser/tests/table.test.ts (1)

89-105: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a case for a missing leading pipe.

Only a missing trailing pipe is tested; the PR description also states leading pipes are required. Consider adding a symmetrical case for a missing leading pipe to fully cover the "surrounding pipes required" rule.

♻️ Suggested addition
 	// missing trailing pipe -> not a table (v1 requires surrounding pipes)
 	[
 		`
 | a | b
 | - | -
 `.trim(),
 		[
 			{ type: 'PARAGRAPH', value: [plain('| a | b')] },
 			{ type: 'PARAGRAPH', value: [plain('| - | -')] },
 		],
 	],
+	// missing leading pipe -> not a table (v1 requires surrounding pipes)
+	[
+		`
+a | b |
+- | - |
+`.trim(),
+		[
+			{ type: 'PARAGRAPH', value: [plain('a | b |')] },
+			{ type: 'PARAGRAPH', value: [plain('- | - |')] },
+		],
+	],
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/message-parser/tests/table.test.ts` around lines 89 - 105, Add a new
negative test in table.test.ts for the “surrounding pipes required” rule by
covering a missing leading pipe case alongside the existing missing trailing
pipe coverage. Update the test.each block around parse() so it includes an input
like a table row without the leading pipe and asserts it is parsed as plain
PARAGRAPH nodes, matching the existing plain text expectations and keeping the
behavior symmetrical.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/message-parser/tests/table.test.ts`:
- Around line 89-105: Add a new negative test in table.test.ts for the
“surrounding pipes required” rule by covering a missing leading pipe case
alongside the existing missing trailing pipe coverage. Update the test.each
block around parse() so it includes an input like a table row without the
leading pipe and asserts it is parsed as plain PARAGRAPH nodes, matching the
existing plain text expectations and keeping the behavior symmetrical.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ddf4adec-78cf-4c6e-afa0-9de49c49b2ed

📥 Commits

Reviewing files that changed from the base of the PR and between 509f163 and 5516f46.

📒 Files selected for processing (4)
  • packages/gazzodown/src/blocks/TableBlock.tsx
  • packages/message-parser/README.md
  • packages/message-parser/src/utils.ts
  • packages/message-parser/tests/table.test.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/message-parser/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/message-parser/src/utils.ts
  • packages/gazzodown/src/blocks/TableBlock.tsx
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/message-parser/tests/table.test.ts
🧠 Learnings (3)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/tests/table.test.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/tests/table.test.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • packages/message-parser/tests/table.test.ts
🔇 Additional comments (2)
packages/message-parser/tests/table.test.ts (2)

1-69: LGTM!


71-87: LGTM!

@ggazzo

ggazzo commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews — addressed in the latest commit:

  • Ragged body rows (cubic utils.ts): rows are now normalized to the header column count — missing cells are padded, extras dropped — so they stay aligned with the header/delimiter. Added a regression test.
  • Unsafe align lookup / stored DoS (hacktron TableBlock.tsx): toAlign now uses an explicit switch instead of an object lookup, so a crafted AST align (e.g. __proto__ / toString) can't resolve to an inherited value.
  • MD040 (coderabbit README.md): the table fence now declares a language (```md).

Not addressed on purpose: header/delimiter column-count mismatch (| a | b | + | - |) still produces a TABLE instead of falling back to a paragraph. Per GFM it should be plain text, but the impact is cosmetic (no crash, no security) and this is a documented v1 limitation. Easy follow-up via a semantic predicate (&{ return header.length === aligns.length }) if we want strict GFM parity later.

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

Labels

type: feature Pull requests that introduces new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant