Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Meshtastic/Resources/docs/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,24 @@
"orange",
"markdown",
"delimiters",
"conversation",
"tap",
"retry",
"exclamationmark",
"tap",
"recipient",
"node",
"meshtastic",
"conversation",
"after",
"selection",
"links",
"bold",
"radio",
"public",
"links",
"field",
"button",
"symbol"
],
"charCount": 11883
"charCount": 12005
},
{
"id": "mqtt",
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Resources/docs/markdown/user/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ On iOS 18 and later, formatting buttons appear in the compact toolbar below the

When the compose field contains markdown syntax, a preview bubble appears above the compose field showing how the message will look when sent. The preview updates in real time as you type. When no markdown is present, the preview is hidden.

Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance.
Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance. Links in these conversation-list previews are not interactive; open the conversation to tap a link in its message bubble.

| Example | Description |
|---------|-------------|
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Resources/docs/user/messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h3>How to Format Text</h3>
</ol>
<h3>Live Preview</h3>
<p>When the compose field contains markdown syntax, a preview bubble appears above the compose field showing how the message will look when sent. The preview updates in real time as you type. When no markdown is present, the preview is hidden.</p>
<p>Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance.</p>
<p>Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance. Links in these conversation-list previews are not interactive; open the conversation to tap a link in its message bubble.</p>
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic/Views/Messages/ChannelList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ struct ChannelList: View {

if hasMessages {
HStack(alignment: .top) {
Text(LocalizedStringKey(mostRecent?.messagePayload ?? " "))
MessagePreviewText(mostRecent?.messagePayload ?? " ")
.font(.footnote)
.foregroundColor(.onSurfaceVariant)
}
Expand Down
33 changes: 33 additions & 0 deletions Meshtastic/Views/Messages/MessagePreviewText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// MARK: MessagePreviewText

import SwiftUI

struct MessagePreviewText: View {

private let text: AttributedString

init(_ source: String) {
text = Self.attributedString(for: source)
}

var body: some View {
Text(text)
}

static func attributedString(for source: String) -> AttributedString {
guard var result = try? AttributedString(
markdown: source,
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
) else {
return AttributedString(source)
}

let linkRanges = result.runs.compactMap { run in
run.link == nil ? nil : run.range
}
for range in linkRanges {
result[range].link = nil
}
return result
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
2 changes: 1 addition & 1 deletion Meshtastic/Views/Messages/UserList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private struct DirectMessageUserRow: View {

if let summary {
HStack(alignment: .top) {
Text(LocalizedStringKey(summary.payload))
MessagePreviewText(summary.payload)
.font(.footnote)
.foregroundColor(.onSurfaceVariant)
}
Expand Down
27 changes: 27 additions & 0 deletions MeshtasticTests/MessagePreviewTextTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import Testing

@testable import Meshtastic

@Suite("Message preview text")
struct MessagePreviewTextTests {

@Test("Bare URLs are not interactive in conversation previews")
func bareURLIsNotInteractive() {
let source = "See https://meshtastic.org/docs for details"
let preview = MessagePreviewText.attributedString(for: source)

#expect(String(preview.characters) == source)
#expect(preview.runs.allSatisfy { $0.link == nil })
}

@Test("Markdown links keep their label without remaining interactive")
func markdownLinkIsNotInteractive() {
let preview = MessagePreviewText.attributedString(
for: "Read the [Meshtastic docs](https://meshtastic.org/docs)"
)

#expect(String(preview.characters) == "Read the Meshtastic docs")
#expect(preview.runs.allSatisfy { $0.link == nil })
}
}
2 changes: 1 addition & 1 deletion docs/user/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ On iOS 18 and later, formatting buttons appear in the compact toolbar below the

When the compose field contains markdown syntax, a preview bubble appears above the compose field showing how the message will look when sent. The preview updates in real time as you type. When no markdown is present, the preview is hidden.

Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance.
Markdown formatting is also rendered in the channel and user message list previews, so you can see formatted text at a glance. Links in these conversation-list previews are not interactive; open the conversation to tap a link in its message bubble.

| Example | Description |
|---------|-------------|
Expand Down
Loading