From 308c8893d9706318e8e756069f40c1435a70df91 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 4 May 2026 16:31:51 +0200 Subject: feat(lib): return multiple errors --- examples/main.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/main.c b/examples/main.c index 18393c6..d28af79 100644 --- a/examples/main.c +++ b/examples/main.c @@ -4,13 +4,20 @@ #include 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); + struct typdown_Document doc = typdown_parse(v); + if (doc.errors != NULL) { + for (int i = 0; i < doc.errors_len; i++) { + struct typdown_Error error = doc.errors[i]; + printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(error.code), error.code); + printf("%d to %d ", error.location.beg, error.location.end); + for (int j = error.location.beg; j < error.location.end; j++) + printf("%c", v[j]); + printf("\n"); + } typdown_free(doc); return; } + uint8_t code; char *res = typdown_renderHTML(doc, &code); if (code != 0) { printf("cannot render '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code); @@ -31,6 +38,6 @@ int main() { // invalid foo("hello *world"); foo("hello world :::"); - foo("# hello :::"); + foo("# hello :::"); return 0; } -- cgit v1.2.3