diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 49 |
1 files changed, 27 insertions, 22 deletions
@@ -1,33 +1,38 @@ -#include <string.h> #include <stdio.h> #include <stdlib.h> -#include "parser.h" - -#define MAX_LINE_LEN 1024 +#include <cmark.h> +#include <string.h> +#define MAX_SIZE 1024 +#define BUFFER_SIZE 4096 -int main(int argc, char** argv) { - - char line[MAX_LINE_LEN]; - struct md_token* mt = malloc(sizeof(struct md_token)); - if (!mt) { - return -1; - } +/* TODO: Add custom syntax filter */ +int apply_custom_syntax(char *input); - mt->idx = 0; +int main() +{ + size_t cap = BUFFER_SIZE; + size_t len = 0; + char *markdown_input = malloc(cap); - while(fgets(line, sizeof(line), stdin) != NULL) { - mt->line_len = strlen(line); - mt->line = line; - if (line[0] == '#') { - int a = parse_title(mt); - } else { - parse_content(mt); + char buffer[BUFFER_SIZE]; + while (fgets(buffer, sizeof(buffer), stdin) != NULL) { + size_t line_len = strlen(buffer); + if (len + line_len >= cap) { + cap *= 2; + markdown_input = realloc(markdown_input, cap); } + strcpy(markdown_input + len, buffer); + len += line_len; + } + char *html_output = + cmark_markdown_to_html(markdown_input, len, CMARK_OPT_DEFAULT); - - - mt->idx = 0; + if (html_output) { + printf("%s", html_output); + free(html_output); } + + free(markdown_input); return 0; } |
