add table markup; v1.0
This commit is contained in:
parent
10d57d0f6c
commit
eb80d36ef6
2 changed files with 78 additions and 4 deletions
|
@ -104,6 +104,12 @@ There is a markup language which makes writing long blog posts, memex entries, e
|
|||
// shorthand for level 4 heading
|
||||
{.heading text}
|
||||
|
||||
// shorthand for tables
|
||||
{[column 1 header|column 2 header|column 3 header}
|
||||
{|simple data|{@bold data}|{*https://nilfm.cc|link data}}
|
||||
{|more|and more|and more data!}
|
||||
{;}
|
||||
|
||||
// shorthand for publish date (renders as <time class='publish-date'>)
|
||||
{+2022-02-22}
|
||||
```
|
||||
|
|
76
main.c
76
main.c
|
@ -46,6 +46,8 @@ int clin(char *str, char c) {int i = -1; int j = 0; while(str[j] != '\0'){if(str
|
|||
/* clang-format on */
|
||||
|
||||
int fpinject(FILE* f, Lexicon* l, char* filepath);
|
||||
int fptemplate(FILE*, Lexicon*, char*);
|
||||
int fpmetatemplate(FILE*, Lexicon*, char*);
|
||||
|
||||
int error(char* msg, char* val) {
|
||||
printf("Error: %s(%s)\n", msg, val);
|
||||
|
@ -114,7 +116,7 @@ int gettwtxt(FILE* f) {
|
|||
|
||||
void fpedited(FILE* f) {
|
||||
struct tm timebuf;
|
||||
char strbuf[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
char strbuf[16] = {0};
|
||||
|
||||
timebuf = *localtime(&edittime);
|
||||
strftime(strbuf, 16, "%Y-%m-%d", &timebuf);
|
||||
|
@ -228,6 +230,69 @@ int fpimg(FILE* f, char* s) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int fpthead(FILE* f, char* s) {
|
||||
char sbuf[TAG_BODY_SIZE] = {0};
|
||||
char* c = s;
|
||||
int data = 0;
|
||||
|
||||
fputs("<table><thead><tr>\n", f);
|
||||
while (*c) {
|
||||
data = 1;
|
||||
if (*c != '|') {
|
||||
ccat(sbuf, *c);
|
||||
} else {
|
||||
fprintf(f, "<th>%s</th>\n", sbuf);
|
||||
sbuf[0] = 0;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (data) {
|
||||
fprintf(f, "<th>%s</th>\n", sbuf);
|
||||
}
|
||||
fputs("</tr></thead>\n<tbody>", f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fptbody(FILE* f, Lexicon* l, char* s) {
|
||||
char sbuf[TAG_BODY_SIZE] = {0};
|
||||
char* c = s;
|
||||
int data = 0;
|
||||
int bopen = 0;
|
||||
int bclose = 0;
|
||||
|
||||
fputs("<tr>\n", f);
|
||||
while (*c) {
|
||||
data = 1;
|
||||
if (*c == '{') {
|
||||
bopen++;
|
||||
}
|
||||
if (*c == '}') {
|
||||
bclose++;
|
||||
}
|
||||
if (*c != '|' || bopen != bclose) {
|
||||
ccat(sbuf, *c);
|
||||
} else {
|
||||
fputs("<td>", f);
|
||||
fpmetatemplate(f, l, sbuf);
|
||||
fputs("</td>\n", f);
|
||||
sbuf[0] = 0;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (data) {
|
||||
fputs("<td>", f);
|
||||
fpmetatemplate(f, l, sbuf);
|
||||
fputs("</td>\n", f);
|
||||
}
|
||||
fputs("</tr>", f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fptfoot(FILE* f) {
|
||||
fputs("</tbody></table>", f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fphimg(FILE* f, char* s) {
|
||||
char id[1024] = {0};
|
||||
char href[1024] = {0};
|
||||
|
@ -321,9 +386,6 @@ int fpaudio(FILE* f, char* s) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int fptemplate(FILE*, Lexicon*, char*);
|
||||
int fpmetatemplate(FILE*, Lexicon*, char*);
|
||||
|
||||
int fppara(FILE* f, Lexicon* l, char* s) {
|
||||
fputs("<p>", f);
|
||||
fpmetatemplate(f, l, s);
|
||||
|
@ -465,6 +527,12 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
|
|||
return fpli(f, l, s + 1);
|
||||
case '&':
|
||||
return fppara(f, l, s + 1);
|
||||
case '[':
|
||||
return fpthead(f, s + 1);
|
||||
case '|':
|
||||
return fptbody(f, l, s + 1);
|
||||
case ';':
|
||||
return fptfoot(f);
|
||||
}
|
||||
if (s[0]) {
|
||||
target = findf(l, s);
|
||||
|
|
Loading…
Reference in a new issue