LOWDOWN_TERM_RNDR(3)

πŸ“¦
version 3.2.1 Β· 2 versions
, in alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 called setlocale(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. πŸ’–βœ¨πŸŽ€