Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new alt attribute to produce alt text for images #62

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/Elementary/HtmlAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ public extension HTMLAttributeValue {
}
}

public extension HTMLAttribute where Tag == HTMLTag.img {
static func alt(_ value: String) -> Self {
HTMLAttribute(name: "alt", value: value)
}
}

public extension HTMLAttribute where Tag: HTMLTrait.Attributes.autocomplete {
static func autocomplete(_ value: HTMLAttributeValue.AutoComplete) -> Self {
HTMLAttribute(name: "autocomplete", value: value.rawValue)
Expand Down
7 changes: 7 additions & 0 deletions Tests/ElementaryTests/AttributeRenderingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ final class AttributeRenderingTests: XCTestCase {
#"<img width="100" height="200">"#
)
}

func testRendersAltForImg() async throws {
try await HTMLAssertEqual(
img(.src("/path/to/dog.jpeg"), .alt("A happy dog"), .width(200), .height(200)),
#"<img src="/path/to/dog.jpeg" alt="A happy dog" width="200" height="200">"#
)
}
}
Loading