File tree Expand file tree Collapse file tree 6 files changed +55
-4
lines changed Expand file tree Collapse file tree 6 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ import HTMLKitUtilities
11
11
import SwiftDiagnostics
12
12
import SwiftSyntax
13
13
14
+ #if canImport(SwiftLexicalLookup)
15
+ import SwiftLexicalLookup
16
+ #endif
17
+
14
18
extension HTMLKitUtilities {
15
19
// MARK: Escape HTML
16
20
public static func escapeHTML( context: inout HTMLExpansionContext ) -> String {
@@ -289,6 +293,21 @@ extension HTMLKitUtilities {
289
293
context: HTMLExpansionContext ,
290
294
node: some SyntaxProtocol
291
295
) {
296
+ /*#if canImport(SwiftLexicalLookup)
297
+ for t in node.tokens(viewMode: .fixedUp) {
298
+ let results = node.lookup(t.identifier)
299
+ for result in results {
300
+ switch result {
301
+ case .lookForMembers(let test):
302
+ print("lookForMembers=" + test.debugDescription)
303
+ case .lookForImplicitClosureParameters(let test):
304
+ print("lookForImplicitClosureParameters=" + test.debugDescription)
305
+ default:
306
+ print(result.debugDescription)
307
+ }
308
+ }
309
+ }
310
+ #endif*/
292
311
/*if let fix:String = InterpolationLookup.find(context: context, node) {
293
312
let expression:String = "\(node)"
294
313
let ranges:[Range<String.Index>] = string.ranges(of: expression)
Original file line number Diff line number Diff line change @@ -125,9 +125,6 @@ extension HTMLKitUtilities {
125
125
remainingInterpolation -= 1
126
126
values. append ( create ( fix) )
127
127
} else {
128
- //if let decl:DeclReferenceExprSyntax = expression.declRef {
129
- // TODO: lookup and try to promote | need to wait for swift-syntax to update to access SwiftLexicalLookup
130
- //}
131
128
values. append ( interpolate ( expression) )
132
129
warnInterpolation ( context: context, node: expression)
133
130
}
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ extension StringLiteralExprSyntax {
84
84
switch encoding {
85
85
case . string:
86
86
value. replace ( " \n " , with: " \\ n " )
87
+ value. replace ( " \" " , with: " \\ \" " )
87
88
default :
88
89
break
89
90
}
Original file line number Diff line number Diff line change 5
5
// Created by Evan Anderson on 11/27/24.
6
6
//
7
7
8
+ /*
8
9
#if canImport(Foundation)
9
10
import Foundation
10
11
@@ -60,4 +61,4 @@ extension TranslateHTML {
60
61
}
61
62
}
62
63
63
- #endif
64
+ #endif*/
Original file line number Diff line number Diff line change
1
+ //
2
+ // LexicalLookupTests.swift
3
+ //
4
+ //
5
+ // Created by Evan Anderson on 3/30/25.
6
+ //
7
+
8
+ #if compiler(>=6.0)
9
+
10
+ import Testing
11
+ import HTMLKit
12
+
13
+ struct LexicalLookupTests {
14
+ @Test
15
+ func lexicalLookup( ) {
16
+ let placeholder : String = #html( p ( " gottem " ) )
17
+ let value : String = #html( html ( placeholder) )
18
+ }
19
+ }
20
+
21
+ #endif
Original file line number Diff line number Diff line change @@ -19,6 +19,18 @@ struct RawHTMLTests {
19
19
expected = " <!DOCTYPE html><html><p>test<></p>dude&dude bro&bro</html> "
20
20
result = #html( html ( #anyRawHTML( p ( " test<> " ) , " dude&dude " ) , " bro&bro " ) )
21
21
#expect( expected == result)
22
+
23
+ expected = " <svg xmlns= \" http://www.w3.org/2000/svg \" width= \" 16 \" height= \" 16 \" viewBox= \" 0 0 24 24 \" fill= \" none \" stroke= \" currentColor \" stroke-width= \" 2 \" stroke-linecap= \" round \" stroke-linejoin= \" round \" class= \" lucide lucide-eye-icon \" > \n <path d= \" M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0 \" ></path> \n <circle cx= \" 12 \" cy= \" 12 \" r= \" 3 \" ></circle></svg><!--]--></a><a href= \" about:blank# \" class= \" hover:underline tooltip \" title= \" Delete \" ><svg xmlns= \" http://www.w3.org/2000/svg \" width= \" 16 \" height= \" 16 \" viewBox= \" 0 0 24 24 \" fill= \" none \" stroke= \" currentColor \" stroke-width= \" 2 \" stroke-linecap= \" round \" stroke-linejoin= \" round \" class= \" lucide lucide-trash-icon \" > \n <path d= \" M3 6h18 \" ></path> \n <path d= \" M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6 \" ></path> \n <path d= \" M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2 \" ></path></svg> "
24
+ result = #rawHTML( #"""
25
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-eye-icon">
26
+ <path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"></path>
27
+ <circle cx="12" cy="12" r="3"></circle></svg><!--]--></a><a href="about:blank#" class="hover:underline tooltip" title="Delete"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-trash-icon">
28
+ <path d="M3 6h18"></path>
29
+ <path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path>
30
+ <path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path></svg>
31
+ """#
32
+ )
33
+ #expect( expected == result)
22
34
}
23
35
}
24
36
You can’t perform that action at this time.
0 commit comments