Scroll to navigation

LOWDOWN_TERM_RNDR(3) Library Functions Manual LOWDOWN_TERM_RNDR(3)

NAME

lowdown_term_rndrrender Markdown into terminal output

LIBRARY

library “liblowdown”

SYNOPSIS

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

int
lowdown_term_rndr(struct lowdown_buf *out, struct lowdown_metaq *mq, void *arg, const struct lowdown_node *n);

DESCRIPTION

Renders a node tree n created by lowdown_doc_parse(3) or lowdown_diff(3) using the terminal renderer arg as returned by lowdown_term_new(3). The output is written into out, which must be initialised and freed by the caller.

If mq is not NULL, it is filled with any metadata as parsed. It must be initialised and its contents freed with lowdown_metaq_free(3).

The output consists of UTF-8 encoded characters and ANSI (really ISO/IEC 6429) escape sequences.

The caller is expected to have invoked setlocale(3) to a "UTF-8" character encoding prior to using this function, otherwise UTF-8 sequences will not be properly recognised.

RETURN VALUES

Returns zero on failure to allocate memory, non-zero on success.

EXAMPLES

The following assumes the the string buf of length bsz consists of Markdown content.

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, buf, bsz)) == NULL)
  err(1, NULL);
if ((out = lowdown_buf_new(256)) == NULL)
  err(1, NULL);
if ((rndr = lowdown_term_new(NULL)) == NULL)
  err(1, NULL);
if (!lowdown_term_rndr(out, NULL, rndr, n))
  err(1, NULL);

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

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

SEE ALSO

lowdown(3), lowdown_term_free(3), lowdown_term_new(3)

STANDARDS

ANSI escape codes are described in ISO/IEC 6429, previously ECMA-48.

February 19, 2021 Debian