No description
Find a file
Noah Hellman e8503e28fd lib: add Render::render_{event, prologue, epilogue}
derive push/write automatically from these
2023-04-05 21:17:33 +02:00
.github/workflows ci: add fuzz html step 2023-03-17 19:01:29 +01:00
bench lib: add Render::render_{event, prologue, epilogue} 2023-04-05 21:17:33 +02:00
examples/jotdown_wasm lib: add Render::render_{event, prologue, epilogue} 2023-04-05 21:17:33 +02:00
modules test suite, suite bench: update djot.js module 2023-02-05 20:36:49 +01:00
src lib: add Render::render_{event, prologue, epilogue} 2023-04-05 21:17:33 +02:00
tests lib: add Render::render_{event, prologue, epilogue} 2023-04-05 21:17:33 +02:00
.gitmodules modules/djot.js: ssh -> https 2023-02-13 18:13:48 +01:00
Cargo.lock add iai benchmarks 2023-02-14 21:51:23 +01:00
Cargo.toml add iai benchmarks 2023-02-14 21:51:23 +01:00
CHANGELOG.md changelog: fix release link 2023-03-18 15:09:59 +01:00
COPYING add MIT license 2023-02-05 20:41:59 +01:00
Makefile make: nonzero exit when afl_quick detects crashes 2023-04-05 21:17:33 +02:00
README.md readme: describe running benchmarks 2023-02-14 21:51:23 +01:00

Jotdown

Jotdown is a pull parser Rust library for the Djot markup language. It parses a Djot document into a sequence of events and may also render the events to HTML.

Jotdown aims to be fast and efficient, using a minimal number of allocations. The API should use idiomatic Rust and be easy to use and flexible. The event interface allows clients to e.g. construct an AST or generate any type of output format. It also allows one to perform filters on the document before generating the output. Jotdown aims to be feature complete and match the syntax reference and the reference implementation in terms of output.

Another goal is to keep the implementation minimal and build times low. The current implementation has zero dependencies, if major non-essential features are added or larger dependencies are utilized, these should be optional using feature flags.

Jotdown supports Rust edition 2021, i.e. Rust 1.56 and above.

Usage

Jotdown is primarily a parsing library but also has a minimal CLI implementation and a simple online demo version.

Library

The Jotdown API is inspired by pulldown-cmark and is overall very similar. The Jotdown crate contains in-source documentation, a rendered version is available at https://docs.rs/jotdown.

While Jotdown is usable, it is still in early development and breaking changes to the API may occur frequently. The Djot syntax is also in quite early stages and may also change significantly.

CLI

The Jotdown crate contains a minimal implementation of a CLI that simply reads from standard input and writes HTML to standard output. It can be built from this repository and run locally with cargo:

$ cargo build --release
$ echo "hello world" | ./target/release/djot
<p>hello world</p>

Alternatively, it can be installed from the crates.io repository using simply:

$ cargo install jotdown

It will be placed in ~/.cargo/bin/jotdown.

Web demo

A version of Jotdown compiled to WebAssembly and runnable in a web browser is available at https://hllmn.net/projects/jotdown/demo. It can also be run locally:

$ cd examples/jotdown_wasm
$ make run

You may need to install wasm-pack and make sure your Rust compiler has the WebAssembly backend.

Status

Correctness

As of writing, Jotdown implements all the current features of the Djot syntax, including:

  • links, images, either inline or with reference link definitions,
  • autolinks,
  • inline typesetting
    • emphasis,
    • highlight,
    • super/subscript,
    • insert/delete,
    • smart punctuation,
  • inline verbatim, code and code blocks,
  • math,
  • line breaks,
  • comments,
  • symbols,
  • headings, including hierarchical sections, and automatic links
  • block quotes,
  • lists,
    • unordered,
    • ordered,
    • task,
    • definitions,
  • raw inline and blocks,
  • thematic breaks,
  • pipe tables,
  • attributes, on inline and block elements,
  • inline spans and div blocks,
  • footnotes.

The HTML output is in some cases not exactly identical to the reference implementation. There are two test suites that compares Jotdown with the reference implementation. One uses the unit tests of the reference implementation and runs them with Jotdown. It can be run with:

$ make suite

Another target uses the reference implementation to generate html output for its benchmark files and compares it to the output of Jotdown:

$ make suite_bench

Note that it requires node in order to run the reference implementation.

Performance

There are benchmarks available to measure the performance. The input files are borrowed from the reference implementation. To fetch the input files symlink them to the bench directory, run:

make bench

There are two separate benchmarks suites that can be run; criterion and iai. Criterion measures statistical real-time performance while iai measures exact number of executed instructions and memory accesses. To run the criterion benchmarks, use

cargo bench -p bench-crit [filter]

Alternatively, if cargo-criterion is installed:

cargo criterion -p bench-crit -- [filter]

To run the iai benchmarks, use

cargo bench -p bench-iai