1LOWDOWN_DOC_PARSE(3)     BSD Library Functions Manual     LOWDOWN_DOC_PARSE(3)
2

NAME

4     lowdown_doc_parse — parse a Markdown document into an AST
5

LIBRARY

7     library “liblowdown”
8

SYNOPSIS

10     #include <sys/queue.h>
11     #include <stdio.h>
12     #include <lowdown.h>
13
14     struct lowdown_node *
15     lowdown_doc_parse(struct lowdown_doc *doc, size_t *maxn,
16         const char *input, size_t inputsz, struct lowdown_metaq *metaq);
17

DESCRIPTION

19     Parse a lowdown(5) document input of length inputsz into an AST with the
20     parser doc.  The maxn argument, if not NULL, is set to one greater than
21     the highest node identifier.  Its value is undefined if the function re‐
22     turns NULL.
23
24     If metaq is not NULL, it is filled in with document metadata (if any).
25     Metadata key names are canonicalised and duplicate names are ignored.
26     The results should be freed with lowdown_metaq_free(3).
27
28     This function may be invoked multiple times with a single doc and differ‐
29     ent input.
30

RETURN VALUES

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

EXAMPLES

36     The following parses b of length bsz.  It first allocates the parser,
37     then the document, then the renderer (HTML is used in this case).  Then
38     it passes output to the renderer, prints it, and cleans up resources.  On
39     any memory errors, it exits with err(3).
40
41           struct lowdown_doc *doc;
42           struct lowdown_node *n;
43           struct lowdown_buf *ob;
44           void *rndr;
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 ((rndr = lowdown_html_new(NULL)) == NULL)
51                   err(1, NULL);
52           if ((ob = lowdown_buf_new(1024)) == NULL)
53                   err(1, NULL);
54           if (!lowdown_html_rndr(ob, rndr, n))
55                   err(1, NULL);
56
57           fwrite(stdout, 1, ob->size, ob->data);
58
59           lowdown_buf_free(ob);
60           lowdown_html_rndr_free(rndr);
61           lowdown_node_free(n);
62           lowdown_doc_free(doc);
63

SEE ALSO

65     lowdown(3)
66
67BSD                            December 17, 2023                           BSD
Impressum