aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--main.c76
2 files changed, 78 insertions, 4 deletions
diff --git a/README.md b/README.md
index 0ba79ce..79b2606 100644
--- a/README.md
+++ b/README.md
@@ -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}
```
diff --git a/main.c b/main.c
index d4a3c31..f0e7254 100644
--- a/main.c
+++ b/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);