https://github.com/thyringer/hackup
Haskell library for generating HTML.
https://github.com/thyringer/hackup
haskell html
Last synced: 11 months ago
JSON representation
Haskell library for generating HTML.
- Host: GitHub
- URL: https://github.com/thyringer/hackup
- Owner: thyringer
- License: unlicense
- Created: 2024-12-22T23:23:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T00:18:38.000Z (over 1 year ago)
- Last Synced: 2025-07-04T10:04:23.582Z (11 months ago)
- Topics: haskell, html
- Language: Haskell
- Homepage:
- Size: 1.42 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Hackup
Hackup is a Haskell library designed to generate HTML markup in a declarative and compositional style. It provides a set of combinators to construct HTML elements with attributes and nestings, and render them as HTML text.
## Features
- **Declarative HTML generation**: Using combinators such as >, <:, <<, you can build HTML tags, add attributes, and nest elements.
- **Type-safe**: The library leverages Haskell’s type system to ensure correctness when building HTML elements.
## Usage
Here is an example of how to use Hackup to generate HTML for a simple page:
```haskell
module Main (main) where
import Hackup
import Hackup.Html
import Hackup.Html.Attribute (charset', class', href', id', lang', name', rel', src')
homepageHead = head' [lang' "de"] [
meta' [charset' "utf-8"],
title' [] [put "Hauptstädte der Welt"],
link' [rel' "stylesheet", href' ".styles/main.css"],
script' [src' ".scripts/controls.js"] []
]
homepageNav = nav' [
a' [href' "http://städte-der-welt.de/index.html"] << "Hauptseite",
a' [href' "http://städte-der-welt.de/contact.html"] << "Impressum"
]
content1 = main' [] [
h1' << "Deutsche Millionenstädte",
ul' [id' "cities"] [
li' << "Berlin",
li' << "Hamburg",
li' << "Köln",
li' << "München"
]
]
homepage = doctype > html' [lang' "de"] [homepageHead, body' (div' homepageNav content1)]
main :: IO ()
main = do
print $ render homepage
```
The above example will generate the following HTML:
```html
Hauptstädte der Welt
```
## HTML Combinators
| Operator | Description |
|----------|---------------------------------------------------|
| `<:` | Add an attribute to an element. |
| `<<` | Add text content to an element. |
| `` | Nest one element inside another. |
| `>` | Merge two elements together. |
| `render` | Render the generated markup as a `Text` object. |
## License
This project is licensed under the [Unlicense](https://unlicense.org/).
You are free to use, modify, and distribute this code without restriction.