This commit is contained in:
radhitya 2025-01-18 12:10:50 +07:00
parent 69d97f4dff
commit 52d54e50e7

42
main.c
View File

@ -288,6 +288,8 @@ void generate(void) {
while (fgets(txt, MAX_LENGTH, fptr) != NULL) { while (fgets(txt, MAX_LENGTH, fptr) != NULL) {
len = strlen(txt); len = strlen(txt);
int judul = 0;
if (len > 0 && txt[len - 1] == '\n') { if (len > 0 && txt[len - 1] == '\n') {
txt[--len] = '\0'; txt[--len] = '\0';
} }
@ -299,35 +301,31 @@ void generate(void) {
} else { } else {
i = 0; i = 0;
if (len > 0 && txt[0] == '#') { if (txt[0] == '#') {
int heading_count = 0; int heading_count = 0;
while (i < len && txt[i] == '#') { while (i < len && txt[i] == '#') { heading_count++; i++; }
heading_count++;
i++;
}
if (i < len && txt[i] == ' ') {
if (i < len && txt[i] != '\\' && txt[i] == ' ') { i++; // Skip space after #
if (heading_count == 1) { const char *title_start = txt + i;
fprintf(fpto, "<h1>"); if (heading_count == 1 && !judul) {
mdt.headingone = 1; judul = 1;
} else if (heading_count == 2) { fseek(fpto, 0, SEEK_SET);
fprintf(fpto, "<h2>"); fprintf(fpto, "<html>\n<head>\n<meta charset=\"utf-8\"/>\n"
mdt.headingtwo = 1; "<title>%s</title>\n<link rel=\"stylesheet\" href=\"style.css\">\n"
} else if (heading_count == 3) { "</head>\n<body>\n", title_start);
fprintf(fpto, "<h3>"); fseek(fpto, 0, SEEK_END);
mdt.headingthree = 1; fprintf(fpto, "<h1>%s</h1>", title_start);
}
i++;
} else { } else {
i = 0; fprintf(fpto, "<h%d>%s</h%d>\n", heading_count, title_start, heading_count);
} }
continue;
} }
}
else if (len > 1 && txt[0] == '>' && txt[1] != '\\') { else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {
fprintf(fpto, "<blockquote>"); doblockquote();
mdt.quote = 1;
while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++; while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++;
} else { } else {
fprintf(fpto, "<p>"); fprintf(fpto, "<p>");