A Swift DSL for type-safe, extensible, and transformable HTML documents. The popular choice for rendering HTML in Swift these days is to use templating languages, but they expose your application to runtime errors and invalid HTML. Our library prevents these runtime issues at compile-time by embedding HTML directly into Swift’s powerful type system. Underneath the hood these tag functions html, body, h1, etc., are just creating and nesting instances of a Node type, which is a simple Swift enum. Because Node is just a simple Swift type, we can transform it in all kinds of interesting ways. For a silly example, what if we wanted to remove all instances of exclamation marks from our document? We even provide plug-in libraries that reduce the friction of using this library with Kitura and Vapor.
Features
- HTML documents can be created in a tree-like fashion
- Type-safe, extensible, and transformable HTML documents
- Underneath the hood these tag functions html, body, h1, etc., are just creating and nesting instances of a Node type
- Because we are embedding our DSL in Swift we can take advantage of some advanced Swift features to add an extra layer of safety
- We can strengthen many HTML APIs to force their true types rather than just relying on strings
- The core of the library is a single enum with 6 cases