commit 1d0ab9c
default
·
2023-01-12 12:49:37 +0000 UTC
parent bb0d8f2
Added (partial) support for #HashTags in posts.
1 files changed,
+16,
-5
+16,
-5
1@@ -261,7 +261,7 @@ int is_msg_public(snac *snac, char *msg)
2 }
3
4
5-void process_tags(const char *content, d_char **n_content, d_char **tag)
6+void process_tags(snac *snac, const char *content, d_char **n_content, d_char **tag)
7 /* parses mentions and tags from content */
8 {
9 d_char *nc = xs_str_new(NULL);
10@@ -270,7 +270,7 @@ void process_tags(const char *content, d_char **n_content, d_char **tag)
11 char *p, *v;
12 int n = 0;
13
14- split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;]+)");
15+ split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;<]+)");
16
17 p = split;
18 while (xs_list_iter(&p, &v)) {
19@@ -304,8 +304,19 @@ void process_tags(const char *content, d_char **n_content, d_char **tag)
20 else
21 if (*v == '#') {
22 /* hashtag */
23- /* store as is by now */
24- nc = xs_str_cat(nc, v);
25+ xs *d = xs_dict_new();
26+ xs *n = xs_tolower_i(xs_dup(v));
27+ xs *h = xs_fmt("%s%s", snac->actor, n);
28+ xs *l = xs_fmt("<a href=\"%s\" class=\"mention hashtag\" rel=\"tag\">%s</a>", h, v);
29+
30+ d = xs_dict_append(d, "type", "Hashtag");
31+ d = xs_dict_append(d, "href", h);
32+ d = xs_dict_append(d, "name", n);
33+
34+ tl = xs_list_append(tl, d);
35+
36+ /* add the code */
37+ nc = xs_str_cat(nc, l);
38 }
39 }
40 else
41@@ -601,7 +612,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
42 fc2 = not_really_markdown(content);
43
44 /* extract the tags */
45- process_tags(fc2, &fc1, &tag);
46+ process_tags(snac, fc2, &fc1, &tag);
47
48 if (tag == NULL)
49 tag = xs_list_new();