LOWDOWN_TERM_RNDR(3)
π LOWDOWN_TERM_RNDR β lowdown_term_rndr(3) π
okay bestie, gather round, because this one is the glow-up function in liblowdown's manual pages. it's lowdown_term_rndr, it lives in the LOWDOWN_TERM_RNDR(3) corner of the Library Functions Manual, and it takes your Markdown and makes it look cute in a terminal. slay.
π LIBRARY
the library is literally called βliblowdownβ. iconic name, no notes.
β¨ SYNOPSIS
#include <sys/queue.h>
#include <stdio.h>
#include <lowdown.h>
int
lowdown_term_rndr(struct lowdown_buf *out, void *arg,
const struct lowdown_node *n);
three includes, one function, zero drama. π
π¦ DESCRIPTION
so basically? you give it a node tree n β one that was created by lowdown_doc_parse(3) or lowdown_diff(3) β and it renders the whole thing using the terminal renderer arg, which you got from lowdown_term_new(3). the output goes into out, and heads up: out has to be initialised and freed by you, the caller. that's your job, not the function's. main character responsibilities. π
what comes out is UTF-8 encoded characters plus ANSI escape sequences β and yes, technically those are ISO/IEC 6429 escape sequences, we're being precise about it because precision is a vibe.
β οΈ real talk: you're expected to have already calledsetlocale(3)and set it to a"UTF-8"character encoding before you use this function. if you skip that step, UTF-8 sequences will not be properly recognised and everything will be a mess. not cute. don't do it. π
π RETURN VALUES
- returns zero if it fails to allocate memory π
- returns non-zero on success π
that's the whole thing. zero = bad, not-zero = good. it's giving inverted logic but we respect it.
π EXAMPLES
this one parses bi of length bsz and outputs in ANSI terminal format. copy it, run it, love it:
struct lowdown_buf *out;
struct lowdown_doc *doc;
struct lowdown_node *n;
void *rndr;
if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL)
err(1, NULL);
if ((doc = lowdown_doc_new(NULL)) == NULL)
err(1, NULL);
if ((n = lowdown_doc_parse(doc, NULL, b, bsz, NULL)) == NULL)
err(1, NULL);
if ((out = lowdown_buf_new(256)) == NULL)
err(1, NULL);
if ((rndr = lowdown_term_new(NULL)) == NULL)
err(1, NULL);
if (!lowdown_term_rndr(out, rndr, n))
err(1, NULL);
fwrite(out->data, 1, out->size, stdout);
lowdown_term_free(rndr);
lowdown_buf_free(out);
lowdown_node_free(n);
lowdown_doc_free(doc);
notice how every single err(1, NULL) is checking for failure and every cleanup at the bottom frees exactly one thing. chef's kiss. π§
π SEE ALSO
the whole friend group, fr fr.
π STANDARDS
ANSI escape codes are described in ISO/IEC 6429, which used to be called ECMA-48 back in the day. glow-up of a standard name, honestly.
and that's the page!! π«Ά this whole thing comes to you from Debian, with a $Mdocdate$ on the calendar β so like, whenever that date is, that's when this was poppin'. go render some Markdown in your terminal and absolutely eat. πβ¨π
π¦ where this page comes from
- alpine 3.24: lowdown-doc 3.0.1-r0 Β· ISC
- arch rolling: lowdown 3.2.1-1 Β· ISC
- debian trixie: liblowdown-dev 2.0.2-2 Β· ISC
- fedora 43: lowdown-libs 2.0.2-2.fc43 Β· ISC AND BSD-3-Clause AND MIT
- fedora 43: lowdown-libs 2.0.2-2.fc43 Β· ISC AND BSD-3-Clause AND MIT
- fedora 44: lowdown-libs 2.0.2-3.fc44 Β· ISC AND BSD-3-Clause AND MIT
- fedora 44: lowdown-libs 2.0.2-3.fc44 Β· ISC AND BSD-3-Clause AND MIT
- nixpkgs unstable: lowdown 3.0.1
- nixpkgs unstable: lowdown-unsandboxed 3.0.1
- opensuse-leap 16.0: lowdown-devel 1.1.0+git20231119.1200b9f-bp160.1.13 Β· ISC
- opensuse-leap 16.0: lowdown-devel 1.1.0+git20231119.1200b9f-bp160.1.13 Β· ISC
- opensuse-leap 16.0: lowdown-devel 1.1.0+git20231119.1200b9f-bp160.1.13 Β· ISC
- opensuse-leap 16.0: lowdown-devel 1.1.0+git20231119.1200b9f-bp160.1.13 Β· ISC
- ubuntu noble: liblowdown-dev 1.1.0-1 Β· ISC
- ubuntu questing: liblowdown-dev 2.0.2-2
- ubuntu resolute: liblowdown-dev 2.0.4-2 Β· ISC
- ubuntu stonking: liblowdown-dev 3.0.1-1 Β· ISC
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms