diff --git a/main.c b/main.c index 41bc582..cb0792f 100644 --- a/main.c +++ b/main.c @@ -288,6 +288,8 @@ void generate(void) { while (fgets(txt, MAX_LENGTH, fptr) != NULL) { len = strlen(txt); + int judul = 0; + if (len > 0 && txt[len - 1] == '\n') { txt[--len] = '\0'; } @@ -299,35 +301,31 @@ void generate(void) { } else { i = 0; - if (len > 0 && txt[0] == '#') { - int heading_count = 0; - while (i < len && txt[i] == '#') { - heading_count++; - i++; - } + if (txt[0] == '#') { + int heading_count = 0; + while (i < len && txt[i] == '#') { heading_count++; i++; } - - if (i < len && txt[i] != '\\' && txt[i] == ' ') { - if (heading_count == 1) { - fprintf(fpto, "

"); - mdt.headingone = 1; - } else if (heading_count == 2) { - fprintf(fpto, "

"); - mdt.headingtwo = 1; - } else if (heading_count == 3) { - fprintf(fpto, "

"); - mdt.headingthree = 1; - } - i++; + if (i < len && txt[i] == ' ') { + i++; // Skip space after # + const char *title_start = txt + i; + if (heading_count == 1 && !judul) { + judul = 1; + fseek(fpto, 0, SEEK_SET); + fprintf(fpto, "\n\n\n" + "%s\n\n" + "\n\n", title_start); + fseek(fpto, 0, SEEK_END); + fprintf(fpto, "

%s

", title_start); } else { - i = 0; + fprintf(fpto, "%s\n", heading_count, title_start, heading_count); } - } + continue; + } + } else if (len > 1 && txt[0] == '>' && txt[1] != '\\') { - fprintf(fpto, "
"); - mdt.quote = 1; + doblockquote(); while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++; } else { fprintf(fpto, "

");