77 while ((tag1 = strstr(*str,
"<a"))) {
79 char *href = strstr(tag1,
"href=\"");
80 char *tag1_end = strstr(tag1,
">");
81 char *tag2 = strstr(tag1,
"</a>");
85 LOG_W(
"Given link is broken: '%s'", tag1);
89 if (tag2 && tag2 < tag1_end) {
90 int repl_len = (tag2 - tag1) + strlen(
"</a>");
91 LOG_W(
"Given link is broken: '%.*s.'", repl_len, tag1);
97 char *plain_url = NULL;
98 if (href && href < tag1_end) {
103 const char *quote = strstr(href,
"\"");
104 if (quote && quote < tag1_end) {
105 plain_url = g_strndup(href, quote-href);
112 text_len = tag2 - (tag1_end+1);
114 text_len = strlen(tag1_end+1);
116 char *text = g_strndup(tag1_end+1, text_len);
118 int repl_len = text_len + (tag1_end-tag1) + 1;
119 repl_len += tag2 ? strlen(
"</a>") : 0;
125 if (plain_url && urls) {
132 char *url = g_strdup_printf(
"[%s] %s", text, plain_url);
151 while ((start = strstr(*str,
"<img"))) {
152 const char *end = strstr(start,
">");
156 LOG_W(
"Given image is broken: '%s'", start);
162 const char *alt_s = strstr(start,
"alt=\"");
163 const char *src_s = strstr(start,
"src=\"");
165 char *text_alt = NULL, *text_src = NULL;
166 const char *src_e = NULL, *alt_e = NULL;
170 alt_s += strlen(
"alt=\"");
171 alt_e = strstr(alt_s,
"\"");
174 src_s += strlen(
"src=\"");
175 src_e = strstr(src_s,
"\"");
182 && ( (alt_s < src_s && alt_e < src_s-strlen(
"src=\"") && src_e < end)
183 ||(src_s < alt_s && src_e < alt_s-strlen(
"alt=\"") && alt_e < end)) ) {
185 text_alt = g_strndup(alt_s, alt_e-alt_s);
186 text_src = g_strndup(src_s, src_e-src_s);
189 }
else if (alt_s && alt_e && alt_e < end && (!src_s || src_s < alt_s || alt_e < src_s - strlen(
"src=\""))) {
190 text_alt = g_strndup(alt_s, alt_e-alt_s);
193 }
else if (src_s && src_e && src_e < end && (!alt_s || alt_s < src_s || src_e < alt_s - strlen(
"alt=\""))) {
194 text_src = g_strndup(src_s, src_e-src_s);
197 LOG_W(
"Given image argument is broken: '%.*s'",
198 (
int)(end-start), start);
202 int repl_len = end - start + 1;
205 text_alt = g_strdup(
"[image]");
211 if (text_src && urls) {
218 char *url = g_strdup_printf(
"[%s] %s", text_alt, text_src);
255 char *end = strchr(str,
';');
260 const char *cur = str + 2;
269 while (isxdigit(*cur) && cur < end)
277 while (isdigit(*cur) && cur < end)
283 const char *supported_tags[] = {
"&",
"<",
">",
""",
"'"};
284 for (
size_t i = 0; i <
sizeof(supported_tags)/
sizeof(*supported_tags); i++) {
285 if (g_str_has_prefix(str, supported_tags[i]))
303 while ((match = strchr(match,
'&'))) {
305 int pos = match - str;
307 match = str + pos + strlen(
"&");
321 switch (markup_mode) {
324 assert(markup_mode != MARKUP_NULL);
Logging subsystem and helpers.
static char * markup_br2nl(char *str)
Convert all HTML linebreak tags to a newline character.
static char * markup_unquote(char *str)
Convert all HTML special entities to their actual char.
void markup_strip_img(char **str, char **urls)
Remove img-tags of a string.
void markup_strip_a(char **str, char **urls)
Remove HTML hyperlinks of a string.
static char * markup_escape_unsupported(char *str)
Escape all unsupported and invalid &-entities in a string.
char * markup_transform(char *str, enum markup_mode markup_mode)
Transform the string in accordance with markup_mode and settings.ignore_newline
char * markup_strip(char *str)
Strip any markup from text; turn it in to plain text.
static bool markup_is_entity(const char *str)
Determine if an & character pointed to by str is a markup & entity or part of the text.
static char * markup_quote(char *str)
Convert all HTML special symbols to HTML entities.
Markup handling for notifications body.
Type definitions for settings.
char * string_replace_at(char *buf, int pos, int len, const char *repl)
Replace a substring inside a string with another string.
void string_strip_delimited(char *str, char a, char b)
Strip content between two delimiter characters.
char * string_replace_all(const char *needle, const char *replacement, char *haystack)
Replace all occurences of a substring.
char * string_append(char *a, const char *b, const char *sep)
Append b to string a, then concatenate both with sep (if they are non-empty).
String, time and other various helpers.
#define ASSERT_OR_RET(expr, val)
Assert that expr evaluates to true, if not return val.