Djot HTML renderer with advanced features
27 days ago

David Arnold via public-inbox

30 days ago

#DMOS - Djot Much Output Schnutification

Crates.io builds.sr.ht status Documentation

DMOS is a Djot HTML renderer with some advanced features. Parsing and rendering basics are handled by jotdown. DMOS adds the following features:

#Syntax highlighting

DMOS will automatically attempt to add CSS-class-based syntax highlighting to all fenced code blocks with a language specifier. The default highlighter is syntect, which means it is small and fast, but also line-based (which is not an issue for the vast majority of code snippets).

For the adventurous, an alternative highlighter based on inkjet/tree-sitter is also available. Tree-sitter is quite sophisticated, but the executable size will be huge (see their README).

#Table of contents

DMOS can generate a table of contents for a document. The table's prologue and epilogue are customizable, meaning it can be embedded into the document with arbitrary elements (<section>, <div>, <details>, ...).

There is also an option to exclude the document title from the table of contents. If enabled, DMOS will also emit the table of contents after the title (providing a more natural document structure: title, TOC, content).

#Section anchors

DMOS can add section anchors to headings linking to themselves. These anchors are a common technique to allow readers to easily get the link to a specific section. They are usually styled with CSS to only appear when hovering over the heading. If you are viewing the HTML rendering of this document on sr.ht you can see a similar mechanism in action by hovering the mouse over any section heading.


The dmos crate is a library, dmos-cli is a thin CLI wrapper around it.

For usage of the library, see the crate documentation.

For usage of the CLI:

Usage: dmos [OPTIONS] [FILE]

  [FILE]  Read input from FILE instead of stdin

  -a, --anchor <ANCHOR>      Add anchors with text ANCHOR to headings
  -t, --title-only           Output first first-level heading and exit
      --toc                  Generate document with table of contents
  -T, --toc-only             Output table of contents and exit
      --toc-skip-title       Skip title (first heading) in table of contents
      --toc-prologue <HTML>  Prologue to the table of content listing [default: "<section class=\"toc\"><h3>Table of Contents</h3>"]
      --toc-epilogue <HTML>  Epilogue to the table of content listing [default: </section>]
  -h, --help                 Print help
  -V, --version              Print version


Feel free to send questions, patches, or other feedback to my public inbox.