1LOWDOWN_BUF(3) BSD Library Functions Manual LOWDOWN_BUF(3)
2
4 lowdown_buf — parse a Markdown buffer into formatted output
5
7 library “liblowdown”
8
10 #include <sys/queue.h>
11 #include <stdio.h>
12 #include <lowdown.h>
13
14 int
15 lowdown_buf(const struct lowdown_opts *opts, const char *buf,
16 size_t bufsz, char **ret, size_t *retsz,
17 struct lowdown_metaq *metaq);
18
20 Parses a lowdown(5) buffer buf of size bufsz into an output buffer ret of
21 size retsz according to a configuration opts. The output format is spec‐
22 ified by opts->type. If LOWDOWN_METADATA is set in opts->feat and metaq
23 is not NULL, metaq is filled with metadata rendered in the given output
24 format.
25
26 The caller is responsible for freeing ret and metaq.
27
29 Returns zero on failure, non-zero on success. On failure, the values
30 pointed to by res and rsz are undefined.
31
33 The following parses standard input into a standalone HTML5 document. It
34 enables footnotes, autolinks, tables, superscript, strikethrough, fenced
35 codeblocks, commonmark, definition lists, extended image attributes, and
36 metadata processing. The output passes through raw HTML and has smart
37 typography.
38
39 struct lowdown_opts opts;
40 char *buf = NULL, *obuf;
41 char rbuf[1024];
42 size_t sz, bufsz = 0, obufsz;
43
44 while (!(feof(stdin) || ferror(stdin))) {
45 sz = fread(rbuf, 1, sizeof(rbuf), stdin);
46 if (sz == 0)
47 err(1, "fread");
48 buf = realloc(buf, bufsz + sz);
49 if (buf == NULL)
50 err(1, NULL);
51 memcpy(buf + bufsz, rbuf, sz);
52 bufsz += sz;
53 }
54
55 if (ferror(stdin))
56 err(1, "fread");
57
58 memset(&opts, 0, sizeof(struct lowdown_opts));
59 opts.type = LOWDOWN_HTML;
60 opts.feat = LOWDOWN_FOOTNOTES |
61 LOWDOWN_AUTOLINK |
62 LOWDOWN_TABLES |
63 LOWDOWN_SUPER |
64 LOWDOWN_STRIKE |
65 LOWDOWN_FENCED |
66 LOWDOWN_COMMONMARK |
67 LOWDOWN_DEFLIST |
68 LOWDOWN_IMG_EXT |
69 LOWDOWN_METADATA;
70 opts.oflags = LOWDOWN_HTML_HEAD_IDS |
71 LOWDOWN_HTML_NUM_ENT |
72 LOWDOWN_HTML_OWASP |
73 LOWDOWN_SMARTY |
74 LOWDOWN_STANDALONE;
75 if (!lowdown_buf(&opts, buf, bufsz, &obuf, &obufsz, NULL))
76 errx(1, "lowdown_buf");
77 fwrite(buf, 1, bufsz, stdout);
78 free(buf);
79 free(obuf);
80
82 lowdown(3), lowdown_metaq_free(3)
83
84BSD December 17, 2023 BSD