summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2022-09-27 09:38:46 +0200
committerGravatar default2022-09-27 09:38:46 +0200
commit26a3b260d56cedf0ca56b331d8bec71d1a8b49f8 (patch)
tree16168d7f2a96a91d666786af03d1355b3f90b412
parent[html.c] new file. (diff)
downloadsnac2-26a3b260d56cedf0ca56b331d8bec71d1a8b49f8.tar.gz
snac2-26a3b260d56cedf0ca56b331d8bec71d1a8b49f8.tar.xz
snac2-26a3b260d56cedf0ca56b331d8bec71d1a8b49f8.zip
Started function not_really_markdown().
-rw-r--r--activitypub.c3
-rw-r--r--html.c65
-rw-r--r--main.c5
-rw-r--r--snac.h2
4 files changed, 74 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c
index 3a459bf..bd79041 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -32,7 +32,8 @@ int activitypub_request(snac *snac, char *url, d_char **data)
32 /* ensure it's ActivityPub data */ 32 /* ensure it's ActivityPub data */
33 ctype = xs_dict_get(response, "content-type"); 33 ctype = xs_dict_get(response, "content-type");
34 34
35 if (xs_str_in(ctype, "application/activity+json") != -1) 35 if (xs_str_in(ctype, "application/activity+json") != -1 ||
36 xs_str_in(ctype, "application/ld+json") != -1)
36 *data = xs_json_loads(payload); 37 *data = xs_json_loads(payload);
37 else 38 else
38 status = 500; 39 status = 500;
diff --git a/html.c b/html.c
index 2646e7d..de9060c 100644
--- a/html.c
+++ b/html.c
@@ -7,3 +7,68 @@
7 7
8#include "snac.h" 8#include "snac.h"
9 9
10d_char *not_really_markdown(char *content, d_char **f_content)
11/* formats a content using some Markdown rules */
12{
13 d_char *s = NULL;
14 int in_pre = 0;
15 int in_blq = 0;
16 xs *list;
17 char *p, *v;
18
19 s = xs_str_new(NULL);
20
21 p = list = xs_split(content, "\n");
22
23 while (xs_list_iter(&p, &v)) {
24 xs *ss = xs_strip(xs_dup(v));
25
26 if (xs_startswith(ss, "```")) {
27 if (!in_pre)
28 s = xs_str_cat(s, "<pre>");
29 else
30 s = xs_str_cat(s, "</pre>");
31
32 in_pre = !in_pre;
33 continue;
34 }
35
36 if (xs_startswith(ss, ">")) {
37 /* delete the > and subsequent spaces */
38 ss = xs_strip(xs_crop(ss, 1, 0));
39
40 if (!in_blq) {
41 s = xs_str_cat(s, "<blockquote>");
42 in_blq = 1;
43 }
44
45 s = xs_str_cat(s, ss);
46 s = xs_str_cat(s, "<br>");
47
48 continue;
49 }
50
51 if (in_blq) {
52 s = xs_str_cat(s, "</blockquote>");
53 in_blq = 0;
54 }
55
56 s = xs_str_cat(s, ss);
57 s = xs_str_cat(s, "<br>");
58 }
59
60 if (in_blq)
61 s = xs_str_cat(s, "</blockquote>");
62 if (in_pre)
63 s = xs_str_cat(s, "</pre>");
64
65 /* some beauty fixes */
66 if (xs_str_in(s, "</blockquote><br>") != -1) {
67 xs *os = s;
68 s = xs_replace(os, "</blockquote><br>", "</blockquote>");
69 }
70
71 *f_content = s;
72
73 return *f_content;
74}
diff --git a/main.c b/main.c
index eed5ea8..4fd0a87 100644
--- a/main.c
+++ b/main.c
@@ -153,6 +153,11 @@ int main(int argc, char *argv[])
153 153
154 printf("status: %d\n", status); 154 printf("status: %d\n", status);
155 155
156 if (valid_status(status)) {
157 xs *j = xs_json_dumps_pp(data, 4);
158 printf("%s\n", j);
159 }
160
156 return 0; 161 return 0;
157 } 162 }
158 163
diff --git a/snac.h b/snac.h
index aef8d69..562a627 100644
--- a/snac.h
+++ b/snac.h
@@ -100,3 +100,5 @@ int activitypub_get_handler(d_char *req, char *q_path,
100int activitypub_post_handler(d_char *req, char *q_path, 100int activitypub_post_handler(d_char *req, char *q_path,
101 char *payload, int p_size, 101 char *payload, int p_size,
102 char **body, int *b_size, char **ctype); 102 char **body, int *b_size, char **ctype);
103
104d_char *not_really_markdown(char *content, d_char **f_content);