diff --git a/Sources/HTMLKitMacros/HTMLElement.swift b/Sources/HTMLKitMacros/HTMLElement.swift
index f8d3b91..7e38438 100644
--- a/Sources/HTMLKitMacros/HTMLElement.swift
+++ b/Sources/HTMLKitMacros/HTMLElement.swift
@@ -209,7 +209,7 @@ private extension HTMLElement {
switch returnType {
case .boolean: return string.elementsEqual("true") ? "" : nil
case .string, .enumCase:
- if returnType == .string && string.isEmpty {
+ if returnType == .string && string.isEmpty && key != "href" {
return nil
}
string.escapeHTML(escapeAttributes: true)
diff --git a/Tests/HTMLKitTests/HTMLKitTests.swift b/Tests/HTMLKitTests/HTMLKitTests.swift
index eb87090..7575f5a 100644
--- a/Tests/HTMLKitTests/HTMLKitTests.swift
+++ b/Tests/HTMLKitTests/HTMLKitTests.swift
@@ -95,6 +95,20 @@ extension HTMLKitTests {
string = #html(xmlns: "test")
#expect(string == "")
}
+ @Test func element_a() {
+ var string:String = #a("Test")
+ #expect(string == "Test")
+
+ string = #a(href: "test", "Test")
+ #expect(string == "Test")
+
+ string = #a(href: "", "Test")
+ #expect(string == "Test")
+
+ let test:String = "test"
+ string = #a(href: "\(test)", "Test")
+ #expect(string == "Test")
+ }
@Test func element_area() {
var string:StaticString = #area(coords: [1, 2, 3])
#expect(string == "")