Add a V2 version of the AttributedStringBuilder as a verbatim copy of the original one (for now)

This commit is contained in:
Stefan Ceriu
2025-08-21 13:14:47 +03:00
committed by Doug
parent 5738b08a94
commit 754c2f0fed
5 changed files with 428 additions and 14 deletions
@@ -20,6 +20,19 @@ protocol MentionBuilderProtocol {
func handleAllUsersMention(for attributedString: NSMutableAttributedString, in range: NSRange)
}
extension NSAttributedString.Key {
static let DTTextBlocks: NSAttributedString.Key = .init(rawValue: DTTextBlocksAttribute)
static let MatrixBlockquote: NSAttributedString.Key = .init(rawValue: BlockquoteAttribute.name)
static let MatrixUserID: NSAttributedString.Key = .init(rawValue: UserIDAttribute.name)
static let MatrixUserDisplayName: NSAttributedString.Key = .init(rawValue: UserDisplayNameAttribute.name)
static let MatrixRoomDisplayName: NSAttributedString.Key = .init(rawValue: RoomDisplayNameAttribute.name)
static let MatrixRoomID: NSAttributedString.Key = .init(rawValue: RoomIDAttribute.name)
static let MatrixRoomAlias: NSAttributedString.Key = .init(rawValue: RoomAliasAttribute.name)
static let MatrixEventOnRoomID: NSAttributedString.Key = .init(rawValue: EventOnRoomIDAttribute.name)
static let MatrixEventOnRoomAlias: NSAttributedString.Key = .init(rawValue: EventOnRoomAliasAttribute.name)
static let MatrixAllUsersMention: NSAttributedString.Key = .init(rawValue: AllUsersMentionAttribute.name)
}
struct AttributedStringBuilder: AttributedStringBuilderProtocol {
private static let defaultKey = "default"
@@ -32,7 +45,11 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
}
init(cacheKey: String = defaultKey, mentionBuilder: MentionBuilderProtocol) {
builder = AttributedStringBuilderV1(cacheKey: cacheKey, mentionBuilder: mentionBuilder)
if Self.useNextGenHTMLParser {
builder = AttributedStringBuilderV2(cacheKey: cacheKey, mentionBuilder: mentionBuilder)
} else {
builder = AttributedStringBuilderV1(cacheKey: cacheKey, mentionBuilder: mentionBuilder)
}
}
func fromPlain(_ string: String?) -> AttributedString? {