LOWDOWN_GEMINI_NEW(3)

πŸ“¦
version 3.2.1 Β· 3 versions
, in alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– LOWDOWN_GEMINI_NEW(3) πŸ’–

okay bestie, gather round, because we're looking at lowdown_gemini_new from section 3 of the manual β€” that's the library functions manual for liblowdown, and this little cutie is the one that hands you a whole Gemini renderer. it's giving "let me build you a renderer" energy, and honestly? obsessed. πŸŽ€


✨ NAME ✨

lowdown_gemini_new β€” allocate a Markdown gemini renderer πŸ¦‹


πŸ“š LIBRARY πŸ“š

library β€œliblowdown” β€” that's the one, no cap. πŸ’…


🌸 SYNOPSIS 🌸

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

void *
lowdown_gemini_new(const struct lowdown_opts *opts);

like, you include those three headers, you call the function, it gives you a void *. simple as that, periodt. ✨


πŸ’œ DESCRIPTION πŸ’œ

So what does it actually DO? It allocates a Gemini renderer, and it does that using opts->oflags β€” or, if opts is NULL, it just uses zero. lowkey the most forgiving function in the whole library. 🫢

The pointer it hands back is reusable β€” you can pass it to lowdown_gemini_rndr(3) multiple times, as many invocations as you want, it does not care. BUT (and this is the important part, don't skip this) it must be freed with lowdown_gemini_free(3). no leaving it lying around, bestie, that's a memory leak and we do NOT do those here. πŸ’€

Now, the bits that get recognised inside opts->oflags are:

  • LOWDOWN_GEMINI_LINK_IN
  • LOWDOWN_GEMINI_LINK_END
  • LOWDOWN_GEMINI_LINK_NOREF
  • LOWDOWN_GEMINI_LINK_ROMAN
  • LOWDOWN_GEMINI_METADATA
  • LOWDOWN_STANDALONE

and all of those are documented over in lowdown(3), so go read that one too, iykyk. πŸ”₯


πŸ‘‘ RETURN VALUES πŸ‘‘

  • Returns a pointer to the renderer ✨
  • or NULL on memory failure 😭 (it happens, we move on)

and yeah β€” the returned pointer must be freed with lowdown_gemini_free(3). said it before, saying it again, because it matters. πŸ’–


🌈 EXAMPLES 🌈

okay here's the whole vibe. this parses b of length bsz and outputs in Gemini format. look at her go:

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

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

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

see how every single thing that got allocated gets freed at the bottom? main character energy is also cleaning up after yourself. 🧚 the setlocale call, the lowdown_doc_new, the lowdown_doc_parse, the lowdown_buf_new, the lowdown_gemini_new, then lowdown_gemini_rndr writes into out, then fwrite sends out->data (that's out->size bytes, starting at offset 1... wait no, 1 is the size and out->size is the count β€” literally copy the line, don't overthink it πŸ’€) straight to stdout. and THEN the free-fest: lowdown_gemini_free(rndr), lowdown_buf_free(out), lowdown_node_free(n), lowdown_doc_free(doc). chef's kiss. 🀌


πŸ” SEE ALSO πŸ”

go read them, they're all connected, it's a whole friend group. 🫢


⭐ STANDARDS ⭐

The gemini β€œgemtext” format is documented in Project Gemini: https://geminiprotocol.net β€” and the version at the time of writing is 0.24.1. noted. πŸ“


ngl the thing to actually remember here: NULL opts = zero flags, reuse the pointer freely with lowdown_gemini_rndr(3), and always, ALWAYS lowdown_gemini_free(3) it. that's the whole tea. πŸ“

and that's a wrap, bestie!! this page came to you from Debian, dated $Mdocdate$, sitting pretty under the title LOWDOWN_GEMINI_NEW(3). slay, go render some gemtext, and hydrate. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from