File: test-html.c

package info (click to toggle)
lowdown 2.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,484 kB
  • sloc: ansic: 21,512; sh: 1,892; xml: 861; makefile: 518
file content (40 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <sys/queue.h>
#include <lowdown.h>

int main(int argc, char *argv[])
{
    const char *text = "# This is a header";

    struct lowdown_doc *doc = lowdown_doc_new(NULL);
    if (!doc)
        err(2, "Cannot allocate document");

    size_t maxn = 0;
    struct lowdown_node *node = lowdown_doc_parse(doc, &maxn, text, strlen(text), NULL);
    if (!node)
        err(3, "Cannot parse document");

    void *renderer = lowdown_html_new(NULL);
    if (!renderer)
        err(4, "Cannot allocate renderer");

    struct lowdown_buf *buf = lowdown_buf_new(16384);
    if (!buf)
        err(5, "Cannot allocate output buffer");

    int rndr_res = lowdown_html_rndr(buf, renderer, node);
    if (!rndr_res)
        err(6, "Allocation error while rendering Markdown");

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

    lowdown_html_free(renderer);
    lowdown_buf_free(buf);
    lowdown_node_free(node);
    lowdown_doc_free(doc);

    return 0;
}