Skip to content

Commit

Permalink
Try to solve #94 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkalvi authored Feb 23, 2023
1 parent 05dcfbf commit 57d9359
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
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)
)
}
}

0 comments on commit 57d9359

Please sign in to comment.