1LOWDOWN_TERM_RNDR(3) BSD Library Functions Manual LOWDOWN_TERM_RNDR(3)
2
4 lowdown_term_rndr — render Markdown into terminal output
5
7 library “liblowdown”
8
10 #include <sys/queue.h>
11 #include <stdio.h>
12 #include <lowdown.h>
13
14 int
15 lowdown_term_rndr(struct lowdown_buf *out, void *arg,
16 const struct lowdown_node *n);
17
19 Renders a node tree n created by lowdown_doc_parse(3) or lowdown_diff(3)
20 using the terminal renderer arg as returned by lowdown_term_new(3). The
21 output is written into out, which must be initialised and freed by the
22 caller.
23
24 The output consists of UTF-8 encoded characters and ANSI (really ISO/IEC
25 6429) escape sequences.
26
27 The caller is expected to have invoked setlocale(3) to a "UTF-8" charac‐
28 ter encoding prior to using this function, otherwise UTF-8 sequences will
29 not be properly recognised.
30
32 Returns zero on failure to allocate memory, non-zero on success.
33
35 The following parses bi of length bsz and outputs in ANSI terminal for‐
36 mat.
37
38 struct lowdown_buf *out;
39 struct lowdown_doc *doc;
40 struct lowdown_node *n;
41 void *rndr;
42
43 if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL)
44 err(1, NULL);
45
46 if ((doc = lowdown_doc_new(NULL)) == NULL)
47 err(1, NULL);
48 if ((n = lowdown_doc_parse(doc, NULL, b, bsz, NULL)) == NULL)
49 err(1, NULL);
50 if ((out = lowdown_buf_new(256)) == NULL)
51 err(1, NULL);
52 if ((rndr = lowdown_term_new(NULL)) == NULL)
53 err(1, NULL);
54 if (!lowdown_term_rndr(out, rndr, n))
55 err(1, NULL);
56
57 fwrite(out->data, 1, out->size, stdout);
58
59 lowdown_term_free(rndr);
60 lowdown_buf_free(out);
61 lowdown_node_free(n);
62 lowdown_doc_free(doc);
63
65 lowdown(3), lowdown_term_free(3), lowdown_term_new(3)
66
68 ANSI escape codes are described in ISO/IEC 6429, previously ECMA-48.
69
70BSD December 17, 2023 BSD