diff --git a/Sources/Elementary/HtmlDocument.swift b/Sources/Elementary/HtmlDocument.swift
index a28c69b..afc1684 100644
--- a/Sources/Elementary/HtmlDocument.swift
+++ b/Sources/Elementary/HtmlDocument.swift
@@ -32,6 +32,9 @@ public protocol HTMLDocument: HTML {
/// By default this attribute is not set.
var lang: String { get }
+ /// Attributes for the body tag.
+ var bodyAttributes: [HTMLAttribute] { get }
+
/// The text directionality (`ltr`, `rtl`, `auto`) of the HTML document.
///
/// By default this attribute is not set.
@@ -52,6 +55,8 @@ public extension HTMLDocument {
var lang: String { defaultUndefinedLanguage }
/// The default value for the `dir` property is an empty string and will not be rendered in the HTML.
var dir: HTMLAttributeValue.Direction { .init(value: defaultUndefinedDirection) }
+ /// The default value for the `bodyAttribute` property is an empty array.
+ var bodyAttributes: [HTMLAttribute] { [] }
}
// NOTE: this is a bit messy after the renaming of var content to var body
@@ -92,7 +97,7 @@ public extension HTMLDocument {
Elementary.title { self.title }
self.head
}
- Elementary.body { self.body }
+ Elementary.body(attributes: self.bodyAttributes) { self.body }
}
.attributes(.lang(lang), when: lang != defaultUndefinedLanguage)
.attributes(.dir(dir), when: dir.value != defaultUndefinedDirection)
diff --git a/Tests/ElementaryTests/CompositionRenderingTest.swift b/Tests/ElementaryTests/CompositionRenderingTest.swift
index 7e38301..cf5dce4 100644
--- a/Tests/ElementaryTests/CompositionRenderingTest.swift
+++ b/Tests/ElementaryTests/CompositionRenderingTest.swift
@@ -5,7 +5,7 @@ final class CompositionRenderingTests: XCTestCase {
func testRendersADocument() async throws {
try await HTMLAssertEqual(
MyPage(text: "my text"),
- #"Foo"#
+ #"Foo"#
)
}
@@ -47,6 +47,7 @@ struct MyPage: HTMLDocument {
var title = "Foo"
var lang = "en"
+ var bodyAttributes: [HTMLAttribute] = [.class("my-class"), .id("42")]
var head: some HTML {
meta(.name(.author), .content("Me"))