From 24a0a640f1f2123d512ecdfd268199679b7e089f Mon Sep 17 00:00:00 2001 From: radhitya Date: Thu, 23 Jan 2025 12:41:55 +0700 Subject: [PATCH] fak --- main.c | 101 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/main.c b/main.c index 7b4a19a..c811a2c 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ typedef struct { int italic; int hyperlink; int code; + int blockcode; int headingone; int headingtwo; int headingthree; @@ -445,16 +446,16 @@ dohyperlink(void) { void build(void) { } + void generate(void) { - header = doinsert("./media/header.html"); fprintf(fpto, "\n\n\nhomepage - %s\n\n", SUBTITLE); - if( header == NULL ) { + if (header == NULL) { printf("header NULL\n"); } else { - fprintf(fpto, "%s\n", header); + fprintf(fpto, "%s\n", header); } while (fgets(txt, MAX_LENGTH, fptr) != NULL) { @@ -464,48 +465,62 @@ void generate(void) { txt[--len] = '\0'; } - mdt.headingone = mdt.headingtwo = mdt.headingthree = mdt.quote = 0; + mdt.headingone = mdt.headingtwo = mdt.headingthree = mdt.quote = mdt.blockcode = 0; if (len == 0) { fprintf(fpto, "\n"); } else { - i = 0; -judul = 0; + i = 0; + judul = 0; -if (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] == ' ') { - i++; - - char *title_start = txt + i; - - if (heading_count == 1) { - if (!judul) { - judul = 1; - fseek(fpto, 0, SEEK_SET); - fprintf(fpto, "\n\n\n" - "%s - %s\n\n" - "", title_start, SUBTITLE); - fprintf(fpto, "%s\n", header); + if (i < len && txt[i] == ' ') { + i++; + + char *title_start = txt + i; + + if (heading_count == 1) { + if (!judul) { + judul = 1; + fseek(fpto, 0, SEEK_SET); + fprintf(fpto, "\n\n\n" + "%s - %s\n\n" + "", title_start, SUBTITLE); + fprintf(fpto, "%s\n", header); + } + fprintf(fpto, "

%s

", title_start); + } else { + fprintf(fpto, "%s\n", heading_count, title_start, heading_count); + } + continue; + } } - fprintf(fpto, "

%s

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

"); - i = 0; } for (; i < len; i++) { @@ -525,13 +540,13 @@ if (txt[0] == '#') { } if (mdt.italic) fprintf(fpto, ""); - else if (mdt.code) fprintf(fpto, ""); - else if (mdt.bold) fprintf(fpto, ""); - else if (mdt.quote) fprintf(fpto, "\n"); - else if (mdt.headingone) fprintf(fpto, "\n"); - else if (mdt.headingtwo) fprintf(fpto, "\n"); - else if (mdt.headingthree) fprintf(fpto, "\n"); - if (!(mdt.headingone || mdt.headingtwo || mdt.headingthree || mdt.quote)) fprintf(fpto, "

\n"); + if (mdt.code) fprintf(fpto, ""); + if (mdt.bold) fprintf(fpto, ""); + if (mdt.quote) fprintf(fpto, "\n"); + if (mdt.headingone) fprintf(fpto, "\n"); + if (mdt.headingtwo) fprintf(fpto, "\n"); + if (mdt.headingthree) fprintf(fpto, "\n"); + if (!(mdt.headingone || mdt.headingtwo || mdt.headingthree || mdt.quote || mdt.blockcode)) fprintf(fpto, "

\n"); mdt.italic = mdt.bold = mdt.quote = mdt.headingone = mdt.headingtwo = mdt.headingthree = mdt.code = 0; } @@ -539,10 +554,10 @@ if (txt[0] == '#') { footer = doinsert("./media/footer.html"); - if(footer == NULL) { - printf("gak ada footer bro :(\n"); + if (footer == NULL) { + printf("gak ada footer bro :(\n"); } else { - fprintf(fpto, "%s", footer); + fprintf(fpto, "%s", footer); } fprintf(fpto, "\n");