We have great packages for embedding julia code into markdown documents, and render HTML using Weave.jl or Literate.jl.
However, sometimes I’ll like to generate an HTML-file from inside a julia-script rather than using one the templating packages. Something similar to what the hwriter R-package does.
The following works, but it is somewhat low-level:
julia> open("/tmp/index.html", "w") do io
show(io, "text/html", html"""<!DOCTYPE html><HTML lang = "en"><HEAD><meta charset="UTF-8"/></HEAD><BODY>""")
show(io, "text/html", html"<h1>My title</h1>")
show(io, "text/html", html"Some text.")
show(io, "text/html", html"</BODY></HTML>")
end
Is there already a package to help make this more ergonomic?
Thanks for the link to HypertextLiteral@dpsanders .
I did not know of that, and it is definitely relevant for this usecase.
It appears to be mainly focused on improving on the @html_str string macro from base Julia.
I’m looking for something to reduce the amount of “boiler-plate” I need to type to generate an HTML-document, and as far as I can see, that is not the goal of HypertextLiteral.
Thanks @mike. Both Hiccup and Hyperscript look like they can help me write HTML in a simple way.
The READMEs don’t show how to generate a full HTML document and write it to a file, so I’ll take a look at the source, and see if I can generate a simple example.
Thanks for sharing! Have you considered submitting those two examples to the respective READMEs? It would be a great help to others with the same question.