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_metadata
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 struct lowdown_opts structure manage features. It has the following fields:
LOWDOWN_AUTOLINK
http
, https
,
ftp
, mailto
, and
relative links or link fragments.LOWDOWN_COMMONMARK
LOWDOWN_DEFLIST
LOWDOWN_FENCED
LOWDOWN_FOOTNOTES
LOWDOWN_HILITE
LOWDOWN_IMG_EXT
LOWDOWN_MATH
LOWDOWN_METADATA
LOWDOWN_NOCODEIND
LOWDOWN_NOINTEM
LOWDOWN_STRIKE
LOWDOWN_SUPER
LOWDOWN_TABLES
The default value is zero (none).
For LOWDOWN_HTML
:
LOWDOWN_HTML_ESCAPE
LOWDOWN_HTML_SKIP_HTML
has not been set,
escapes in-document HTML so that it is rendered as opaque text.LOWDOWN_HTML_HARD_WRAP
LOWDOWN_HTML_HEAD_IDS
LOWDOWN_HTML_OWASP
LOWDOWN_HTML_NUM_ENT
LOWDOWN_HTML_SKIP_HTML
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 element.
LOWDOWN_GEMINI_LINK_END
LOWDOWN_GEMINI_LINK_IN
LOWDOWN_GEMINI_LINK_NOREF
LOWDOWN_GEMINI_LINK_ROMAN
.LOWDOWN_GEMINI_LINK_ROMAN
LOWDOWN_GEMINI_METADATA
There may only be one of
LOWDOWN_GEMINI_LINK_END
or
LOWDOWN_GEMINI_LINK_IN
. If both are specified,
the latter is unset.
For LOWDOWN_LATEX
:
LOWDOWN_LATEX_NUMBERED
LOWDOWN_LATEX_SKIP_HTML
And for LOWDOWN_MAN
and
LOWDOWN_NROFF
:
LOWDOWN_NROFF_GROFF
-m
pdfmark when invoking groff(1)
for formatting links. Applies to the
LOWDOWN_MAN
and
LOWDOWN_NROFF
output types.LOWDOWN_NROFF_NUMBERED
LOWDOWON_NROFF_GROFF
is not specified. Only applies to the
LOWDOWN_NROFF
output type.LOWDOWN_NROFF_SKIP_HTML
LOWDOWN_NROFF_SHORTLINK
LOWDOWN_MAN
or when
LOWDOWN_NROFF_GROFF
is not specified.LOWDOWN_NROFF_NOLINK
LOWDOWN_MAN
or when
LOWDOWN_NROFF_GROFF
is not specified.For LOWDOWN_TERM
:
LOWDOWN_TERM_SHORTLINK
LOWDOWN_TERM_NOLINK
For any mode, you may specify:
LOWDOWN_SMARTY
LOWDOWN_STANDALONE
LOWDOWN_METADATA
was provided as an option or
as given in meta or
metaovr.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_HTML
for HTML5 output,
LOWDOWN_LATEX
for LaTeX,
LOWDOWN_MAN
for -man
macros, LOWDOWN_TERM
for ANSI-compatible UTF-8
terminal output, LOWDOWN_GEMINI
for the Gemini
format, or LOWDOWN_NROFF
for
-ms
macros. The
LOWDOWN_TREE
type causes a debug tree to be
written.
Both LOWDOWN_MAN
and
LOWDOWN_MS
will use troff tables, which usually
require the tbl(1) preprocessor.
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.Another common structure is struct
lowdown_metadata, which is used to hold parsed (and output-formatted)
metadata keys and values if LOWDOWN_METADATA
was
provided as an input bit. This structure consists of the following
fields:
The abstract syntax tree is encoded in struct lowdown_node, which consists of the following.
NULL
at the root.LOWDOWN_CHNG_INSERT
), deleted
(LOWDOWN_CHNG_DELETE
), or neither
(LOWDOWN_CHNG_NONE
).The nodes may be one of the following types, with default rendering in HTML5 to illustrate functionality.
LOWDOWN_ROOT
NULL
.LOWDOWN_BLOCKCODE
<pre><code>
elements.LOWDOWN_BLOCKHTML
LOWDOWN_BLOCKQUOTE
<blockquote>
element.LOWDOWN_CODESPAN
<code>
element.LOWDOWN_DOC_FOOTER
LOWDOWN_DOC_HEADER
.LOWDOWN_DOC_HEADER
<head>
element. (Only if
configured during parse.)LOWDOWN_DOUBLE_EMPHASIS
<strong>
element.LOWDOWN_EMPHASIS
<em>
element.LOWDOWN_ENTITY
LOWDOWN_FOOTNOTE_DEF
LOWDOWN_FOOTNOTES_BLOCK
node.
Described by the <li id="fnXX">
element. (Only if configured during parse.)LOWDOWN_FOOTNOTE_REF
LOWDOWN_FOOTNOTE_DEF
. Described
by the <sup><a>
elements. (Only if
configured during parse.)LOWDOWN_FOOTNOTES_BLOCK
<div
class="footnotes"><hr /><ol>
elements.
(Only if configured during parse.)LOWDOWN_HEADER
<h1>
through
<h6>
.LOWDOWN_HIGHLIGHT
<mark>
element. (Only if configured during parse.)LOWDOWN_HRULE
<hr>
.LOWDOWN_IMAGE
<img>
element.LOWDOWN_LINEBREAK
<br>
element.LOWDOWN_LINK
<a>
element.LOWDOWN_LINK_AUTO
LOWDOWN_LINK
, except inferred from text
content. Described by the <a>
element. (Only
if configured during parse.)LOWDOWN_LIST
<ul>
or
<ol>
.LOWDOWN_LISTITEM
LOWDOWN_LIST
. Described by
<li>
.LOWDOWN_MATH_BLOCK
\[xx\]
or \(xx\)
. This is
usually (in HTML) externally handled by a JavaScript renderer. (Only if
configured during parse.)LOWDOWN_META
<head>
element.LOWDOWN_NORMAL_TEXT
LOWDOWN_PARAGRAPH
<p>
element.LOWDOWN_RAW_HTML
LOWDOWN_STRIKETHROUGH
<del>
element. (Only if configured during
parse.)LOWDOWN_SUPERSCRIPT
<sup>
element. (Only if configured during parse.)LOWDOWN_TABLE_BLOCK
<table>
. (Only
if configured during parse.)LOWDOWN_TABLE_BODY
<tbody>
.
Parent is always LOWDOWN_TABLE_BLOCK
. (Only if
configured during parse.)LOWDOWN_TABLE_CELL
<td>
or
<th>
if in the header. Parent is always
LOWDOWN_TABLE_ROW
. (Only if configured during
parse.)LOWDOWN_TABLE_HEADER
<thead>
. Parent is always
LOWDOWN_TABLE_BLOCK
. (Only if configured during
parse.)LOWDOWN_TABLE_ROW
<tr>
. Parent is
always LOWDOWN_TABLE_HEADER
or
LOWDOWN_TABLE_BODY
. (Only if configured during
parse.)LOWDOWN_TRIPLE_EMPHASIS
LOWDOWN_EMPHASIS
and
LOWDOWN_DOUBLE_EMPHASIS
.The following anonymous union structures correspond to certain nodes. Note that all buffers may be zero-length.
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_DEFINITION
, containing
flags that may be
HLIST_FL_BLOCK
if the definition list should be
interpreted as containing block elements.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. If start is a
non-empty string, it is the first list item value.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 element.LOWDOWN_LISTITEM
, consists of a bitfield
flags that may be set to
HLIST_FL_ORDERED
(an ordered list),
HLIST_FL_UNORDERED
(unordered list),
HLIST_FL_DEF
(definition list data), and/or
HLIST_FL_BLOCK
(list item output as if containing
block elements). The HLIST_FL_BLOCK
should not be
used: use the parent list (or definition list) flags for this. The
num is the index in an ordered list.LOWDOWN_HEADER
, the
level of the header starting at zero This value is
relative to the metadata base header level, defaulting to one (the
top-level header).LOWDOWN_NORMAL_TEXT
.LOWDOWN_ENTITY
, the entity
text.LOWDOWN_LINK_AUTO
, the link address as
link; the textual component
text; 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_RAW_HTML
, the opaque HTML
text.LOWDOWN_BLOCKCODE
, the opaque
text of the block and the optional
lang of the code language.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_HEADER
, the number of
columns in each row and the per-column
flags, which may be bits of
HTBL_FL_ALIGN_LEFT
,
HTBL_FL_ALIGN_RIGHT
, or
HTBL_FL_ALIGN_CENTER
when masked with
HTBL_FL_ALIGNMASK
; or
HTBL_FL_HEADER
. 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_FOOTNOTE_DEF
, the footnote number
num (starting at zero). This matches a single
LOWDOWN_FOOTNOTE_DEF
similarly numbered. The
key is its original in-document reference key.LOWDOWN_FOOTNOTE_REF
reference to a
LOWDOWN_FOOTNOTE_DEF
, the footnote number
num (starting at zero). The
def is the content parsed as children to the
matching LOWDOWN_FOOTNOTE_DEF
. The
key is its original in-document reference key.LOWDOWN_IMAGE
, the image address
link, the image title title,
dimensions NxN (width by height) in dims, and
alternate text alt.LOWDOWN_MATH
, the mode of display
displaymode: if 1, in-line math; if 2,
multi-line.LOWDOWN_BLOCKHTML
, the opaque HTML
text.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_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.
February 19, 2021 | Debian |