diff options
| -rw-r--r-- | html.c | 91 |
1 files changed, 29 insertions, 62 deletions
| @@ -1173,7 +1173,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1173 | } | 1173 | } |
| 1174 | 1174 | ||
| 1175 | /* make custom css for attachments easier */ | 1175 | /* make custom css for attachments easier */ |
| 1176 | s = xs_str_cat(s, "<p class=\"snac-content-attachments\">\n"); | 1176 | s = xs_str_cat(s, "<div class=\"snac-content-attachments\">\n"); |
| 1177 | 1177 | ||
| 1178 | xs_list *p = attach; | 1178 | xs_list *p = attach; |
| 1179 | 1179 | ||
| @@ -1186,84 +1186,51 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1186 | if (xs_is_null(t)) | 1186 | if (xs_is_null(t)) |
| 1187 | continue; | 1187 | continue; |
| 1188 | 1188 | ||
| 1189 | if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) { | 1189 | const char *url = xs_dict_get(v, "url"); |
| 1190 | char *url = xs_dict_get(v, "url"); | 1190 | if (xs_is_null(url)) |
| 1191 | char *name = xs_dict_get(v, "name"); | 1191 | url = xs_dict_get(v, "href"); |
| 1192 | if (xs_is_null(url)) | ||
| 1193 | continue; | ||
| 1192 | 1194 | ||
| 1193 | if (url != NULL) { | 1195 | const char *name = xs_dict_get(v, "name"); |
| 1194 | if (xs_is_null(name)) | 1196 | if (xs_is_null(name)) |
| 1195 | name = ""; | 1197 | name = L("No description"); |
| 1196 | 1198 | ||
| 1197 | xs *es1 = encode_html(name); | 1199 | xs *es1 = encode_html(name); |
| 1198 | xs *s1 = xs_fmt( | 1200 | xs *s1 = NULL; |
| 1199 | "<a href=\"%s\" target=\"_blank\">" | ||
| 1200 | "<img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n", | ||
| 1201 | url, url, es1, es1); | ||
| 1202 | 1201 | ||
| 1203 | s = xs_str_cat(s, s1); | 1202 | if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) { |
| 1204 | } | 1203 | s1 = xs_fmt( |
| 1204 | "<a href=\"%s\" target=\"_blank\">" | ||
| 1205 | "<img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n", | ||
| 1206 | url, url, es1, es1); | ||
| 1205 | } | 1207 | } |
| 1206 | else | 1208 | else |
| 1207 | if (xs_startswith(t, "video/")) { | 1209 | if (xs_startswith(t, "video/")) { |
| 1208 | char *url = xs_dict_get(v, "url"); | 1210 | s1 = xs_fmt("<video style=\"width: 100%\" class=\"snac-embedded-video\" " |
| 1209 | char *name = xs_dict_get(v, "name"); | 1211 | "controls src=\"%s\">Video: " |
| 1210 | 1212 | "<a href=\"%s\">%s</a></video>\n", url, url, es1); | |
| 1211 | if (url != NULL) { | ||
| 1212 | if (xs_is_null(name)) | ||
| 1213 | name = "No description"; | ||
| 1214 | |||
| 1215 | xs *es1 = encode_html(name); | ||
| 1216 | xs *s1 = xs_fmt("<video style=\"width: 100%\" class=\"snac-embedded-video\" " | ||
| 1217 | "controls src=\"%s\">Video: " | ||
| 1218 | "<a href=\"%s\">%s</a></video>\n", url, url, es1); | ||
| 1219 | |||
| 1220 | s = xs_str_cat(s, s1); | ||
| 1221 | } | ||
| 1222 | } | 1213 | } |
| 1223 | else | 1214 | else |
| 1224 | if (xs_startswith(t, "audio/")) { | 1215 | if (xs_startswith(t, "audio/")) { |
| 1225 | char *url = xs_dict_get(v, "url"); | 1216 | s1 = xs_fmt("<audio style=\"width: 100%\" class=\"snac-embedded-audio\" " |
| 1226 | char *name = xs_dict_get(v, "name"); | 1217 | "controls src=\"%s\">Audio: " |
| 1227 | 1218 | "<a href=\"%s\">%s</a></audio>\n", url, url, es1); | |
| 1228 | if (url != NULL) { | ||
| 1229 | if (xs_is_null(name)) | ||
| 1230 | name = "No description"; | ||
| 1231 | |||
| 1232 | xs *es1 = encode_html(name); | ||
| 1233 | xs *s1 = xs_fmt("<audio style=\"width: 100%\" class=\"snac-embedded-audio\" " | ||
| 1234 | "controls src=\"%s\">Audio: " | ||
| 1235 | "<a href=\"%s\">%s</a></audio>\n", url, url, es1); | ||
| 1236 | |||
| 1237 | s = xs_str_cat(s, s1); | ||
| 1238 | } | ||
| 1239 | } | 1219 | } |
| 1240 | else | 1220 | else |
| 1241 | if (strcmp(t, "Link") == 0) { | 1221 | if (strcmp(t, "Link") == 0) { |
| 1242 | const char *url = xs_dict_get(v, "href"); | 1222 | xs *es2 = encode_html(url); |
| 1243 | 1223 | s1 = xs_fmt("<p><a href=\"%s\">%s</a></p>\n", url, es2); | |
| 1244 | if (!xs_is_null(url)) { | ||
| 1245 | xs *es1 = encode_html(url); | ||
| 1246 | xs *s1 = xs_fmt("<p><a href=\"%s\">%s</a></p>\n", url, es1); | ||
| 1247 | s = xs_str_cat(s, s1); | ||
| 1248 | } | ||
| 1249 | } | 1224 | } |
| 1250 | else { | 1225 | else { |
| 1251 | char *url = xs_dict_get(v, "url"); | 1226 | s1 = xs_fmt("<p><a href=\"%s\">Attachment: %s</a></p>\n", url, es1); |
| 1252 | char *name = xs_dict_get(v, "name"); | ||
| 1253 | |||
| 1254 | if (url != NULL) { | ||
| 1255 | if (xs_is_null(name)) | ||
| 1256 | name = "No description"; | ||
| 1257 | |||
| 1258 | xs *es1 = encode_html(name); | ||
| 1259 | xs *s1 = xs_fmt("<a href=\"%s\">Attachment: %s</a>", url, es1); | ||
| 1260 | |||
| 1261 | s = xs_str_cat(s, s1); | ||
| 1262 | } | ||
| 1263 | } | 1227 | } |
| 1228 | |||
| 1229 | if (!xs_is_null(s1)) | ||
| 1230 | s = xs_str_cat(s, s1); | ||
| 1264 | } | 1231 | } |
| 1265 | 1232 | ||
| 1266 | s = xs_str_cat(s, "</p>\n"); | 1233 | s = xs_str_cat(s, "</div>\n"); |
| 1267 | } | 1234 | } |
| 1268 | 1235 | ||
| 1269 | /* has this message an audience (i.e., comes from a channel or community)? */ | 1236 | /* has this message an audience (i.e., comes from a channel or community)? */ |