A fast Djot parser and formatter for Elixir.
Djot parsing and transformations powered by the jotdown rust crate.
Simply call to_html
on a string that contains Djot data, and you'll get back a html fragment.
Djot.to_html("hello *world*!")
# => {:ok, "<p>hello <strong>world</strong>!</p>\n"}
If you want to write Djot contents inline in an Elixir program, you can use the provided sigil
import Djot.Sigil
~d"""
This is a Djot document. \
It will be compiled to HTML automatically, at compile time!
Here's some display math, thank you djot!
$$`
\frac{-b \pm \sqrt{b^2 - 4 a c}}{2 a}
`
"""
# => "<p>This is a Djot document. <br>\nIt will be compiled to HTML automatically, at compile time!</p>\n<p><span class=\"math display\">\\[\n\\frac{-b \\pm \\sqrt{b^2 - 4 a c}}{2 a}\n\\]</span></p>\n"
This can be useful when paired with tools such as the Tableau SSG
The Djot renderer accepts a few options:
Option | Values | Description |
---|---|---|
renderer |
:default , :minified , :indented |
Which particular output renderer to use |
indent_string |
String | String which is used to indent lines when using the :indented renderer |
indent_initial_level |
Integer | How deep the initial indent starts at |
These are passed to the Djot.to_html
calls as follows:
Djot.to_html(document, renderer: :indented, indent_string: " ", initial_indent_level: 1)
If you are using the bang variant of to_html/2
, substitute it where appropriate
Add :djot
as a dependency:
def deps do
[
{:djot, "~> 0.1.0"}
]