cmark
My personal build of CMark ✏️
cmark.c (1069B)
1 #include <stdlib.h> 2 #include <assert.h> 3 #include <stdio.h> 4 #include "node.h" 5 #include "houdini.h" 6 #include "cmark.h" 7 #include "buffer.h" 8 9 int cmark_version() { return CMARK_VERSION; } 10 11 const char *cmark_version_string() { return CMARK_VERSION_STRING; } 12 13 static void *xcalloc(size_t nmem, size_t size) { 14 void *ptr = calloc(nmem, size); 15 if (!ptr) { 16 fprintf(stderr, "[cmark] calloc returned null pointer, aborting\n"); 17 abort(); 18 } 19 return ptr; 20 } 21 22 static void *xrealloc(void *ptr, size_t size) { 23 void *new_ptr = realloc(ptr, size); 24 if (!new_ptr) { 25 fprintf(stderr, "[cmark] realloc returned null pointer, aborting\n"); 26 abort(); 27 } 28 return new_ptr; 29 } 30 31 cmark_mem DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, free}; 32 33 cmark_mem *cmark_get_default_mem_allocator() { 34 return &DEFAULT_MEM_ALLOCATOR; 35 } 36 37 38 char *cmark_markdown_to_html(const char *text, size_t len, int options) { 39 cmark_node *doc; 40 char *result; 41 42 doc = cmark_parse_document(text, len, options); 43 44 result = cmark_render_html(doc, options); 45 cmark_node_free(doc); 46 47 return result; 48 }