Skip to content

Commit

Permalink
Add DocumentMain. (#186)
Browse files Browse the repository at this point in the history
Part of #25.
  • Loading branch information
jverkoey authored Sep 14, 2024
1 parent dcc9ba9 commit 8227be1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips
[`<body>`](https://html.spec.whatwg.org/multipage/sections.html#the-body-element) | ``Body``
[`<article>`](https://html.spec.whatwg.org/multipage/sections.html#the-article-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<section>`](https://html.spec.whatwg.org/multipage/sections.html#the-section-element) | ``Section``
[`<nav>`](https://html.spec.whatwg.org/multipage/sections.html#the-nav-element) | ``Navigation``
[`<nav>`](https://html.spec.whatwg.org/multipage/sections.html#the-nav-element) | ``Navigation``
[`<aside>`](https://html.spec.whatwg.org/multipage/sections.html#the-aside-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<h1>`](https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements) | ``H1`` or ``Heading``
[`<h2>`](https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements) | ``H2`` or ``Heading``
Expand Down Expand Up @@ -96,7 +96,7 @@ provided below is an organized table of W3C HTML tags and their equivalent Slips
[`<dd>`](https://html.spec.whatwg.org/multipage/sections.html#the-dd-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<figure>`](https://html.spec.whatwg.org/multipage/sections.html#the-figure-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<figcaption>`](https://html.spec.whatwg.org/multipage/sections.html#the-figcaption-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<main>`](https://html.spec.whatwg.org/multipage/sections.html#the-main-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<main>`](https://html.spec.whatwg.org/multipage/sections.html#the-main-element) | ``DocumentMain``
[`<search>`](https://html.spec.whatwg.org/multipage/sections.html#the-search-element) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/25)
[`<div>`](https://html.spec.whatwg.org/multipage/sections.html#the-div-element) | ``Div``

Expand Down
1 change: 1 addition & 0 deletions Sources/Slipstream/Documentation.docc/W3C/W3CViews.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh
- ``Blockquote``
- ``List``
- ``ListItem``
- ``DocumentMain``
- ``Div``

### Text-level semantics
Expand Down
28 changes: 28 additions & 0 deletions Sources/Slipstream/W3C/Elements/GroupingContent/DocumentMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// A view that represents the dominant contents of the document.
///
/// ```swift
/// struct MySiteContent: View {
/// var body: some View {
/// Body {
/// Main {
/// Text("Hello, world!")
/// }
/// }
/// }
/// }
/// ```
///
/// - SeeAlso: W3C [main](https://html.spec.whatwg.org/multipage/grouping-content.html#hierarchically-correct-main-element) specification.
@available(iOS 17.0, macOS 14.0, *)
public struct DocumentMain<Content>: W3CElement where Content: View {
@_documentation(visibility: private)
public let tagName: String = "main"

@_documentation(visibility: private)
@ViewBuilder public let content: () -> Content

/// Creates a DocumentMain view.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/DocumentMainTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct DocumentMainTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(DocumentMain {}) == "<main></main>")
}

@Test func withText() throws {
try #expect(renderHTML(DocumentMain {
DOMString("Hello, world!")
}) == """
<main>
Hello, world!
</main>
""")
}
}

0 comments on commit 8227be1

Please sign in to comment.