Skip to content

Added Support of Markdown Format#382

Open
KommunicateDeveloper wants to merge 1 commit intomasterfrom
markDownSupport
Open

Added Support of Markdown Format#382
KommunicateDeveloper wants to merge 1 commit intomasterfrom
markDownSupport

Conversation

@KommunicateDeveloper
Copy link
Contributor

Summary

  • Add Markdown detection, parsing, and rendering utilities, and integrate them into message cells

  • Introduce KMMarkdownDetector, KMMarkdownParser, and KMMarkdownRenderer leveraging iOS 15 AttributedString Markdown parsing with fallbacks for older OS versions

  • Update KMChatMessageBaseCell to:

    • Detect Markdown in incoming (non-self) messages
    • Parse and render Markdown into attributed strings
    • Merge mention styling with the rendered Markdown output
    • Use the combined attributed text for both sizing and display
  • Update KMChatFriendMessageCell to:

    • Render reply text using the Markdown parser
    • Apply minor formatting cleanups for constraints and image resource construction

Image

Simulator Screenshot - iPhone 17 Pro - 2026-02-18 at 19 25 51

Add Markdown detection, parsing and rendering utilities and integrate them into message cells. Introduces KMMarkdownDetector, KMMarkdownParser and KMMarkdownRenderer which use iOS 15 AttributedString markdown parsing with fallbacks for older OS versions. Update KMChatMessageBaseCell to detect markdown in incoming (non-my) text, render Markdown into attributed strings, merge mention styling with Markdown output, and use the combined attributed text for sizing and display. Update KMChatFriendMessageCell to render reply text with the Markdown parser and include minor formatting/formatting-cleanups for constraints and image resource construction.
Comment on lines +327 to +332
mentionAttributed.enumerateAttributes(
in: NSRange(location: 0, length: mentionAttributed.length),
options: []
) { attributes, range, _ in
if attributes.keys.contains(.foregroundColor) ||
attributes.keys.contains(.backgroundColor) ||
Copy link

Choose a reason for hiding this comment

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

Bug: Height calculation in messageHeight() assumes markdown for all messages, but setMessageText() only renders it for received messages, causing layout bugs for self-sent markdown messages.
Severity: MEDIUM

Suggested Fix

The height calculation logic in messageHeight() should be aligned with the display logic in setMessageText(). It should check if the message is self-sent (viewModel.isMyMessage) and only apply markdown sizing for received messages, matching the rendering behavior.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: Sources/Views/KMChatMessageBaseCell.swift#L327-L332

Potential issue: There is an inconsistency between message height calculation and
rendering for self-sent messages. The `messageHeight()` method calculates the cell
height assuming markdown is applied to all messages, including those sent by the user.
However, the `setMessageText()` method only renders markdown for received messages. This
causes a mismatch for self-sent messages containing markdown syntax, leading to
incorrect UI rendering, such as text clipping or improper bubble sizing.

Did we get this right? 👍 / 👎 to inform future reviews.

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