mirror of
https://github.com/ichmagmaus111/ghostgram.git
synced 2026-11-03 06:14:14 +01:00
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.2 KiB
Swift
28 lines
1.2 KiB
Swift
import Foundation
|
|
import TelegramCore
|
|
|
|
/// Decides whether a `ChatInputContent` produced by parsing pasted plain text as markdown carries
|
|
/// formatting or structure that ordinary plain-text paste would NOT already produce.
|
|
///
|
|
/// Returns `false` (treat as plain, let the default paste path handle it) when the content is nothing
|
|
/// but unformatted `.body` paragraphs — CommonMark collapses single-newline soft breaks and represents
|
|
/// blank-line-separated plain text as multiple plain paragraphs, and the default paste path already
|
|
/// reproduces that. Returns `true` when any block is non-paragraph, any paragraph is a heading or a list
|
|
/// item, or any run carries a non-default inline attribute (bold/italic/mono/strike/underline/spoiler/
|
|
/// formula/entity).
|
|
public func pastedMarkdownContentIsRicherThanPlain(_ content: ChatInputContent) -> Bool {
|
|
let plainAttributes = ChatInputInlineAttributes()
|
|
for block in content.blocks {
|
|
guard case let .paragraph(paragraph) = block else {
|
|
return true
|
|
}
|
|
if paragraph.style != .body || paragraph.list != nil {
|
|
return true
|
|
}
|
|
if paragraph.runs.contains(where: { $0.attributes != plainAttributes }) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|