summaryrefslogtreecommitdiffstats
path: root/main.c
blob: deeff4a55d54c67c69672c1e0616fd65f13b1c38 (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <cmark.h>
#include <string.h>

#define MAX_SIZE 1024
#define BUFFER_SIZE 4096

/* TODO: Add custom syntax filter */
int apply_custom_syntax(char *input);

int main()
{
	size_t cap = BUFFER_SIZE;
	size_t len = 0;
	char *markdown_input = malloc(cap);

	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);

	if (html_output) {
		printf("%s", html_output);
		free(html_output);
	}

	free(markdown_input);
	return 0;
}