             }
         }
 
-        let mutableStringParts = parts.flatMap {
+        let optimizedStringParts = parts.flatMap {
             resolveAttributes(part: $0, inheritedAttributes: localProperties, parentElements: [])
-        }
+        }.reduce([]) { current, stringPart in
+            // getting rid of quotes at the beginning and end because `TransformedText` encloses its output with them
+            let startIndex = stringPart.text.index(after: stringPart.text.startIndex)
+            let endIndex = stringPart.text.index(before: stringPart.text.endIndex)
+            let trimmedStringPart = (text: String(stringPart.text[startIndex..<endIndex]), attributes: stringPart.attributes)
+            guard let lastStringPart = current.last, lastStringPart.attributes == stringPart.attributes else {
+                return current.arrayByAppending(trimmedStringPart)
+            }
+            var mutableCurrent = current
+            mutableCurrent[mutableCurrent.endIndex - 1] = (text: lastStringPart.text + trimmedStringPart.text, attributes: lastStringPart.attributes)
+            return mutableCurrent
+        } as [(text: String, attributes: String)]
 
         return """
         {
             let s = NSMutableAttributedString()
-            \(mutableStringParts.map { "s.append(\($0))" }.joined(separator: "\n"))
+            \(optimizedStringParts.map { "s.append(\"\($0.text)\".attributed(\($0.attributes)))" }.joined(separator: "\n"))
             return s
         }()
         """

    }

    public func generate(context: SupportedPropertyTypeContext) -> String {
        func resolveAttributes(part: AttributedText.Part, inheritedAttributes: [Property], parentElements: [String]) -> [String] {
            switch part {
            case .transform(let transformedText):
                let generatedAttributes = inheritedAttributes.map {

                    style.map { context.resolvedStyleName(named: $0) + ".\(elementName)" }
                }
                let attributesString = (generatedParentStyles + ["[\(generatedAttributes)]"]).joined(separator: " + ")
                return [(generatedTransformedText, attributesString)]
            case .attributed(let attributedStyle, let attributedTexts):
                // the order of appending is important because the `distinct(where:)` keeps the first element of the duplicates
                let lowerAttributes = attributedStyle.properties
