LOWDOWN_DOC_PARSE(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_DOC_PARSE(3) πŸ’–

okay bestie, welcome to the lowdown_doc_parse page, straight out of the Library Functions Manual πŸ’… this one lives in the library liblowdown and it's literally the glow-up moment where your Markdown text becomes a whole ✨ AST ✨


🌸 NAME 🌸

lowdown_doc_parse β€” parse a Markdown document into an AST, no cap 🧚


πŸ“š LIBRARY πŸ“š

library β€œliblowdown” 🫢 that's the one, that's the vibe


✨ SYNOPSIS ✨

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

struct lowdown_node *
lowdown_doc_parse(struct lowdown_doc *doc, size_t *maxn,
    const char *input, size_t inputsz, struct lowdown_metaq *metaq);

like, include the headers first, obviously πŸ’œ


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically: you hand it a lowdown(5) document input of length inputsz, and it parses that whole thing into an AST using the parser doc. main character energy fr fr πŸ”₯

the maxn argument β€” if it's not NULL β€” gets set to one greater than the highest node identifier. and heads up, bestie: its value is undefined if the function returns NULL. so like, don't go reading it after a fail, that's giving chaos πŸ’€

if metaq is not NULL, it gets filled in with document metadata (if any). metadata key names are canonicalised and duplicate names are ignored β€” yes, she said what she said. and you gotta free those results with lowdown_metaq_free(3) afterwards, don't leave them hanging πŸŽ€

fun fact: you can invoke this function multiple times with a single doc and different input. reusing her? iconic. she doesn't mind πŸ’…


πŸ‘‘ RETURN VALUES πŸ‘‘

returns the root of the parse tree, or NULL on memory allocation failure 😭

if it's not NULL, the returned node is always of type LOWDOWN_ROOT. periodt. ⭐


πŸ“ EXAMPLES πŸ“

ok so here's the whole little ritual: it parses b of length bsz. first it allocates the parser, then the document, then the renderer (HTML in this case, because slay). then it passes output to the renderer, prints it, and cleans up resources. on any memory errors, it exits with err(3). 🌈

struct lowdown_doc *doc;
struct lowdown_node *n;
struct lowdown_buf *ob;
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 ((rndr = lowdown_html_new(NULL)) == NULL)
        err(1, NULL);
if ((ob = lowdown_buf_new(1024)) == NULL)
        err(1, NULL);
if (!lowdown_html_rndr(ob, rndr, n))
        err(1, NULL);

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

lowdown_buf_free(ob);
lowdown_html_rndr_free(rndr);
lowdown_node_free(n);
lowdown_doc_free(doc);
also can we talk about the cleanup section?? she frees everything. lowdown_buf_free, lowdown_html_rndr_free, lowdown_node_free, lowdown_doc_free. memory hygiene is the real self-care 🫢

πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie πŸ’– this one shipped with Debian and carries the date $Mdocdate$, filed under LOWDOWN_DOC_PARSE(3). go forth and parse, you absolute legend πŸ‘‘βœ¨