diff --git a/Sources/Slipstream/Documentation.docc/Views/W3C/W3CViews.md b/Sources/Slipstream/Documentation.docc/Views/W3C/W3CViews.md index 69ae14d..29ba11f 100644 --- a/Sources/Slipstream/Documentation.docc/Views/W3C/W3CViews.md +++ b/Sources/Slipstream/Documentation.docc/Views/W3C/W3CViews.md @@ -32,3 +32,7 @@ The complete W3C HTML elements standard can be found [here](https://html.spec.wh ### Grouping content - ``Div`` + +### Text-level semantics + +- ``Linebreak`` diff --git a/Sources/Slipstream/W3C/Elements/TextLevelSemantics/LineBreak.swift b/Sources/Slipstream/W3C/Elements/TextLevelSemantics/LineBreak.swift new file mode 100644 index 0000000..428280f --- /dev/null +++ b/Sources/Slipstream/W3C/Elements/TextLevelSemantics/LineBreak.swift @@ -0,0 +1,26 @@ +import SwiftSoup + +/// A view that represents a line break. +/// +/// ```swift +/// struct MySiteContent: View { +/// var body: some View { +/// Text("Hello") +/// Linebreak() +/// Text("world!") +/// } +/// } +/// ``` +/// +/// - SeeAlso: W3C [`br`](https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-br-element) specification. +@available(iOS 17.0, macOS 14.0, *) +public struct Linebreak: View { + /// Creates a Linebreak view. + public init() { + } + + @_documentation(visibility: private) + public func render(_ container: Element, environment: EnvironmentValues) throws { + _ = try container.appendElement("br") + } +} diff --git a/Tests/SlipstreamTests/Sites/CatalogSiteTests.swift b/Tests/SlipstreamTests/Sites/CatalogSiteTests.swift index d14c73b..b305d12 100644 --- a/Tests/SlipstreamTests/Sites/CatalogSiteTests.swift +++ b/Tests/SlipstreamTests/Sites/CatalogSiteTests.swift @@ -16,7 +16,9 @@ private struct CatalogSite: View { } Body { Container { - Text("Hello, world!") + Text("Hello") + Linebreak() + Text("world!") H1("Heading 1") H2 { Text("Heading 2") @@ -45,7 +47,8 @@ struct CatalogSiteTests {
- Hello, world! + Hello +
world!

Heading 1

Heading 2

Heading 3

diff --git a/Tests/SlipstreamTests/Views/W3C/LinebreakTests.swift b/Tests/SlipstreamTests/Views/W3C/LinebreakTests.swift new file mode 100644 index 0000000..f43b085 --- /dev/null +++ b/Tests/SlipstreamTests/Views/W3C/LinebreakTests.swift @@ -0,0 +1,9 @@ +import Testing + +import Slipstream + +struct LinebreakTests { + @Test func render() throws { + try #expect(renderHTML(Linebreak()) == "
") + } +}