Skip to content

Basic Markdown support#183

Merged
acarlson33 merged 1 commit into
mainfrom
04-12-basic_markdown_support
May 5, 2026
Merged

Basic Markdown support#183
acarlson33 merged 1 commit into
mainfrom
04-12-basic_markdown_support

Conversation

@acarlson33

@acarlson33 acarlson33 commented Apr 19, 2026

Copy link
Copy Markdown
Owner

This pull request adds robust Markdown support to the MessageWithMentions component, ensuring safe rendering of links and proper handling of mentions, emojis, and formatting. It also updates the test suite to cover these new behaviors and makes a minor UI adjustment in the search results.

Markdown rendering and safety improvements:

  • src/components/message-with-mentions.tsx: Integrates react-markdown with remark-gfm to support basic Markdown formatting (bold, italic, strikethrough, lists, blockquotes, links, code, etc.) in messages. Ensures that only safe links (http, https, mailto, or relative) are rendered as clickable, with external links opening in a new tab and using rel="noopener noreferrer" for security. Unsafe links (e.g., javascript:) are not rendered as links. [1] [2]

  • src/components/message-with-mentions.tsx: Mentions are tokenized and injected into the Markdown rendering flow, preserving highlighting and formatting even inside Markdown elements. Custom emoji rendering is disabled inside inline code blocks to prevent accidental parsing. [1] [2]

Test coverage:

UI consistency:

  • src/components/search-results.tsx: Changes the container for message previews from a <p> to a <div> to better support nested Markdown elements and avoid invalid HTML.

@appwrite

appwrite Bot commented Apr 19, 2026

Copy link
Copy Markdown

Firepit

Project ID: 68b230a0002245833242

Sites (1)
Site Status Logs Preview QR
 firepit
68eed9c6001f50d8f260
Ready Ready View Logs Preview URL QR Code

Tip

Sites auto-generate unique domains with the pattern https://randomstring.appwrite.network

acarlson33 commented Apr 19, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai

coderabbitai Bot commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@acarlson33 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 53 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e9effe16-a40e-47ac-9445-196afe33dcd9

📥 Commits

Reviewing files that changed from the base of the PR and between 8c1c998 and 2229c55.

📒 Files selected for processing (3)
  • src/__tests__/components/message-with-mentions.test.tsx
  • src/components/message-with-mentions.tsx
  • src/components/search-results.tsx
📝 Walkthrough

Walkthrough

The MessageWithMentions component now includes a refactored rendering pipeline that precomputes mention tokens, detects markdown content, and applies safe rendering via ReactMarkdown with custom element handlers and URL sanitization. Comprehensive test coverage validates markdown formatting, link safety, mention highlighting, and emoji handling. The search results markup container type was updated.

Changes

Cohort / File(s) Summary
MessageWithMentions Component Enhancement
src/components/message-with-mentions.tsx
Refactored rendering pipeline: precomputes mention tokens, detects markdown content, routes to ReactMarkdown with custom element renderers or fallback renderDecoratedText. Implements URL protocol whitelist to sanitize links (href validation, target="_blank", rel="noopener noreferrer"), renders unsafe URLs as plain text. Replaces markdown images with muted alt-text placeholders. Recursively processes markdown children to reapply mention/emoji decoration.
MessageWithMentions Test Coverage
src/__tests__/components/message-with-mentions.test.tsx
Added test cases for markdown formatting (bold, italic, strikethrough), safe/unsafe URL handling, mention highlighting within markdown, and emoji shortcode conversion behavior in code blocks.
SearchResults Markup Update
src/components/search-results.tsx
Changed container element wrapping MessageWithMentions from <p> to <div>.

Sequence Diagram

sequenceDiagram
    participant Input as Message Text
    participant Detector as Markdown Detector
    participant Router as Render Router
    participant Markdown as ReactMarkdown<br/>(with GFM)
    participant Renderers as Custom Element<br/>Renderers
    participant FallbackPath as RenderDecoratedText<br/>(Mentions & Emoji)
    participant Output as Rendered Output

    Input->>Detector: Check if markdown content
    alt Contains Markdown
        Detector->>Router: Is Markdown
        Router->>Markdown: Process via ReactMarkdown
        Markdown->>Renderers: Render custom elements
        Renderers->>Renderers: Sanitize links (protocol whitelist)
        Renderers->>Renderers: Replace images with alt placeholders
        Renderers->>Renderers: Recursively apply mentions & emoji
        Renderers->>Output: Return formatted output
    else No Markdown
        Detector->>Router: Not Markdown
        Router->>FallbackPath: Use fallback path
        FallbackPath->>FallbackPath: Apply mention tokens & emoji
        FallbackPath->>Output: Return decorated text
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Mentions dance through markdown halls,
Safe links now guard our waterfall,
Strikethrough bold and emoji cheer,
The rendering pipeline's crystal clear! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author; cannot assess whether the description relates to the changeset. Add a description explaining the Markdown support implementation, its scope, and how it integrates with existing mention and emoji features.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Basic Markdown support' accurately reflects the main changes: adding Markdown rendering support to the MessageWithMentions component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 04-12-basic_markdown_support
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch 04-12-basic_markdown_support

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 and usage tips.

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/search-results.tsx (1)

118-167: ⚠️ Potential issue | 🟠 Major

Avoid rendering Markdown anchors inside the result button.

MessageWithMentions can now emit <a> elements, so Markdown links in a search result create invalid nested interactive content inside this <button>. That can break keyboard/screen-reader behavior and make link clicks trigger row navigation instead. Disable link rendering for previews or move row navigation out of the ancestor of the message content. As per coding guidelines, Make sure all anchors are valid and navigable.

🐛 Suggested direction
                             <div className="mt-1 text-muted-foreground text-sm">
                                 <MessageWithMentions
                                     text={truncateText(message.text)}
                                     currentUserId=""
                                     customEmojis={customEmojis}
+                                    /* Prefer a prop such as renderLinks={false} here,
+                                       or render a non-interactive preview variant. */
                                 />
                             </div>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/search-results.tsx` around lines 118 - 167, The search result
button currently contains MessageWithMentions which can emit <a> elements,
causing nested interactive controls; fix by preventing link rendering inside the
preview: update the MessageWithMentions invocation in search-results.tsx (the
instance that uses truncateText(message.text)) to render plain text/no-anchors
(e.g., pass a prop like renderLinks={false} or plainText={true} if supported)
or, if MessageWithMentions has no such prop, replace it with a
non-markdown/plain-text rendering of truncateText(message.text) so no <a> tags
are produced; keep handleResultClick on the row button unchanged but ensure
message preview contains no anchors so keyboard/screen-reader behavior and click
routing remain correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/__tests__/components/message-with-mentions.test.tsx`:
- Around line 189-199: The test "should render basic markdown formatting" in
message-with-mentions.test.tsx currently mixes strong and strike-through which
can mask detection gaps for single-emphasis italics; update the test for the
MessageWithMentions component to include standalone italic cases using both
`_Italic_` and `*Italic*` (in separate render/assert blocks or additional
renders) and assert that each renders into an <em> element (e.g., via
screen.getByText("Italic").closest("em")) so the markdown detector for
single-emphasis is actually exercised.

In `@src/components/message-with-mentions.tsx`:
- Around line 18-21: The code currently tokenizes mentions into placeholders
(type MentionToken) before Markdown parsing but fails to restore them when
rendering code/pre/inline code nodes, causing placeholders like
FIREPITMENTIONTOKEN... to appear; update the renderer or AST walker used in
MessageWithMentions to detect code/pre/inlineCode nodes and replace any mention
placeholder substrings with their original MentionToken.token values (use the
existing MentionToken array or map you already create) before returning the
node's text/element; ensure this restoration runs in the same places you handle
normal text nodes (the code/pre branches referenced around lines ~18, ~194,
~263, ~382) so backticked mentions render correctly.
- Around line 13-14: The MARKDOWN_PATTERN currently misses single-emphasis
syntax (e.g., *italic* or _italic_), so messages that are valid Markdown but
only use single emphasis fall through to the plain-text branch; update the
MARKDOWN_PATTERN regex to include single-asterisk and single-underscore emphasis
alternatives (e.g., patterns matching \*...* and _..._) alongside the existing
bold/strikethrough/inline-link/list/blockquote/header cases so that
MARKDOWN_PATTERN correctly detects single-emphasis Markdown; modify the constant
MARKDOWN_PATTERN in src/components/message-with-mentions.tsx to add those
single-emphasis alternations.

---

Outside diff comments:
In `@src/components/search-results.tsx`:
- Around line 118-167: The search result button currently contains
MessageWithMentions which can emit <a> elements, causing nested interactive
controls; fix by preventing link rendering inside the preview: update the
MessageWithMentions invocation in search-results.tsx (the instance that uses
truncateText(message.text)) to render plain text/no-anchors (e.g., pass a prop
like renderLinks={false} or plainText={true} if supported) or, if
MessageWithMentions has no such prop, replace it with a non-markdown/plain-text
rendering of truncateText(message.text) so no <a> tags are produced; keep
handleResultClick on the row button unchanged but ensure message preview
contains no anchors so keyboard/screen-reader behavior and click routing remain
correct.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 46a3b3f8-7215-4b31-aa96-d6c0c42b925b

📥 Commits

Reviewing files that changed from the base of the PR and between 3b41765 and 8c1c998.

📒 Files selected for processing (3)
  • src/__tests__/components/message-with-mentions.test.tsx
  • src/components/message-with-mentions.tsx
  • src/components/search-results.tsx

Comment thread src/__tests__/components/message-with-mentions.test.tsx
Comment thread src/components/message-with-mentions.tsx
Comment thread src/components/message-with-mentions.tsx
Comment thread src/components/message-with-mentions.tsx
@acarlson33

Copy link
Copy Markdown
Owner Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Comments resolved and changes approved.

acarlson33 commented May 5, 2026

Copy link
Copy Markdown
Owner Author

Merge activity

  • May 5, 11:21 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 5, 11:22 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 5, 11:23 PM UTC: @acarlson33 merged this pull request with Graphite.

@acarlson33 acarlson33 changed the base branch from 04-12-announcement_channel_type_implementation to graphite-base/183 May 5, 2026 23:21
@acarlson33 acarlson33 changed the base branch from graphite-base/183 to main May 5, 2026 23:22
@acarlson33 acarlson33 force-pushed the 04-12-basic_markdown_support branch from 8c1c998 to 2229c55 Compare May 5, 2026 23:22
@acarlson33 acarlson33 merged commit 2fab7ff into main May 5, 2026
2 of 4 checks passed
@acarlson33 acarlson33 deleted the 04-12-basic_markdown_support branch May 5, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant