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
1111import SwiftDiagnostics
1212import SwiftSyntax
1313
14+ #if canImport(SwiftLexicalLookup)
15+ import SwiftLexicalLookup
16+ #endif
17+
1418extension HTMLKitUtilities {
1519 // MARK: Escape HTML
1620 public static func escapeHTML( context: inout HTMLExpansionContext ) -> String {
@@ -289,6 +293,21 @@ extension HTMLKitUtilities {
289293 context: HTMLExpansionContext ,
290294 node: some SyntaxProtocol
291295 ) {
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*/
292311 /*if let fix:String = InterpolationLookup.find(context: context, node) {
293312 let expression:String = "\(node)"
294313 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 {
125125 remainingInterpolation -= 1
126126 values. append ( create ( fix) )
127127 } 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- //}
131128 values. append ( interpolate ( expression) )
132129 warnInterpolation ( context: context, node: expression)
133130 }
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ extension StringLiteralExprSyntax {
8484 switch encoding {
8585 case . string:
8686 value. replace ( " \n " , with: " \\ n " )
87+ value. replace ( " \" " , with: " \\ \" " )
8788 default :
8889 break
8990 }
Original file line number Diff line number Diff line change 55// Created by Evan Anderson on 11/27/24.
66//
77
8+ /*
89#if canImport(Foundation)
910import Foundation
1011
@@ -60,4 +61,4 @@ extension TranslateHTML {
6061 }
6162}
6263
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 {
1919 expected = " <!DOCTYPE html><html><p>test<></p>dude&dude bro&bro</html> "
2020 result = #html( html ( #anyRawHTML( p ( " test<> " ) , " dude&dude " ) , " bro&bro " ) )
2121 #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)
2234 }
2335}
2436
You can’t perform that action at this time.
0 commit comments