Crates.io | dmos-cli |
lib.rs | dmos-cli |
version | 0.4.0 |
source | src |
created_at | 2024-04-11 20:20:04.84693 |
updated_at | 2024-07-19 11:39:05.568113 |
description | Djot HTML renderer with advanced features - CLI |
homepage | https://sr.ht/~bitfehler/dmos |
repository | https://git.sr.ht/~bitfehler/dmos |
max_upload_size | |
id | 1205400 |
size | 34,939 |
DMOS is a djot HTML renderer with some advanced features. DMOS is not a static site generator! But it's feature set is designed so that it can potentially be used to stitch one together with a bunch of scripting :)
Parsing and rendering basics are handled by jotdown. DMOS adds the following features:
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).
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).
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.
DMOS can render just the title of a document. This is useful, for example when
generating a full HTML page, to write the document's title to the <title>
element. Normally, the title of a document is considered to be its first
top-level heading, but this can be overridden by providing the special
dmos:title
metadata attribute (see below).
Somewhat related, DMOS can render a document without the title. Handy in case you want to render the title in some special way and then the document body separately.
DMOS considers any djot key-value attributes on headings whose key starts with
dmos:
to be metadata. These attributes are stripped during regular document
rendering, but can be output separately, making the metadata available to tools
that do not know about djot. While these attributes can be anywhere in a
document, by convention they should be attached to the first heading.
For example, given the following document:
{dmos:title="My title"}
{dmos:author="Conrad Hoffmann"}
# My title, but maybe longer
Lorem ipsum...
the metadata can be rendered as shell syntax, which can be written to a file and then sourced by any POSIX-compliant shell:
dmos_title=My\ title
dmos_author=Conrad\ Hoffmann
or it can be rendered as JSON:
{
"dmos_title": "My title",
"dmos_author": "Conrad Hoffmann"
}
While nothing prevents the use of emojis in djot documents, the language does
have the concept of symbols. It uses the :<NAME>:
syntax
popularized by Github and others, such as :+1:
for 👍. DMOS handles these
symbols and replaces them with the respective emoji, if one is found for the
given name. The available names are based on the gemoji definitions.
DMOS also adds basic skin tone support (e.g. :+1::skin-tone-5:
).
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]
Arguments:
[FILE] Read input from FILE instead of stdin
Options:
-a, --anchor <ANCHOR> Add anchors with text ANCHOR to headings
--no-sym Disable symbols processing
-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>]
-m, --meta <FMT> Output metadata attributes in given format and exit [possible values: sh, json]
-h, --help Print help
-V, --version Print version
Feel free to send questions, patches, or other feedback to my public inbox.