Skip to content

Commit 46eb7bb

Browse files
Create README.md
1 parent 8a138af commit 46eb7bb

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Write HTML using Swift Macros.
2+
3+
## Why Use?
4+
- Swift Macros are powerful and offer performance benefits to alternative libraries relying on runtime performance
5+
- 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)
6+
- HTML macros enforces safety by default, can be used anywhere, and compile directly to strings which can be easily manipulated
7+
- The compiled output is valid, minified html
8+
## Syntax
9+
- prepend the html element you want with the macro delimiter (`#<html element name>()`)
10+
- create `html` element: `#html(innerHTML: [])`
11+
- create `body` element: `#body()`
12+
- create `div` element: `#div()`
13+
- create `div` element with "dark" and "mode" classes: `#div(attributes: [.class(["dark", "mode"])])`
14+
### Example
15+
This html is compiled by following code
16+
```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>
18+
```
19+
```swift
20+
let test:String = #html(innerHTML: [
21+
#body(innerHTML: [
22+
#div(
23+
attributes: [
24+
.class(["dark", "mode"]),
25+
.title("Hover over message"),
26+
.draggable(.false),
27+
.inputMode(.email),
28+
.hidden(.hidden)
29+
],
30+
innerHTML: [
31+
"Unconstrained text",
32+
#div(),
33+
#a(innerHTML: [#div(innerHTML: [#abbr()])]),
34+
#div(),
35+
#button(disabled: true),
36+
#video(autoplay: true, controls: false, height: nil, preload: .auto, src: "ezclap", width: 5),
37+
]
38+
)
39+
])
40+
])
41+
```

0 commit comments

Comments
 (0)