mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-25 16:53:37 +00:00
Accept any URL schema (not just http) in format_line().
This commit is contained in:
parent
8de46e30fd
commit
560db69d14
1 changed files with 24 additions and 24 deletions
48
format.c
48
format.c
|
@ -93,7 +93,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
|
|||
"\\*\\*?\\*?[^\\*]+\\*?\\*?\\*" "|"
|
||||
"!\\[[^]]+\\]\\([^\\)]+\\)" "|"
|
||||
"\\[[^]]+\\]\\([^\\)]+\\)" "|"
|
||||
"https?:/" "/[^[:space:]]+"
|
||||
"[a-z]+?:/" "/[^[:space:]]+"
|
||||
")");
|
||||
int n = 0;
|
||||
|
||||
|
@ -133,29 +133,6 @@ static xs_str *format_line(const char *line, xs_list **attach)
|
|||
s = xs_str_cat(s, s2);
|
||||
}
|
||||
else
|
||||
if (xs_startswith(v, "http")) {
|
||||
xs *u = xs_replace(v, "#", "#");
|
||||
xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
|
||||
|
||||
const char *mime = xs_mime_by_ext(v2);
|
||||
|
||||
if (attach != NULL && xs_startswith(mime, "image/")) {
|
||||
/* if it's a link to an image, insert it as an attachment */
|
||||
xs *d = xs_dict_new();
|
||||
|
||||
d = xs_dict_append(d, "mediaType", mime);
|
||||
d = xs_dict_append(d, "url", v2);
|
||||
d = xs_dict_append(d, "name", "");
|
||||
d = xs_dict_append(d, "type", "Image");
|
||||
|
||||
*attach = xs_list_append(*attach, d);
|
||||
}
|
||||
else {
|
||||
xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
|
||||
s = xs_str_cat(s, s1);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (*v == '[') {
|
||||
/* markdown-like links [label](url) */
|
||||
xs *w = xs_strip_chars_i(xs_replace(v, "#", "#"), "[)");
|
||||
|
@ -200,6 +177,29 @@ static xs_str *format_line(const char *line, xs_list **attach)
|
|||
else
|
||||
s = xs_str_cat(s, v);
|
||||
}
|
||||
else
|
||||
if (xs_str_in(v, ":/" "/") != -1) {
|
||||
xs *u = xs_replace(v, "#", "#");
|
||||
xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
|
||||
|
||||
const char *mime = xs_mime_by_ext(v2);
|
||||
|
||||
if (attach != NULL && xs_startswith(mime, "image/")) {
|
||||
/* if it's a link to an image, insert it as an attachment */
|
||||
xs *d = xs_dict_new();
|
||||
|
||||
d = xs_dict_append(d, "mediaType", mime);
|
||||
d = xs_dict_append(d, "url", v2);
|
||||
d = xs_dict_append(d, "name", "");
|
||||
d = xs_dict_append(d, "type", "Image");
|
||||
|
||||
*attach = xs_list_append(*attach, d);
|
||||
}
|
||||
else {
|
||||
xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
|
||||
s = xs_str_cat(s, s1);
|
||||
}
|
||||
}
|
||||
else
|
||||
s = xs_str_cat(s, v);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue