SOLDOUT_MARKDOWN(3)

πŸŽ€ SOLDOUT_MARKDOWN(3) β€” the markdown parser, bestie edition πŸŽ€

okay so this whole page is about soldout_markdown and markdown, and their whole job is to parse markdown documents. that's it. that's the vibe. it's a C library function that takes markdown in one hand and hands you rendered stuff back with the other. no cap πŸ’…


✨ SYNOPSIS ✨

like, here's the whole cast list, copy-pasted with love:

#include <markdown.h>

#define MKD_CELL_ALIGN_DEFAULT
#define MKD_CELL_ALIGN_LEFT
#define MKD_CELL_ALIGN_RIGHT
#define MKD_CELL_ALIGN_CENTER
#define MKD_CELL_ALIGN_MASK
#define MKD_CELL_HEAD
#define MKD_LIST_ORDERED
#define MKD_LI_BLOCK

void
markdown(struct buf *ob, struct buf *ib,
    const struct mkd_renderer *rndr);

πŸ’– DESCRIPTION πŸ’–

so the markdown() function parses the input buffer ib and renders it into the output buffer ob. and rndr? that's a pointer to the renderer structure. that's the whole flow, bestie, input goes in, output comes out, the renderer decides what it all looks like πŸ¦‹

now here's the part that lowkey changes everything: function pointers inside struct mkd_renderer can be NULL. and the two kinds of NULL behave so differently:

  • a null block-level callback makes that corresponding block disappear from the output entirely, like the callback was just an empty function that does nothing. poof. gone πŸ’€
  • a null span-level callback makes the corresponding element get treated as normal characters, copied verbatim into the output. so it survives, it's just naked.

and also β€” span-level callbacks return an int, and that int is basically a vibe check: it tells you whether the renderer accepts to render the item (non-zero return value) or whether it should be copied verbatim (zero return value). periodt.

the first argument of a renderer function is always the output buffer, which is where the function is supposed to write its output. and the last argument is always a private pointer, which is the opaque member of struct mkd_renderer. and listen β€” libsoldout itself never does anything with this data. it's yours. do whatever, it doesn't peek πŸ™ˆ

emph_chars is a zero-terminated string holding the set of characters that trigger emphasis. in regular markdown, emphasis is only triggered by '_' and '*', but in some extensions it might be useful to add other characters to this list. the character that triggered the emphasis then gets passed to the emphasis, double_emphasis and triple_emphasis function callbacks through the parameter c. cute, right? πŸŽ€

the normal_text callback should perform whatever escape is needed to have the output looking like the input data. that's on you, bestie.

libsoldout supports PHP-Markdown-like tables ✨. it uses these flags: MKD_CELL_ALIGN_DEFAULT, MKD_CELL_ALIGN_LEFT, MKD_CELL_ALIGN_RIGHT, MKD_CELL_ALIGN_CENTER, MKD_CELL_ALIGN_MASK, MKD_CELL_HEAD β€” and those show up in these function callbacks: table_cell and table_row.

and MKD_LIST_ORDERED, MKD_LI_BLOCK are used as flags in these function callbacks: list and listitem.


🌸 Types 🌸

it's the type of autolink, and here's every single flavor:

  • MKDA_NOT_AUTOLINK β€” used internally when it is not an autolink.
  • MKDA_NORMAL β€” normal http/https/ftp link.
  • MKDA_EXPLICIT_EMAIL β€” e-mail link with explicit mailto.
  • MKDA_IMPLICIT_EMAIL β€” e-mail link without mailto.

struct mkd_renderer

consists of the following fields:

Document level callbacks

  • prolog β€” a pointer to a void function(struct buf *ob, void *opaque)
  • epilog β€” a pointer to a void function(struct buf *ob, void *opaque)

Block level callbacks (NULL skips the block)

  • blockcode β€” a pointer to a void function(struct buf *ob, struct buf *text, void *opaque)
  • blockquote β€” a pointer to a void function(struct buf *ob, struct buf *text, void *opaque)
  • blockhtml β€” a pointer to a void function(struct buf *ob, struct buf *text, void *opaque)
  • header β€” a pointer to a void function(struct buf *ob, struct buf *text, int level, void *opaque)
  • hrule β€” a pointer to a void function(struct buf *ob, void *opaque)
  • list β€” a pointer to a void function(struct buf *ob, struct buf *text, int flags, void *opaque)
  • listitem β€” a pointer to a void function(struct buf *ob, struct buf *text, int flags, void *opaque)
  • paragraph β€” a pointer to a void function(struct buf *ob, struct buf *text, void *opaque)
  • table β€” a pointer to a void function(struct buf *ob, struct buf *head_row, struct buf *rows, void *opaque)
  • table_cell β€” a pointer to a void function(struct buf *ob, struct buf *text, int flags, void *opaque)
  • table_row β€” a pointer to a void function(struct buf *ob, struct buf *cells, int flags, void *opaque)

Span level callbacks (NULL or return 0 prints the span verbatim)

  • autolink β€” a pointer to a int function(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque)
  • codespan β€” a pointer to a int function(struct buf *ob, struct buf *text, void *opaque)
  • emphasis β€” a pointer to a int function(struct buf *ob, struct buf *text, char c, void *opaque)
  • double_emphasis β€” a pointer to a int function(struct buf *ob, struct buf *text, char c, void *opaque)
  • triple_emphasis β€” a pointer to a int function(struct buf *ob, struct buf *text, char c, void *opaque)
  • image β€” a pointer to a int function(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque)
  • linebreak β€” a pointer to a int function(struct buf *ob, void *opaque)
  • link β€” a pointer to a int function(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque)
  • raw_html_tag β€” a pointer to a int function(struct buf *ob, struct buf *tag, void *opaque)

Low level callbacks (NULL copies input directly into the output)

  • entity β€” a pointer to a void function(struct buf *ob, struct buf *entity, void *opaque)
  • normal_text β€” a pointer to a void function(struct buf *ob, struct buf *text, void *opaque)

Renderer data

  • int max_work_stack β€” prevent arbitrary deep recursion.
  • const char * emph_chars β€” chars that trigger emphasis rendering.
  • void * opaque β€” opaque data send to every rendering callback.

🫢 RETURN VALUES 🫢

the markdown() function does not return a value. that's it. nothing. silence. main character energy of saying nothing and meaning everything πŸ’…


⭐ SEE ALSO ⭐

go read those next, iykyk πŸ¦‹


πŸ‘‘ 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>. icons, all of them πŸŽ€βœ¨


and that's the whole page bestie!! this one shipped with Debian, dated May 30, 2016 β€” oldie but a goodie, fr fr. now go render something gorgeous πŸŒˆπŸ’–

πŸ“¦ where this page comes from