Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/panthevm/clj-fast-html
Clojure library designed for fast and efficient HTML generation
https://github.com/panthevm/clj-fast-html
clojure html
Last synced: 3 days ago
JSON representation
Clojure library designed for fast and efficient HTML generation
- Host: GitHub
- URL: https://github.com/panthevm/clj-fast-html
- Owner: Panthevm
- Created: 2024-06-10T20:28:10.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-06-11T18:49:23.000Z (4 months ago)
- Last Synced: 2024-09-24T19:33:24.027Z (3 days ago)
- Topics: clojure, html
- Language: Clojure
- Homepage: https://clojars.org/io.github.panthevm/clj-fast-html
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# clj-fast-html
clj-fast-html is a Clojure library designed for fast and efficient HTML generation.# Usage
You can find the latest version on Clojars:[![Clojars Project](http://clojars.org/io.github.panthevm/clj-fast-html/latest-version.svg)](https://clojars.org/io.github.panthevm/clj-fast-html)
## Example:
")]
Here is an example of how to use clj-fast-html to generate an HTML string:
``` clj
(clj-fast-html.core/to-html-string
[[:html/raw ""]
[:html
[:head
[:title "Title"]]
[:body
[:h1#id.class1.class2 "Header"]
[:p {:style {:color "red"}} "text"]
[:p {:class ["class3" "class4"]} "text"]
[:p {:class "class3 class4"} "text"]
[:dialog {:open true} "text"]
[:span {:href (clj-fast-html.core/escape "' onmouseover='alert(1)")}]
[:span (clj-fast-html.core/escape "
(mapv
(fn [x]
[:span x])
[1 2 3 4])]]])
```
``` html
Title
Header
text
text
text
text
<p onmouseover='alert(1)'></p>
1
2
3
4
```
# Benchmark
The performance of clj-fast-html is benchmarked against other popular HTML generation libraries. Below are the benchmark results for generating the [Clojure home page](https://clojure.org/)#### Single Thread
| Library | Average (ns) | % |
|------------------------|------------------|----------|
| clj-fast-html (latest) | 39434.940 ns/op | 0% |
| Hiccup (2.0.0-RC3) | 306147.614 ns/op | 676.34% |
| Hiccup (2.0.0-RC1) | 666406.325 ns/op | 1589.89% |#### Multithread
| Library | Average (μs) | % |
|------------------------|------------------|----------|
| clj-fast-html (latest) | 176.198 μs/op | 0% |
| Hiccup (2.0.0-RC3) | 1332.627 μs/op | 656.32% |
| Hiccup (2.0.0-RC1) | 2041.248 μs/op | 1058.5% |To run the benchmark yourself, use the following command:
``` bash
make bench
```