summaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorGravatar Louis Brauer2024-05-25 08:05:36 +0000
committerGravatar Louis Brauer2024-05-25 08:05:36 +0000
commit84a767dd0878013194ed7551b5ae6ef715e841a6 (patch)
tree9fb1b2b89e0bfbb4b8bf1e85d840c8653e646bb7 /format.c
parentPrevent some browsers from caching servers basic auth request (diff)
parentBackport from xs (fix regex.h compilation with tcc). (diff)
downloadsnac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.gz
snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.xz
snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.zip
Merge pull request 'master' (#1) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/louis77/snac2/pulls/1
Diffstat (limited to 'format.c')
-rw-r--r--format.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/format.c b/format.c
index 92901bb..b021f55 100644
--- a/format.c
+++ b/format.c
@@ -82,7 +82,8 @@ static xs_str *format_line(const char *line, xs_list **attach)
82/* formats a line */ 82/* formats a line */
83{ 83{
84 xs_str *s = xs_str_new(NULL); 84 xs_str *s = xs_str_new(NULL);
85 char *p, *v; 85 char *p;
86 const char *v;
86 87
87 /* split by markup */ 88 /* split by markup */
88 xs *sm = xs_regex_split(line, 89 xs *sm = xs_regex_split(line,
@@ -155,7 +156,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
155 int in_pre = 0; 156 int in_pre = 0;
156 int in_blq = 0; 157 int in_blq = 0;
157 xs *list; 158 xs *list;
158 char *p, *v; 159 char *p;
160 const char *v;
159 161
160 /* work by lines */ 162 /* work by lines */
161 list = xs_split(content, "\n"); 163 list = xs_split(content, "\n");
@@ -234,14 +236,14 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
234 /* traditional emoticons */ 236 /* traditional emoticons */
235 xs *d = emojis(); 237 xs *d = emojis();
236 int c = 0; 238 int c = 0;
237 char *k, *v; 239 const char *k, *v;
238 240
239 while (xs_dict_next(d, &k, &v, &c)) { 241 while (xs_dict_next(d, &k, &v, &c)) {
240 const char *t = NULL; 242 const char *t = NULL;
241 243
242 /* is it an URL to an image? */ 244 /* is it an URL to an image? */
243 if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) { 245 if (xs_startswith(v, "https:/" "/") && xs_startswith((t = xs_mime_by_ext(v)), "image/")) {
244 if (tag) { 246 if (tag && xs_str_in(s, k) != -1) {
245 /* add the emoji to the tag list */ 247 /* add the emoji to the tag list */
246 xs *e = xs_dict_new(); 248 xs *e = xs_dict_new();
247 xs *i = xs_dict_new(); 249 xs *i = xs_dict_new();
@@ -280,7 +282,8 @@ xs_str *sanitize(const char *content)
280 xs_str *s = xs_str_new(NULL); 282 xs_str *s = xs_str_new(NULL);
281 xs *sl; 283 xs *sl;
282 int n = 0; 284 int n = 0;
283 char *p, *v; 285 char *p;
286 const char *v;
284 287
285 sl = xs_regex_split(content, "</?[^>]+>"); 288 sl = xs_regex_split(content, "</?[^>]+>");
286 289
@@ -311,9 +314,9 @@ xs_str *sanitize(const char *content)
311 314
312 s = xs_str_cat(s, s2); 315 s = xs_str_cat(s, s2);
313 } else { 316 } else {
314 /* else? just show it with encoded code.. that's it. */ 317 /* treat end of divs as paragraph breaks */
315 xs *el = encode_html(v); 318 if (strcmp(v, "</div>"))
316 s = xs_str_cat(s, el); 319 s = xs_str_cat(s, "<p>");
317 } 320 }
318 } 321 }
319 else { 322 else {