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

Try to solve https://github.com/pointfreeco/swift-html/issues/94 #95

Merged
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
22 changes: 22 additions & 0 deletions Html.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ render(unexclaim(document))
)
)

// Based on https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
let dl_exmaple_with_div: Node = .dl(
.div(
.dt("Last modified time"),
.dd("2004-12-23T23:33Z")
),
.div(
.dt("Recommended update interval"),
.dd("60s")
),
.div(
.dt("Authors"),
.dt("Editors"),
.dd("Robert Rothman"),
.dd("Daniel Jackson")
)
)

render(dl_exmaple_with_div)



/// A function that "redacts" an HTML document by transforming all text nodes
/// into █-sequences of characters.
func redacted(node: Node) -> Node {
Expand Down
2 changes: 1 addition & 1 deletion Html.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' executeOnSourceChanges='false'>
<playground version='5.0' target-platform='macos'>
<timeline fileName='timeline.xctimeline'/>
</playground>
12 changes: 12 additions & 0 deletions Sources/Html/ChildOf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ extension ChildOf where Element == Tag.Dl {
}
}

// https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element
extension ChildOf where Element == Tag.Dl {
/// The `<div>` element wraps a group, that is part of a term-description group in a description list (`<dl>` element).
///
/// - Parameters:
/// - attributes: Attributes.
/// - content: Child nodes (`<dl>` or `dd` elements).
public static func div(attributes: [Attribute<Tag.Div>] = [], _ content: ChildOf<Tag.Dl>...) -> ChildOf {
return .init(.element("div", attributes: attributes, ChildOf.fragment(content).rawValue))
}
}

extension ChildOf where Element == Tag.Fieldset {
/// The `<legend>` element represents a caption for the rest of the contents of the `<legend>` element's parent `<fieldset>` element, if any.
///
Expand Down
26 changes: 26 additions & 0 deletions Tests/HtmlTests/ElementsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,30 @@ final class ElementsTests: XCTestCase {
)
)
}

func testDlwithDiv() {
let dl_exmaple_with_div: Node = .dl(
.div(
.dt("Last modified time"),
.dd("2004-12-23T23:33Z")
),
.div(
.dt("Recommended update interval"),
.dd("60s")
),
.div(
.dt("Authors"),
.dt("Editors"),
.dd("Robert Rothman"),
.dd("Daniel Jackson")
)
)

XCTAssertEqual(
"""
<dl><div><dt>Last modified time</dt><dd>2004-12-23T23:33Z</dd></div><div><dt>Recommended update interval</dt><dd>60s</dd></div><div><dt>Authors</dt><dt>Editors</dt><dd>Robert Rothman</dd><dd>Daniel Jackson</dd></div></dl>
""",
render(dl_exmaple_with_div)
)
}
}