LOWDOWN_NROFF_RNDR(3)

πŸ“¦
version 2.0.4 Β· 2 versions
, in debian trixie, fedora 43, fedora 44, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute

πŸ’… lowdown_nroff_rndr β€” bestie's guide to rendering Markdown into roff ✨

okay so this is LOWDOWN_NROFF_RNDR(3), a page from the Library Functions Manual, and it lives in library β€œliblowdown”. yes we're doing C library lore today, stay with me 🫢


✨ NAME ✨

lowdown_nroff_rndr β€” render Markdown into roff


πŸ“š LIBRARY πŸ“š

library β€œliblowdown” 🌸


πŸŽ€ SYNOPSIS πŸŽ€

like, here's the whole vibe, the way you actually call it:

#include <sys/queue.h>
#include <stdio.h>
#include <lowdown.h>

int
lowdown_nroff_rndr(struct lowdown_buf *out, void *arg,
    const struct lowdown_node *n);

πŸ’– DESCRIPTION πŸ’–

so basically: this function renders a node tree n β€” and that tree has to have been created by lowdown_doc_parse(3) or lowdown_diff(3) β€” using the roff renderer arg, which you get back from lowdown_nroff_new(3). no cap. πŸ”₯

the output goes into out, and heads up bestie: you are the one who has to initialise it and free it. it is not doing that for you. the audacity? none. it's your job. πŸ’…

and what even comes out? roff output, using the ms or man macro packages. iconic. πŸ‘‘


🌟 RETURN VALUES 🌟

  • returns zero if it fails to allocate memory 😭
  • returns non-zero on success ✨

that's it. that's the whole vibe check. lowkey simple, fr fr.


🌈 EXAMPLES 🌈

okay so here's the moment. this parses b of length bsz and outputs in groff_ms(7) format. take notes πŸ“:

struct lowdown_buf *out;
struct lowdown_doc *doc;
struct lowdown_node *n;
void *rndr;

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_nroff_new(NULL)) == NULL)
        err(1, NULL);
if (!lowdown_nroff_rndr(out, rndr, n))
        err(1, NULL);

fwrite(out->data, 1, out->size, stdout);

lowdown_nroff_free(rndr);
lowdown_buf_free(out);
lowdown_node_free(n);
lowdown_doc_free(doc);

see how every single thing gets freed at the end? that's the main character energy. clean up after yourself, bestie, the memory doesn't free itself 🧚


πŸ‘€ SEE ALSO πŸ‘€


πŸ¦‹ deets on the macros, iykyk πŸ¦‹

this uses both the original troff man macros for Version 7 AT&T UNIX, defined in man(7), and the man-ext groff extensions. both of those are implemented in mandoc. slay.

the troff ms macros are defined in groff_ms(7), along with the mspdf groff extensions described in "Portable Document Format Publishing with GNU Troff" by Keith Marshall. and ngl? neither of those are implemented in mandoc. πŸ’€


🌸 and that's the whole page, bestie. Debian shipped it, the date slot says $Mdocdate$, and it's the LOWDOWN_NROFF_RNDR(3) page. go forth and render, you absolute icon πŸ‘‘πŸ’œ