Skip to content

Commit d66f5b1

Browse files
update README; fixed doctype element not being present
1 parent 46eb7bb commit d66f5b1

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Write HTML using Swift Macros.
22

33
## Why Use?
4-
- Swift Macros are powerful and offer performance benefits to alternative libraries relying on runtime performance
4+
- Swift Macros are powerful and offer performance benefits to alternative libraries relying on runtime performance (middleware, rendering, result builders, etc)
55
- Alternative libraries may not fit all situations and may restrict how the html is generated or manipulated, or is prone to html errors (by human error or otherwise)
66
- HTML macros enforces safety by default, can be used anywhere, and compile directly to strings which can be easily manipulated
77
- The compiled output is valid, minified html
@@ -14,7 +14,7 @@ Write HTML using Swift Macros.
1414
### Example
1515
This html is compiled by following code
1616
```html
17-
<html><body><div class="dark mode" title="Hover over message" draggable="false" inputmode="email" hidden="hidden">Unconstrained text<div></div><a><div><abbr></abbr></div></a><div></div><button disabled></button><video autoplay preload="auto" src="ezclap" width="5"></video></div></body></html>
17+
<!DOCTYPE html><html><body><div class="dark mode" title="Hover over message" draggable="false" inputmode="email" hidden="hidden">Unconstrained text<div></div><a><div><abbr></abbr></div></a><div></div><button disabled></button><video autoplay preload="auto" src="ezclap" width="5"></video></div></body></html>
1818
```
1919
```swift
2020
let test:String = #html(innerHTML: [

Sources/HTMLKitMacros/HTMLElement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ struct HTMLElement : ExpressionMacro {
164164
}
165165
let attributes_string:String = attributes.isEmpty ? "" : " " + attributes.joined(separator: " ")
166166
let extra_attributes_string:String = extra_attributes.isEmpty ? "" : " " + extra_attributes.joined(separator: " ")
167-
var string:String = "\"<" + type.rawValue + attributes_string + extra_attributes_string + ">"
167+
var string:String = (type == .html ? "\"<!DOCTYPE html>" : "\"") + "<" + type.rawValue + attributes_string + extra_attributes_string + ">"
168168
if !items.isEmpty {
169169
string += "\""
170170
}

Tests/HTMLKitTests/HTMLKitTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,27 @@ import XCTest
1010

1111
final class HTMLKitTests : XCTestCase {
1212
func testExample() throws {
13+
let test:String = #html(innerHTML: [
14+
#body(innerHTML: [
15+
#div(
16+
attributes: [
17+
.class(["bing", "bong"]),
18+
.title("just seeing what blow's"),
19+
.draggable(.false),
20+
.inputMode(.email),
21+
.hidden(.hidden)
22+
],
23+
innerHTML: [
24+
"poggies",
25+
#div(),
26+
#a(innerHTML: [#div(innerHTML: [#abbr()]), #address()]),
27+
#div(),
28+
#button(disabled: true),
29+
#video(autoplay: true, controls: false, height: nil, preload: .auto, src: "ezclap", width: 5),
30+
]
31+
)
32+
])
33+
])
34+
print("test=" + test)
1335
}
1436
}

0 commit comments

Comments
 (0)