@@ -48,8 +48,10 @@ extension HTMLKitUtilities {
4848 for e in children {
4949 if let child = e. labeled {
5050 if let key = child. label? . text {
51- if key == " encoding " {
52- context. encoding = parseEncoding ( expression: child. expression) ?? . string
51+ switch key {
52+ case " encoding " : context. encoding = parseEncoding ( expression: child. expression) ?? . string
53+ case " minify " : context. minify = child. expression. boolean ( context) ?? false
54+ default : break
5355 }
5456 } else if var c = HTMLKitUtilities . parseInnerHTML ( context: context, child: child) {
5557 if var element = c as? HTMLElement {
@@ -60,6 +62,8 @@ extension HTMLKitUtilities {
6062 }
6163 }
6264 }
65+ guard !context. minify else { return minify ( html: innerHTML) }
66+ innerHTML. replace ( HTMLKitUtilities . lineFeedPlaceholder, with: " \\ n " )
6367 return innerHTML
6468 }
6569
@@ -68,10 +72,12 @@ extension HTMLKitUtilities {
6872 let ( string, encoding) : ( String , HTMLEncoding ) = expandMacro ( context: context)
6973 return " \( raw: encodingResult ( context: context, node: context. expansion, string: string, for: encoding) ) "
7074 }
71- private static func encodingResult( context: HTMLExpansionContext , node: MacroExpansionExprSyntax , string: String , for encoding: HTMLEncoding ) -> String {
72- func bytes< T: FixedWidthInteger > ( _ bytes: [ T ] ) -> String {
73- return " [ " + bytes. map ( { " \( $0) " } ) . joined ( separator: " , " ) + " ] "
74- }
75+ private static func encodingResult(
76+ context: HTMLExpansionContext ,
77+ node: MacroExpansionExprSyntax ,
78+ string: String ,
79+ for encoding: HTMLEncoding
80+ ) -> String {
7581 switch encoding {
7682 case . utf8Bytes:
7783 guard hasNoInterpolation ( context, node, string) else { return " " }
@@ -97,6 +103,14 @@ extension HTMLKitUtilities {
97103 return encoded. replacingOccurrences ( of: " $0 " , with: string)
98104 }
99105 }
106+ private static func bytes< T: FixedWidthInteger > ( _ bytes: [ T ] ) -> String {
107+ var string : String = " [ "
108+ for b in bytes {
109+ string += " \( b) , "
110+ }
111+ string. removeLast ( )
112+ return string. isEmpty ? " [] " : string + " ] "
113+ }
100114 private static func hasNoInterpolation( _ context: HTMLExpansionContext , _ node: MacroExpansionExprSyntax , _ string: String ) -> Bool {
101115 guard string. firstRange ( of: try ! Regex ( " \\ ((.*) \\ ) " ) ) == nil else {
102116 if !context. ignoresCompilerWarnings {
@@ -323,7 +337,12 @@ extension HTMLKitUtilities {
323337 // MARK: Expand Macro
324338 static func expandMacro( context: HTMLExpansionContext ) -> ( String , HTMLEncoding ) {
325339 let data = HTMLKitUtilities . parseArguments ( context: context)
326- return ( data. innerHTML. map ( { String ( describing: $0) } ) . joined ( ) , data. encoding)
340+ var string : String = " "
341+ for v in data. innerHTML {
342+ string += String ( describing: v)
343+ }
344+ string. replace ( HTMLKitUtilities . lineFeedPlaceholder, with: " \\ n " )
345+ return ( string, data. encoding)
327346 }
328347}
329348
0 commit comments