thx ai:(
This commit is contained in:
parent
34ec8a395b
commit
3e7de00638
47
main.c
47
main.c
|
|
@ -277,12 +277,14 @@ dohyperlink(void) {
|
|||
}
|
||||
void build(void) {
|
||||
}
|
||||
|
||||
void generate(void) {
|
||||
fprintf(fpto, "<html>\n<head>\n");
|
||||
fprintf(fpto, "<meta charset=\"utf-8\"/>\n");
|
||||
fprintf(fpto, "<title>daisy homepage</title>\n");
|
||||
fprintf(fpto, "<link rel=\"stylesheet\" href=\"style.css\">\n");
|
||||
fprintf(fpto, "</head>\n<body>\n");
|
||||
|
||||
while (fgets(txt, MAX_LENGTH, fptr) != NULL) {
|
||||
len = strlen(txt);
|
||||
|
||||
|
|
@ -290,36 +292,49 @@ void build(void) {
|
|||
txt[--len] = '\0';
|
||||
}
|
||||
|
||||
mdt.headingone = mdt.headingtwo = mdt.quote = mdt.headingthree = 0;
|
||||
mdt.headingone = mdt.headingtwo = mdt.headingthree = mdt.quote = 0;
|
||||
|
||||
if (len == 0) {
|
||||
fprintf(fpto, "\n");
|
||||
} else {
|
||||
i = 0;
|
||||
|
||||
if (len > 1 && txt[0] == '#' && txt[1] != '\\') {
|
||||
int level = 1;
|
||||
while(i < len && txt[i] == '#' && level <= 3 && txt[i+1] != '\\') {
|
||||
level++;
|
||||
if (len > 0 && txt[0] == '#') {
|
||||
int heading_count = 0;
|
||||
while (i < len && txt[i] == '#') {
|
||||
heading_count++;
|
||||
i++;
|
||||
}
|
||||
switch (level) {
|
||||
case 2: fprintf(fpto, "<h1>"); mdt.headingone = 1; break;
|
||||
case 3: fprintf(fpto, "<h2>"); mdt.headingtwo = 1; break;
|
||||
case 4: fprintf(fpto, "<h3>"); mdt.headingthree = 1; break;
|
||||
default: i = 0; break;
|
||||
}
|
||||
while (i < len && txt[i] == ' ') i++;
|
||||
|
||||
} else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {
|
||||
doblockquote();
|
||||
|
||||
if (i < len && txt[i] != '\\' && txt[i] == ' ') {
|
||||
if (heading_count == 1) {
|
||||
fprintf(fpto, "<h1>");
|
||||
mdt.headingone = 1;
|
||||
} else if (heading_count == 2) {
|
||||
fprintf(fpto, "<h2>");
|
||||
mdt.headingtwo = 1;
|
||||
} else if (heading_count == 3) {
|
||||
fprintf(fpto, "<h3>");
|
||||
mdt.headingthree = 1;
|
||||
}
|
||||
i++;
|
||||
} else {
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if (len > 1 && txt[0] == '>' && txt[1] != '\\') {
|
||||
fprintf(fpto, "<blockquote>");
|
||||
mdt.quote = 1;
|
||||
while (i < len && (txt[i] == '>' || txt[i] == ' ')) i++;
|
||||
} else {
|
||||
fprintf(fpto, "<p>");
|
||||
i = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
|
||||
for (; i < len; i++) {
|
||||
if (txt[i] == '_' && (i == 0 || txt[i - 1] != '\\')) {
|
||||
doitalic();
|
||||
} else if (txt[i] == '!' && (i == 0 || txt[i - 1] != '\\')) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user