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

Add Blockquote element. #96

Merged
merged 1 commit into from
Aug 6, 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
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 @@ -35,6 +35,7 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh

- ``Paragraph``
- ``Divider``
- ``Blockquote``
- ``Div``

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

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

/// Creates a blockquote.
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}

/// Creates a blockquote with some static text.
public init(_ text: String) where Content == Text {
self.content = {
Text(text)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct Paragraph<Content>: W3CElement where Content: View {
self.content = content
}

/// Creates an paragraph with some static text.
/// Creates a paragraph with some static text.
public init(_ text: String) where Content == Text {
self.content = {
Text(text)
Expand Down
19 changes: 19 additions & 0 deletions Tests/SlipstreamTests/W3C/BlockquoteTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Testing

import Slipstream

struct BlockquoteTests {
@Test func emptyBlock() throws {
try #expect(renderHTML(Blockquote {}) == "<blockquote></blockquote>")
}

@Test func withText() throws {
try #expect(renderHTML(Blockquote {
Text("Hello, world!")
}) == """
<blockquote>
Hello, world!
</blockquote>
""")
}
}