diff --git a/main.c b/main.c index cb0792f..794d126 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,3 @@ -/* daisy - * alif@radhitya.org - * - * thank you stackoverflow, geeksforgeeks, grok - */ - #define _DEFAULT_SOURCE #include @@ -284,12 +278,12 @@ void generate(void) { fprintf(fpto, "daisy homepage\n"); fprintf(fpto, "\n"); fprintf(fpto, "\n\n"); - + + int judul = 0; + while (fgets(txt, MAX_LENGTH, fptr) != NULL) { len = strlen(txt); - int judul = 0; - if (len > 0 && txt[len - 1] == '\n') { txt[--len] = '\0'; } @@ -302,26 +296,32 @@ void generate(void) { i = 0; if (txt[0] == '#') { - int heading_count = 0; - while (i < len && txt[i] == '#') { heading_count++; i++; } + int heading_count = 0; - 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 { - fprintf(fpto, "%s\n", heading_count, title_start, heading_count); + while (i < len && txt[i] == '#') { + heading_count++; + i++; + } + + if (i < len && txt[i] == ' ') { + i++; + + char *title_start = txt + i; + + if (heading_count == 1) { + 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 { + fprintf(fpto, "%s\n", heading_count, title_start, heading_count); + } + continue; } - continue; } - } else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {