Skip to content

Commit 8c60422

Browse files
fixed attributionSrc behavior for 3 macros
1 parent 211e927 commit 8c60422

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Sources/HTMLKit/HTMLKit.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public macro custom<T: ExpressibleByStringLiteral>(tag: String, isVoid: Bool, at
5858
public macro a<T: ExpressibleByStringLiteral>(
5959
attributes: [HTMLElementAttribute] = [],
6060

61-
attributionSrc: [T]? = nil,
61+
attributionsrc: [T] = [],
6262
download: HTMLElementAttribute.Extra.download? = nil,
6363
href: T? = nil,
6464
hreflang: T? = nil,
@@ -475,7 +475,7 @@ public macro img<T: ExpressibleByStringLiteral>(
475475
attributes: [HTMLElementAttribute] = [],
476476

477477
alt: T? = nil,
478-
attributionSrc: [T]? = nil,
478+
attributionsrc: [T] = [],
479479
crossorigin: HTMLElementAttribute.Extra.crossorigin? = nil,
480480
decoding: HTMLElementAttribute.Extra.decoding? = nil,
481481
elementtiming: T? = nil,
@@ -803,7 +803,7 @@ public macro script<T: ExpressibleByStringLiteral>(
803803
attributes: [HTMLElementAttribute] = [],
804804

805805
async: Bool = false,
806-
attributionSrc: [T]? = nil,
806+
attributionsrc: [T] = [],
807807
blocking: HTMLElementAttribute.Extra.blocking? = nil,
808808
crossorigin: HTMLElementAttribute.Extra.crossorigin? = nil,
809809
defer: Bool = false,

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ private extension HTMLElement {
269269
switch returnType {
270270
case .boolean: return string.elementsEqual("true") ? key : nil
271271
case .string, .enumCase:
272-
if returnType == .enumCase && string.isEmpty {
272+
if returnType == .enumCase && string.isEmpty
273+
|| returnType == .string && key == "attributionsrc" && string.isEmpty {
273274
return key
274275
}
275276
string.escapeHTML(escapeAttributes: true)

Tests/HTMLKitTests/AttributeTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct AttributeTests {
2626
string = #div(attributes: [.ariaattribute(.controls(["testing", "123", "yup"]))])
2727
#expect(string == "<div aria-controls=\"testing 123 yup\"></div>")
2828
}
29+
@Test func attributionsrc() {
30+
var string:StaticString = #a(attributionsrc: [])
31+
#expect(string == "<a attributionsrc></a>")
32+
33+
string = #a(attributionsrc: ["https://github.com/RandomHashTags", "https://litleagues.com"])
34+
#expect(string == "<a attributionsrc=\"https://github.com/RandomHashTags https://litleagues.com\"></a>")
35+
}
2936
@Test func data() {
3037
let string:StaticString = #div(attributes: [.data("id", "5")])
3138
#expect(string == "<div data-id=\"5\"></div>")

0 commit comments

Comments
 (0)