LOWDOWN_DOC_PARSE(3) Library Functions Manual LOWDOWN_DOC_PARSE(3)

lowdown_doc_parseparse a Markdown document into an AST

library “liblowdown”

#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);

Parse a lowdown(5) document input of length inputsz into an AST with the parser doc. The maxn argument, if not NULL, is set to one greater than the highest node identifier. Its value is undefined if the function returns NULL.

This function may be invoked multiple times with a single doc and different input.

Returns the root of the parse tree or NULL on memory allocation failure. If not NULL, the returned node is always of type LOWDOWN_ROOT.

The following parsers the NUL-terminated string data. It first allocates the parser, then the document, then the renderer (HTML is used in this case). 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;

doc = lowdown_doc_new(NULL);
if (doc == NULL)
  err(1, NULL);

n = lowdown_doc_parse(doc, NULL, data, strlen(data));
if (n == NULL)
  err(1, NULL);

rndr = lowdown_html_new(NULL);
if (rndr == NULL)
  err(1, NULL);

ob = lowdown_buf_new(1024);

if (!lowdown_html_rndr(ob, NULL, rndr, n))
  err(1, NULL);

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



January 16, 2021 OpenBSD 6.7