diff --git a/src/articles_p/process_md.c b/src/articles_p/process_md.c index 8a8b70d..42c47bf 100644 --- a/src/articles_p/process_md.c +++ b/src/articles_p/process_md.c @@ -7,10 +7,54 @@ int process_md(article_info article, char **out) char *rest = strdup(article.content), *free_rest = rest; char *buff; + int is_in_code = 0; int is_in_list = 0; while ((buff = strtok_r(rest, "\n", &rest)) != NULL) { + if (strncmp(buff, "```", 3) == 0) + { + char *snippet; + + if (is_in_code) + { + snippet = "\n"; + is_in_code = 0; + } + else + { + snippet = "
\n";
+ is_in_code = 1;
+ }
+
+ char *tmp_out = realloc(*out, strlen(*out) + strlen(snippet) + 1);
+ if (tmp_out == NULL)
+ {
+ perror("Couldn't allocate memory for new element");
+ continue;
+ }
+ *out = tmp_out;
+ strcat(*out, snippet);
+
+ continue;
+ }
+
+ if (is_in_code)
+ {
+ char *tmp_out = realloc(*out, strlen(*out) + strlen(buff) + strlen("
") + 1);
+ if (tmp_out == NULL)
+ {
+ perror("Couldn't allocate memory for new element");
+ continue;
+ }
+ *out = tmp_out;
+
+ strcat(*out, buff);
+ strcat(*out, "
");
+
+ continue;
+ }
+
if ((buff[0] == '*' && buff[1] == ' ') || (buff[0] == '-' && buff[1] == ' ') || (buff[0] == '+' && buff[1] == ' '))
{
char *begining = "";
@@ -38,7 +82,7 @@ int process_md(article_info article, char **out)
free(append);
continue;
}
-
+
if (is_in_list)
{
char *tmp_out = realloc(*out, strlen(*out) + strlen("\n") + 1);