@@ -183,8 +183,7 @@ extension HTMLKitUtilities {
183183 let interp = interpolation. removeFirst ( )
184184 let left = encodedResult [ index..< interp. range. lowerBound]
185185 values. append ( " StaticString( \( left) ) " )
186-
187- values. append ( normalizeInterpolation ( encodedResult [ interp. range] ) )
186+ values. append ( normalizeInterpolation ( encodedResult [ interp. range] , withQuotationMarks: true ) )
188187 index = interp. range. upperBound
189188
190189 reserveCapacity += left. count + 32
@@ -196,12 +195,16 @@ extension HTMLKitUtilities {
196195 }
197196 return " HTMLOptimizedLiteral(reserveCapacity: \( reserveCapacity) ).render(( \n \( values. joined ( separator: " , \n " ) ) \n )) "
198197 }
199- static func normalizeInterpolation( _ value: Substring ) -> String {
198+ static func normalizeInterpolation( _ value: Substring , withQuotationMarks : Bool ) -> String {
200199 var value = value
201200 value. removeFirst ( 22 ) // ` + String(describing: `.count
202201 value. removeLast ( 3 ) // ` + `.count
203202 value. removeAll ( where: { $0. isNewline } )
204- return String ( " \" \\ ( " + value + " \" " )
203+ if withQuotationMarks {
204+ value. insert ( " \" " , at: value. startIndex)
205+ value. append ( " \" " )
206+ }
207+ return String ( " \\ ( " + value)
205208 }
206209}
207210
@@ -231,16 +234,14 @@ extension HTMLKitUtilities {
231234 var slice = encodedResult [ range]
232235 var interpolation : String ?
233236 if let interp = interpolationMatches. first, range. contains ( interp. range. lowerBound) { // chunk contains interpolation
234- var normalized = normalizeInterpolation ( encodedResult [ interp. range] )
235- normalized. removeFirst ( )
237+ let normalized = normalizeInterpolation ( encodedResult [ interp. range] , withQuotationMarks: false )
236238 interpolation = normalized
237239 if !range. contains ( interp. range. upperBound) {
238240 endIndex = encodedResult. index ( before: interp. range. lowerBound)
239241 slice = slice [ slice. startIndex..< endIndex]
240242 i += encodedResult. distance ( from: range. upperBound, to: interp. range. upperBound)
241243 } else {
242244 interpolation = nil
243- normalized. removeLast ( )
244245 slice. remove ( at: interp. range. upperBound) // "
245246 slice. replaceSubrange ( interp. range, with: normalized)
246247 slice. remove ( at: slice. index ( before: interp. range. lowerBound) ) // "
@@ -262,9 +263,9 @@ extension HTMLKitUtilities {
262263 string += interpolation
263264 } else {
264265 string += slice
265- if let l = slice . last , let d = delimiter ( l ) {
266- string += d
267- }
266+ }
267+ if let l = slice . last , let d = delimiter ( l ) {
268+ string += d
268269 }
269270 chunks. append ( string)
270271 }
0 commit comments