HTMLBuilder.jl: Building HTML the Julia way
HTMLBuilder.jl is a package for handling HTML in idiomatic Julia. Currently, it can:
- Generate HTML code.
- Parse HTML code.
- Build a site with multiple pages.
All the HTML elements are treated as Julia structs, so you can easily generate HTML programmatically. For instance, we can list the first N Fibonacci numbers. First we import HTMLBuilder.jl and define the Fibonacci function, as well as N=5:
julia> using HTMLBuilderjulia> Fibonacci(n::Int) = (n <= 2) ? (1) : (Fibonacci(n - 1) + Fibonacci(n - 2));julia> N = 5;
Then, we can construct the list by nesting HTML elements and using a for loop:
julia> body( h1("The Fibonacci numbers"), p("Here are the first $N Fibonacci numbers:"), ul([li(string(Fibonacci(n))) for n ∈ 1:N]), )<body> <h1>The Fibonacci numbers</h1> <p>Here are the first 5 Fibonacci numbers:</p> <ul> <li> 1 </li> <li> 1 </li> <li> 2 </li> <li> 3 </li> <li> 5 </li> </ul> </body>
HTMLBuilder.jl can be used to build and manage a complex site through the @build_site macro. The example directory contains a site directory populated with Julia code. The @build_site macro parses these files and generates dist, a complete HTML site. For more details, see the documentation.
Bug reports, feature requests, and contributions
Please see the contribution guidelines.