SOLDOUT(3)

πŸ’– SOLDOUT πŸ’–

okay bestie, gather round, because we're talking about soldout β€” the markdown parser library, straight out of the Library Functions Manual (section 3, where the library functions live 🫢). it's giving "I read markdown so you don't have to" and honestly? iconic.


✨ DESCRIPTION ✨

so here's the tea β˜• β€” the soldout library only performs the parsing of markdown input. that's it. that's the whole job. the construction of the output is left to a renderer, which is literally just a set of callback functions that get called when markdown elements are encountered. no cap.

pointers to these functions are gathered into a struct mkd_renderer, along with some renderer-related data. so the struct is like the group chat, and the callbacks are the members πŸ’…

basic usage will be, step by step, no skipping:

  1. Create output, input buffers by bufnew() function.
  2. Fill input buffer by bufput() function.
  3. Create struct mkd_renderer or use provided renderer.
  4. Call markdown() function.
  5. Process output buffer.
  6. Call bufrelease() function to clean up buffers.

like, that's the whole pipeline. six steps. a little main-character arc, fr fr 🌈


🌸 EXAMPLES 🌸

here's a simple example that uses the first argument as a markdown string, converts it to an HTML and outputs it to stdout. she's little but she works πŸ’–

#include <stdio.h>

#include <buffer.h>
#include <markdown.h>
#include <renderers.h>

#define INPUT_UNIT  1024
#define OUTPUT_UNIT 64

int
main(int argc, char *argv[])
{
  struct buf *ib, *ob;

  /* Make sure we have enough arguments. */
  if (argc != 2) {
    return 1;
  }

  ib = bufnew(INPUT_UNIT);
  ob = bufnew(OUTPUT_UNIT);

  /* bufputs() is a wrapper over bufput() for NUL-terminated string. */
  bufputs(ib, argv[1]);

  markdown(ob, ib, &mkd_html);

  /* Note the resulted data is not NUL-terminated string;
   * to make it use bufnullterm(). */
  printf("%.*s", (int)ob->size, ob->data);

  bufrelease(ib);
  bufrelease(ob);
  return 0;
}
⚠️ okay real talk for one sec β€” note the resulted data is not a NUL-terminated string. if you want it to be, use bufnullterm(). don't be out here printf-ing without knowing, bestie 😭

πŸ‘€ SEE ALSO πŸ‘€


πŸ’œ AUTHORS πŸ’œ

the soldout library was written by Natasha "Kerensikova" Porte <natacha@instinctive.eu>. the manual page was originally written by Massimo Manghi <mxmanghi@apache.org>, and rewritten to mdoc format by Svyatoslav Mishyn <juef@openmailbox.org>. absolute legends, all three of them, we love a credited queen πŸ‘‘


and that's the whole page, babe πŸŽ€ this one came from Debian, dated March 29, 2016, living in section 3 as SOLDOUT(3). go parse some markdown, you're gonna slay πŸ’…βœ¨

πŸ“¦ where this page comes from