diff --git a/Sources/HTMLKitMacros/HTMLElement.swift b/Sources/HTMLKitMacros/HTMLElement.swift index d317dd1..f8d3b91 100644 --- a/Sources/HTMLKitMacros/HTMLElement.swift +++ b/Sources/HTMLKitMacros/HTMLElement.swift @@ -296,7 +296,7 @@ private extension HTMLElement { let interpolation:[ExpressionSegmentSyntax] = expression.stringLiteral?.segments.compactMap({ $0.as(ExpressionSegmentSyntax.self) }) ?? [] var remaining_interpolation:Int = interpolation.count for expr in interpolation { - string = flatten_interpolation(context: context, remaining_interpolation: &remaining_interpolation, expr: expr) + string.replace("\(expr)", with: flatten_interpolation(context: context, remaining_interpolation: &remaining_interpolation, expr: expr)) } if returnType == .interpolation || remaining_interpolation > 0 { if !string.contains("\\(") { diff --git a/Tests/HTMLKitTests/HTMLKitTests.swift b/Tests/HTMLKitTests/HTMLKitTests.swift index 3aa7f00..eb87090 100644 --- a/Tests/HTMLKitTests/HTMLKitTests.swift +++ b/Tests/HTMLKitTests/HTMLKitTests.swift @@ -299,6 +299,28 @@ extension HTMLKitTests { let test:[Int] = [1] bro = #area(coords: test) }*/ + + + @Test func interpolation_flattening() { + let title:String = "flattening" + var string:String = #meta(content: "\("interpolation \(title)")", name: "description") + #expect(string == "") + + string = #meta(content: "interpolation \(title)", name: "description") + #expect(string == "") + + string = #meta(content: "interpolation\(title)", name: "description") + #expect(string == "") + + string = #meta(content: "\(title) interpolation", name: "description") + #expect(string == "") + + string = #meta(content: "\(title)interpolation", name: "description") + #expect(string == "") + + string = #meta(content: "\(title)\("interpolation")", name: "description") + #expect(string == "") + } } // MARK: Attribute tests