This commit is contained in:
radhitya 2025-01-18 13:03:08 +07:00
parent 52d54e50e7
commit be9b9c0ae6

50
main.c
View File

@ -1,9 +1,3 @@
/* daisy
* alif@radhitya.org
*
* thank you stackoverflow, geeksforgeeks, grok
*/
#define _DEFAULT_SOURCE
#include <stdio.h>
@ -285,11 +279,11 @@ void generate(void) {
fprintf(fpto, "<link rel=\"stylesheet\" href=\"style.css\">\n");
fprintf(fpto, "</head>\n<body>\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, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n"
"<title>%s</title>\n<link rel=\"stylesheet\" href=\"style.css\">\n"
"</head>\n<body>\n", title_start);
fseek(fpto, 0, SEEK_END);
fprintf(fpto, "<h1>%s</h1>", title_start);
} else {
fprintf(fpto, "<h%d>%s</h%d>\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, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n"
"<title>%s</title>\n<link rel=\"stylesheet\" href=\"style.css\">\n"
"</head>\n<body>\n", title_start);
fseek(fpto, 0, SEEK_END);
fprintf(fpto, "<h1>%s</h1>", title_start);
} else {
fprintf(fpto, "<h%d>%s</h%d>\n", heading_count, title_start, heading_count);
}
continue;
}
continue;
}
}
else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {