mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-10 20:51:53 +00:00
53 lines
2.0 KiB
Swift
53 lines
2.0 KiB
Swift
//
|
|
// MarkdownHelp.swift
|
|
// SimpleX
|
|
//
|
|
// Created by Evgeny on 24/02/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct MarkdownHelp: View {
|
|
@EnvironmentObject var theme: AppTheme
|
|
@State private var secretRevealed = false
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("You can use markdown to format messages:")
|
|
.padding(.bottom)
|
|
mdFormat("*bold*", Text("bold").bold())
|
|
mdFormat("_italic_", Text("italic").italic())
|
|
mdFormat("~strike~", Text("strike").strikethrough())
|
|
mdFormat("`a + b`", Text("`a + b`").font(.body.monospaced()))
|
|
mdFormat("!- small!", Text("small").font(.footnote).foregroundColor(.secondary))
|
|
mdFormat("!1 colored!", Text("colored").foregroundColor(.red) + Text(verbatim: " (") + color("1", .red) + color("2", .green) + color("3", .blue) + color("4", .yellow) + color("5", .cyan) + Text("6").foregroundColor(.purple) + Text(verbatim: ")"))
|
|
// matches how secret text works in chat: tap to reveal/hide
|
|
mdFormat("#secret#", secretRevealed
|
|
? Text("secret")
|
|
: Text("secret").foregroundColor(.clear).underline(color: theme.colors.onBackground))
|
|
.onTapGesture { secretRevealed.toggle() }
|
|
mdFormat("[link](https://simplex.chat)", Text("link").foregroundColor(theme.colors.primary).underline())
|
|
.onTapGesture { if let url = URL(string: "https://simplex.chat") { openExternalLink(url) } }
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
|
|
private func mdFormat(_ format: LocalizedStringKey, _ example: Text) -> some View {
|
|
HStack {
|
|
Text(format).frame(width: 120, alignment: .leading)
|
|
example
|
|
}
|
|
}
|
|
|
|
private func color(_ s: String, _ c: Color) -> Text {
|
|
Text(s).foregroundColor(c) + Text(verbatim: ", ")
|
|
}
|
|
|
|
struct MarkdownHelp_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MarkdownHelp()
|
|
}
|
|
}
|