aboutsummaryrefslogtreecommitdiff
path: root/examples/main.c
blob: 18393c6d516b7fc79047b841dd92f690593e7b1c (plain)
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
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <typdown.h>

void foo(char *v) {
    uint8_t code;
    void *doc = typdown_parse(v, &code);
    if (code != 0) {
        printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code);
        typdown_free(doc);
        return;
    }
    char *res = typdown_renderHTML(doc, &code);
    if (code != 0) {
        printf("cannot render '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code);
        typdown_free(doc);
        return;
    }
    printf("%s\n", res);
    free(res);
    typdown_free(doc);
}

int main() {
    // valid
    foo("hello world");
    foo("he*ll*o world");
    foo("# he*ll*o world");

    // invalid
    foo("hello *world");
    foo("hello world :::");
    foo("# hello :::");
    return 0;
}