This commit is contained in:
radhitya 2025-01-16 20:48:48 +07:00
parent fdffaa699c
commit d69b9b63f4
3 changed files with 119 additions and 74 deletions

15
doc Normal file
View File

@ -0,0 +1,15 @@
# Heading 1
## Heading 2
### Heading 3
This is normal text
This is **bold** and _italic_.
> This is blockquote
This is a [hyperlink](https://radhitya.org)
You should able to see image:
![idol](https://upload.wikimedia.org/wikipedia/commons/2/23/Dennis_Ritchie_2011.jpg)

76
main.c
View File

@ -57,6 +57,37 @@ char *gantihuruf(const char *kata) {
return output;
}
void add_css(void) {
FILE *fpcss = fopen("./media/style.css", "r");
if (fpcss == NULL) {
fpcss = fopen("./media/style.css", "w");
if (fpcss == NULL) {
perror("galat membuat css");
exit(1);
}
}
}
void newsetup(void) {
struct stat st;
if (stat("./source", &st) == -1) mkdir("./source", 0700);
if (stat("./target", &st) == -1) mkdir("./target", 0700);
if (stat("./media", &st) == -1) mkdir("./media", 0700);
fptr = fopen("./source/index", "r");
if (fptr == NULL) {
fptr = fopen("./source/index", "w");
if (fptr == NULL) {
perror("galat buat ./source/index (fptr)");
exit(1);
} else {
printf("sukses buat ./source/index\n");
}
} else {
printf("./source/index sudah ada\n");
fclose(fptr);
}
}
void checker(void) {
fptr = fopen("./source/index", "rb+");
if (fptr == NULL) {
@ -93,12 +124,11 @@ void
doblockquote(void) {
fprintf(fpto, "<blockquote>");
mdt.quote = 1;
while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++;
}
void
doimage(void) {
if (i + 1 < len && txt[i+1] == '[' && (i == 0 || txt[i] != '\\')) {
if (i + 1 < len && txt[i+1] == '[' && (i == 0 || txt[i] != '\\')) {
int alt_start = i + 2;
int alt_end = -1;
int url_start = -1;
@ -151,6 +181,18 @@ if (i + 1 < len && txt[i+1] == '[' && (i == 0 || txt[i] != '\\')) {
fprintf(fpto, "!");
}
}
void
docode(void) {
if (!mdt.code) {
fprintf(fpto, "<code>");
mdt.code = 1;
} else {
fprintf(fpto, "</code>");
mdt.code = 0;
}
}
void
dohyperlink(void) {
int start_linkname = i + 1;
@ -215,6 +257,7 @@ void build(void) {
}
mdt.headingone = mdt.headingtwo = mdt.quote = mdt.headingthree = 0;
if (len == 0) {
fprintf(fpto, "\n");
} else {
@ -236,8 +279,10 @@ void build(void) {
mdt.headingone = 1;
while (i < len && (txt[i] == '#' || txt[i] == ' ')) i++;
}
} else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {
doblockquote();
while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++;
} else {
fprintf(fpto, "<p>");
}
@ -251,13 +296,7 @@ void build(void) {
} else if (txt[i] == '[' && (i == 0 || txt[i-1] != '\\')) {
dohyperlink();
} else if (txt[i] == '`' && (i == 0 || txt[i-1] != '\\')) {
if (!mdt.code) {
fprintf(fpto, "<code>");
mdt.code = 1;
} else {
fprintf(fpto, "</code>");
mdt.code = 0;
}
docode();
} else if (i + 1 < len && txt[i] == '*' && txt[i+1] == '*' && (i == 0 || txt[i-1] != '\\')) {
dobold();
} else {
@ -335,24 +374,7 @@ int main(int argc, char *argv[]) {
printf("help : help\nnew : new site\nbuild : build all files in source/ to HTML\n");
return 0;
} else if (strcmp("new", argv[i]) == 0) {
struct stat st;
if (stat("./source", &st) == -1) mkdir("./source", 0700);
if (stat("./target", &st) == -1) mkdir("./target", 0700);
if (stat("./media", &st) == -1) mkdir("./media", 0700);
fptr = fopen("./source/index", "r");
if (fptr == NULL) {
fptr = fopen("./source/index", "w");
if (fptr == NULL) {
perror("galat buat ./source/index (fptr)");
exit(1);
} else {
printf("sukses buat ./source/index\n");
}
} else {
printf("./source/index sudah ada\n");
fclose(fptr);
}
newsetup();
return 0;
} else {
printf("salah perintah\n");

View File

@ -3,10 +3,18 @@ cflags = -Wall -Wextra -std=c99 -pedantic
src= main.c
out= daisy
ex=doc
install:
$(cc) $(cflags) $(src) -o $(out)
clean:
rm -rf source
rm -rf target
rm -rf media
rm $(out)
test: install
./$(out) new
cp $(ex) ./source/
./$(out) build