| LOWDOWN(3) | Library Functions Manual | LOWDOWN(3) |
lowdown — simple
markdown translator library
library “liblowdown”
#include
<sys/queue.h>
#include <stdio.h>
#include <lowdown.h>
struct lowdown_meta
struct lowdown_node
struct lowdown_opts
This library parses lowdown(5) into various output formats.
The library consists first of a high-level interface consisting of lowdown_buf(3), lowdown_buf_diff(3), lowdown_file(3), and lowdown_file_diff(3).
The high-level functions interface with low-level functions that perform parsing and formatting. These consist of lowdown_doc_new(3), lowdown_doc_parse(3), and lowdown_doc_free(3) for parsing lowdown(5) documents into an abstract syntax tree.
The front-end functions for freeing, allocation, and rendering are as follows.
To compile and link, use pkg-config(1):
% cc `pkg-config --cflags lowdown` -c -o sample.o sample.c % cc -o sample sample.o `pkg-config --libs lowdown`
The lowdown library is built to operate in
security-sensitive environments, such as those using
pledge(2) on OpenBSD. The only
promise required is stdio for
lowdown_file_diff(3) and
lowdown_file(3): both require access to the stream for
reading input.
All lowdown functions use one or more of
the following structures.
The main structure for configuring parsing and output is struct lowdown_opts. It has the following fields:
LOWDOWN_HTMLLOWDOWN_LATEXLOWDOWN_MAN-man macrosLOWDOWN_FODTLOWDOWN_TERMLOWDOWN_GEMINILOWDOWN_NROFF-ms macrosLOWDOWN_TREELOWDOWN_ATTRSLOWDOWN_AUTOLINKhttp, https,
ftp, mailto, and
relative links or link fragments.LOWDOWN_CALLOUTSLOWDOWN_COMMONMARKLOWDOWN_DEFLISTLOWDOWN_FENCEDLOWDOWN_FOOTNOTESLOWDOWN_HILITELOWDOWN_IMG_EXTLOWDOWN_ATTRS instead.LOWDOWN_MANTITLELOWDOWN_METADATA is also
provided. Manpages titles must begin with a non-empty title followed
by an open parenthesis, digit or “n”, optional letters
after, then a closing parenthesis. This may be optionally followed by
a source and, if a vertical bar is detected, the content after as the
volume. These are passed to the renderers as the
title, volume, and
optionally source and
volume metadata key-value pairs. The original
title is not recoverable.LOWDOWN_MATHLOWDOWN_METADATALOWDOWN_NOCODEINDLOWDOWN_NOINTEMLOWDOWN_STRIKELOWDOWN_SUPERLOWDOWN_SUPER_SHORTLOWDOWN_SUPER is enabled, instead of the
GFM style, accept the “short” form of superscript. This
accepts foo^bar, which puts the parts following the caret until
whitespace in superscripts; or foo^(bar), which puts only the parts in
parenthesis.LOWDOWN_TABLESLOWDOWN_TASKLISTFor all types:
LOWDOWN_SMARTYLOWDOWN_STANDALONELOWDOWN_METADATA was provided as an option or
as given in meta or
metaovr.For LOWDOWN_HTML:
LOWDOWN_HTML_CALLOUT_MDN,
LOWDOWN_HTML_CALLOUT_GFMLOWDOWN_HTML_ESCAPELOWDOWN_HTML_SKIP_HTML has not been set,
escapes in-document HTML so that it is rendered as opaque text.LOWDOWN_HTML_HARD_WRAPLOWDOWN_HTML_HEAD_IDSLOWDOWN_HTML_NUM_ENTLOWDOWN_HTML_OWASPLOWDOWN_HTML_SKIP_HTMLLOWDOWN_HTML_TITLEBLOCKLOWDOWN_STANDALONE, output a
Pandoc-style title block. This is a <header
id="title-block-header"> element right after the
opening <body> containing elements for
specified title, author(s), and date. These are
<h1> and
<p> elements, respectively, with classes
set to what's being output (title, etc.). At least one of these must
be specified for the title block to be output.For LOWDOWN_GEMINI, there are several
flags for controlling link placement. By default, links (images,
autolinks, and links) are queued when specified in-line then emitted in
a block sequence after the nearest block node. (See
ABSTRACT SYNTAX
TREE.)
LOWDOWN_GEMINI_LINK_ENDLOWDOWN_GEMINI_LINK_INLOWDOWN_GEMINI_LINK_NOREFLOWDOWN_GEMINI_LINK_ROMAN.LOWDOWN_GEMINI_LINK_ROMANLOWDOWN_GEMINI_METADATAThere may only be one of
LOWDOWN_GEMINI_LINK_END or
LOWDOWN_GEMINI_LINK_IN. If both are specified,
the latter is unset.
For LOWDOWN_FODT:
LOWDOWN_ODT_SKIP_HTMLFor LOWDOWN_LATEX:
LOWDOWN_LATEX_NUMBEREDLOWDOWN_LATEX_SKIP_HTMLFor LOWDOWN_MAN and
LOWDOWN_NROFF:
LOWDOWN_NROFF_GROFF-mpdfmark for formatting
links with LOWDOWN_MAN or
-mspdf instead of
-ms for
LOWDOWN_NROFF. Applies to the
LOWDOWN_MAN and
LOWDOWN_NROFF output types.LOWDOWN_NROFF_NOLINKLOWDOWN_MAN or when
LOWDOWN_NROFF_GROFF is not specified.LOWDOWN_NROFF_NUMBEREDLOWDOWON_NROFF_GROFF
is not specified. Only applies to the
LOWDOWN_NROFF output type.LOWDOWN_NROFF_SHORTLINKLOWDOWN_MAN or when
LOWDOWN_NROFF_GROFF is not specified.LOWDOWN_NROFF_SKIP_HTMLFor LOWDOWN_TERM:
LOWDOWN_TERM_ALL_METALOWDOWN_STANDALONE is specified, output all
metadata instead of just the title, author, and date.LOWDOWN_TERM_NOANSILOWDOWN_TERM_NOCOLOUR.LOWDOWN_TERM_NOCOLOURLOWDOWN_TERM_NOLINKLOWDOWN_TERM_SHORTLINK to also shorten
autolinks.LOWDOWN_TERM_SHORTLINKLOWDOWN_TERM_NOLINK to only show shortened
autolinks.LOWDOWN_TERM, the “soft limit”
for width of terminal output not including margins. If zero, 80 shall be
used.LOWDOWN_TERM, the left margin (space
characters).LOWDOWN_TERM, the top/bottom margin
(newlines).LOWDOWN_MAN or
LOWDOWN_NROFF, this contains constant-width font
variants: const char *cr for roman constant-width,
const char *cb for bold, const char
*ci for italic, and const char *cbi for
bold-italic. If any of these are NULL, they
default to their constant-width variants.LOWDOWN_FODT,
this contains const char *sty, which is either
NULL or the OpenDocument styles used when creating
standalone documents. If NULL, the default styles
are used.NULL. Each
pair must appear as if provided on one line (or multiple lines) of the
input, including the terminating newline character. If not consisting of a
valid pair (e.g., no newline, no colon), then it is ignored. When
processed, these values are overridden by those in the document (if
LOWDOWN_METADATA is specified) or by those in
metaovr.Parsed metadata is held in key-value struct
lowdown_meta pairs, or collectively as struct
lowdown_metaq, if LOWDOWN_METADATA is set in
feat. The former structure consists of the following
fields:
The abstract syntax tree is encoded in struct lowdown_node, which consists of the following.
LOWDOWN_BLOCKCODE<pre><code>.LOWDOWN_BLOCKHTMLLOWDOWN_BLOCKQUOTE<blockquote>.LOWDOWN_CODESPAN<code>.LOWDOWN_DEFINITION<dl>.LOWDOWN_DEFINITION_DATA<dd>.LOWDOWN_DEFINITION_TITLE<dt>.LOWDOWN_DOC_HEADER<head>.LOWDOWN_DOUBLE_EMPHASIS<strong>.LOWDOWN_EMPHASIS<em>.LOWDOWN_ENTITYLOWDOWN_FOOTNOTELOWDOWN_HEADER<h1> through
<h6>.LOWDOWN_HIGHLIGHT<mark>.LOWDOWN_HRULE<hr>.LOWDOWN_IMAGE<img>.LOWDOWN_LINEBREAK<br>.LOWDOWN_LINK<a>.LOWDOWN_LINK_AUTOLOWDOWN_LINK, except inferred from text
content.LOWDOWN_LIST<ul> or
<ol>.LOWDOWN_LISTITEM<li>.LOWDOWN_MATH_BLOCK\[xx\] or \(xx\). This
is usually (in HTML) externally handled by a JavaScript renderer.LOWDOWN_META<head>.LOWDOWN_NORMAL_TEXTLOWDOWN_PARAGRAPH<p>.LOWDOWN_RAW_HTMLLOWDOWN_ROOTNULL.LOWDOWN_STRIKETHROUGH<del>.LOWDOWN_SUBSCRIPT,
LOWDOWN_SUPERSCRIPT<sub> or
<sup>, respectively.LOWDOWN_TABLE_BLOCK<table>.LOWDOWN_TABLE_BODY<tbody>.LOWDOWN_TABLE_CELL<td>, or
<th> if in the header.LOWDOWN_TABLE_HEADER<thead>.LOWDOWN_TABLE_ROW<tr>.LOWDOWN_TRIPLE_EMPHASISLOWDOWN_EMPHASIS and
LOWDOWN_DOUBLE_EMPHASIS.NULL at the root.LOWDOWN_CHNG_INSERT), deleted
(LOWDOWN_CHNG_DELETE), or neither
(LOWDOWN_CHNG_NONE).LOWDOWN_LINK_AUTO, the link address as
link and the link type
type, which may be one of
HALINK_EMAIL for e-mail links and
HALINK_NORMAL otherwise. Any buffer may be
empty-sized.LOWDOWN_BLOCKCODE, the opaque
text of the block and the optional
lang of the code language.LOWDOWN_BLOCKHTML, the opaque HTML
text.LOWDOWN_DEFINITION, containing
flags that may be
HLIST_FL_BLOCK if the definition list should
be interpreted as containing block nodes.LOWDOWN_ENTITY, the entity
text.LOWDOWN_HEADER, the
level of the header starting at zero (this value
is relative to the metadata base header level, defaulting to one),
optional space-separated class list attr_cls,
and optional single identifier attr_id.LOWDOWN_IMAGE, the image address
link, the image title
title, dimensions NxN (width by height) in
dims, and alternate text
alt. CSS in-line style for width and height may
be given in attr_width and/or
attr_height, and a space-separated list of
classes may be in attr_cls and a single
identifier may be in attr_id.LOWDOWN_LIST, consists of a bitfield
flags that may be set to
HLIST_FL_ORDERED for an ordered list and
HLIST_FL_UNORDERED for an unordered one. If
HLIST_FL_BLOCK is set, the list should be
output as if items were separate blocks. The
start value for
HLIST_FL_ORDERED is the starting list item
position, which is one by default and never zero. The
items is the number of list items.LOWDOWN_LISTITEM, consists of a bitfield
flags that may be set to
HLIST_FL_ORDERED for an ordered list,
HLIST_FL_UNORDERED for an unordered list,
HLIST_FL_DEF for definition list data,
HLIST_FL_CHECKED or
HLIST_FL_UNCHECKED for an unordered
“task” list, and/or
HLIST_FL_BLOCK for list item output as if
containing block nodes. The HLIST_FL_BLOCK
should not be used: use the parent list (or definition list) flags for
this. The num is the index in a
HLIST_FL_ORDERED list. It is monotonically
increasing with each item in the list, starting at the
start variable given in struct
rndr_list.LOWDOWN_MATH, the mode of display in
blockmode: if 1, in-line math; if 2, multi-line.
The opaque equation, which is assumed to be in LaTeX format, is in the
opaque text.LOWDOWN_META key-value pair is
represented. The keys are lower-case without spaces or non-ASCII
characters. If provided, enclosed nodes may consist only of
LOWDOWN_NORMAL_TEXT and
LOWDOWN_ENTITY.LOWDOWN_NORMAL_TEXT. If
flags is set to
HTEXT_ESCAPED, the text may be escaped for
output, but may not be altered by any smart typography or similar (it
should be passed as-is).LOWDOWN_PARAGRAPH, species how many
lines the paragraph has in the input file and
beoln, set to non-zero if the paragraph ends
with an empty line instead of a breaking block node.LOWDOWN_RAW_HTML, the opaque HTML
text.LOWDOWN_TABLE_BLOCK, the number of
columns in each row or header row. The number of
columns in rndr_table,
rndr_table_header, and
rndr_table_cell are the same.LOWDOWN_TABLE_CELL, the current
col column number out of
columns. See
rndr_table_header for a description of the bits
in flags. The number of columns in
rndr_table,
rndr_table_header, and
rndr_table_cell are the same.LOWDOWN_TABLE_HEADER, the number of
columns in each row and the per-column
flags, which may tested for equality against
HTBL_FL_ALIGN_LEFT,
HTBL_FL_ALIGN_RIGHT, or
HTBL_FL_ALIGN_CENTER after being masked with
HTBL_FL_ALIGNMASK; or
HTBL_FL_HEADER. If no alignment is specified
after the mask, the default should be left-aligned. The number of
columns in rndr_table,
rndr_table_header, and
rndr_table_cell are the same.A parsed document is a tree of struct lowdown_node nodes. If a node is “block”, it may contain other block or inline nodes. If “inline,” it may only contain other inline nodes. “Special” nodes are documented below. An additional mark of “void” means that the node will never contain children.
| Node | Scope |
LOWDOWN_BLOCKCODE |
block, void |
LOWDOWN_BLOCKHTML |
block, void |
LOWDOWN_BLOCKQUOTE |
block |
LOWDOWN_CODESPAN |
inline, void |
LOWDOWN_DEFINITION |
block |
LOWDOWN_DEFINITION_DATA |
special |
LOWDOWN_DEFINITION_TITLE |
special |
LOWDOWN_DOC_HEADER |
special |
LOWDOWN_DOUBLE_EMPHASIS |
inline |
LOWDOWN_EMPHASIS |
inline |
LOWDOWN_ENTITY |
inline, void |
LOWDOWN_FOOTNOTE |
block, special |
LOWDOWN_HEADER |
block |
LOWDOWN_HRULE |
inline, void |
LOWDOWN_IMAGE |
inline, void |
LOWDOWN_LINEBREAK |
inline, void |
LOWDOWN_LINK |
inline |
LOWDOWN_LINK_AUTO |
inline, void |
LOWDOWN_LIST |
block |
LOWDOWN_LISTITEM |
special |
LOWDOWN_MATH_BLOCK |
inline, void |
LOWDOWN_META |
special |
LOWDOWN_NORMAL_TEXT |
inline, void |
LOWDOWN_PARAGRAPH |
block |
LOWDOWN_RAW_HTML |
inline, void |
LOWDOWN_ROOT |
special |
LOWDOWN_STRIKETHROUGH |
inline |
LOWDOWN_SUBSCRIPT |
inline |
LOWDOWN_SUPERSCRIPT |
inline |
LOWDOWN_TABLE_BLOCK |
block |
LOWDOWN_TABLE_BODY |
special |
LOWDOWN_TABLE_CELL |
special |
LOWDOWN_TABLE_HEADER |
special |
LOWDOWN_TABLE_ROW |
special |
LOWDOWN_TRIPLE_EMPHASIS |
inline |
The general structure of the AST is as follows. Nodes have no order imposed on them unless as noted:
LOWDOWN_ROOT
(ordered)
LOWDOWN_DOC_HEADER
Special nodes have specific placement within their parents as follows:
LOWDOWN_DEFINITION
(one or more ordered pairs of...)
LOWDOWN_DEFINITION_TITLE
LOWDOWN_DEFINITION_DATA
LOWDOWN_HEADER
LOWDOWN_LIST
LOWDOWN_LISTITEM
LOWDOWN_TABLE_BLOCK
(ordered)
LOWDOWN_TABLE_HEADER
(zero or more...)
LOWDOWN_TABLE_ROW
(one or more...)
LOWDOWN_TABLE_CELL
LOWDOWN_TABLE_BODY
(zero or more...)
LOWDOWN_TABLE_ROW
(one or more...)
LOWDOWN_TABLE_CELL
Lastly, LOWDOWN_FOOTNOTE may appear
anywhere in the document and contains block nodes.
lowdown(1), lowdown_buf(3), lowdown_buf_diff(3), lowdown_diff(3), lowdown_doc_free(3), lowdown_doc_new(3), lowdown_doc_parse(3), lowdown_file(3), lowdown_file_diff(3), lowdown_gemini_free(3), lowdown_gemini_new(3), lowdown_gemini_rndr(3), lowdown_html_free(3), lowdown_html_new(3), lowdown_html_rndr(3), lowdown_latex_free(3), lowdown_latex_new(3), lowdown_latex_rndr(3), lowdown_metaq_free(3), lowdown_nroff_free(3), lowdown_nroff_new(3), lowdown_nroff_rndr(3), lowdown_odt_free(3), lowdown_odt_new(3), lowdown_odt_rndr(3), lowdown_term_free(3), lowdown_term_new(3), lowdown_term_rndr(3), lowdown_tree_rndr(3), lowdown(5)
lowdown was forked from
hoedown by
Kristaps Dzonsons,
kristaps@bsd.lv. It has been
considerably modified since.
| January 31, 2025 | Debian |