mirror of
https://github.com/GLEGram/GLEGram-iOS.git
synced 2026-04-25 12:26:55 +02:00
4647310322
Based on Swiftgram 12.5 (Telegram iOS 12.5). All GLEGram features ported and organized in GLEGram/ folder. Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass, Font Replacement, Fake Profile, Chat Export, Plugin System, and more. See CHANGELOG_12.5.md for full details.
31 lines
1.5 KiB
Swift
31 lines
1.5 KiB
Swift
import Foundation
|
|
import UIKit
|
|
import Markdown
|
|
|
|
public func addAttributesToStringWithRanges(_ stringWithRanges: (String, [(Int, NSRange)]), body: MarkdownAttributeSet, argumentAttributes: [Int: MarkdownAttributeSet], textAlignment: NSTextAlignment = .natural) -> NSAttributedString {
|
|
let result = NSMutableAttributedString()
|
|
|
|
var bodyAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: body.font, NSAttributedString.Key.foregroundColor: body.textColor, NSAttributedString.Key.paragraphStyle: paragraphStyleWithAlignment(textAlignment)]
|
|
if !body.additionalAttributes.isEmpty {
|
|
for (key, value) in body.additionalAttributes {
|
|
bodyAttributes[NSAttributedString.Key(rawValue: key)] = value
|
|
}
|
|
}
|
|
|
|
result.append(NSAttributedString(string: stringWithRanges.0, attributes: bodyAttributes))
|
|
|
|
for (index, range) in stringWithRanges.1 {
|
|
if let attributes = argumentAttributes[index] {
|
|
var argumentAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: attributes.font, NSAttributedString.Key.foregroundColor: attributes.textColor, NSAttributedString.Key.paragraphStyle: paragraphStyleWithAlignment(textAlignment)]
|
|
if !attributes.additionalAttributes.isEmpty {
|
|
for (key, value) in attributes.additionalAttributes {
|
|
argumentAttributes[NSAttributedString.Key(rawValue: key)] = value
|
|
}
|
|
}
|
|
result.addAttributes(argumentAttributes, range: range)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|